Class: Raykit::Git::Repository
- Inherits:
-
Object
- Object
- Raykit::Git::Repository
- Defined in:
- lib/raykit/git/repository.rb
Overview
Functionality to manage a remote git repository
Instance Attribute Summary collapse
-
#clone_directory ⇒ Object
Returns the value of attribute clone_directory.
-
#url ⇒ Object
The url of the remote repository.
-
#work_directory ⇒ Object
Returns the value of attribute work_directory.
Class Method Summary collapse
Instance Method Summary collapse
-
#branches ⇒ Object
The branches for the git repository.
-
#clone(directory, depth = 0) ⇒ Object
Clone the repository to a specific directory.
- #get_dev_dir(dir) ⇒ Object
-
#initialize(url) ⇒ Repository
constructor
A new instance of Repository.
-
#latest_commit(branch) ⇒ Object
The latest commit id for a branch of the repostiory.
-
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository.
-
#relative_path ⇒ Object
The relative path is a valid local path name derived from the url.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(url) ⇒ Repository
Returns a new instance of Repository.
11 12 13 14 15 |
# File 'lib/raykit/git/repository.rb', line 11 def initialize(url) @url = url @clone_directory = Raykit::Git::Directory.new(get_dev_dir("clone")) @work_directory = Raykit::Git::Directory.new(get_dev_dir("work")) end |
Instance Attribute Details
#clone_directory ⇒ Object
Returns the value of attribute clone_directory.
9 10 11 |
# File 'lib/raykit/git/repository.rb', line 9 def clone_directory @clone_directory end |
#url ⇒ Object
The url of the remote repository
8 9 10 |
# File 'lib/raykit/git/repository.rb', line 8 def url @url end |
#work_directory ⇒ Object
Returns the value of attribute work_directory.
9 10 11 |
# File 'lib/raykit/git/repository.rb', line 9 def work_directory @work_directory end |
Class Method Details
.parse(json) ⇒ Object
21 22 23 24 |
# File 'lib/raykit/git/repository.rb', line 21 def self.parse(json) hash = JSON.parse(json) Repository.new(hash["url"]) end |
Instance Method Details
#branches ⇒ Object
The branches for the git repository
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/raykit/git/repository.rb', line 46 def branches results = [] update_local_clone_directory if Dir.exist?(local_clone_directory) Dir.chdir(local_clone_directory) do `git branch`.split('\n').each do |line| branch = line.gsub("*", "").strip results.insert(-1, branch) if branch.length.positive? end end end results end |
#clone(directory, depth = 0) ⇒ Object
Clone the repository to a specific directory
37 38 39 40 41 42 43 |
# File 'lib/raykit/git/repository.rb', line 37 def clone(directory, depth = 0) if depth.zero? PROJECT.run("git clone #{@url} #{directory}") else PROJECT.run("git clone #{@url} #{directory} --depth #{depth}") end end |
#get_dev_dir(dir) ⇒ Object
31 32 33 34 |
# File 'lib/raykit/git/repository.rb', line 31 def get_dev_dir(dir) dev_dir = Environment.get_dev_dir(dir) "#{dev_dir}/#{relative_path}" end |
#latest_commit(branch) ⇒ Object
The latest commit id for a branch of the repostiory
61 62 63 64 65 66 67 68 |
# File 'lib/raykit/git/repository.rb', line 61 def latest_commit(branch) if checkout_local_clone_directory_branch(branch) text = `git log -n 1` scan = text.scan(/commit (\w+)\s/) return scan[0][0].to_s end "" end |
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository
71 72 73 74 75 |
# File 'lib/raykit/git/repository.rb', line 71 def latest_tag(branch) return `git describe --abbrev=0`.strip if checkout_local_clone_directory_branch(branch) "" end |
#relative_path ⇒ Object
The relative path is a valid local path name derived from the url
27 28 29 |
# File 'lib/raykit/git/repository.rb', line 27 def relative_path @url.gsub("https://", "").gsub(".git", "").gsub("http://", "") end |
#to_json(*_args) ⇒ Object
17 18 19 |
# File 'lib/raykit/git/repository.rb', line 17 def to_json(*_args) JSON.generate({ "url" => @url }) end |