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
- .parse(json) ⇒ Object
- .work(url, cmd) ⇒ Object
- .work_integrate(url) ⇒ Object
- .work_pull(url) ⇒ Object
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.
- #short_name(url) ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
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
25 26 27 28 |
# File 'lib/raykit/git/repository.rb', line 25 def self.parse(json) hash = JSON.parse(json) Repository.new(hash["url"]) end |
.work(url, cmd) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/raykit/git/repository.rb', line 128 def self.work(url, cmd) repo = Raykit::Git::Repository.new(url) work_dir = repo.get_dev_dir("work") repo.clone(work_dir) if !Dir.exist?(work_dir) Dir.chdir(work_dir) do run("git pull") run(cmd) end end |
.work_integrate(url) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/raykit/git/repository.rb', line 118 def self.work_integrate(url) repo = Raykit::Git::Repository.new(url) work_dir = repo.get_dev_dir("work") repo.clone(work_dir) if !Dir.exist?(work_dir) Dir.chdir(work_dir) do run("git pull") run("rake integrate") end end |
Instance Method Details
#branches ⇒ Object
The branches for the git repository
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/raykit/git/repository.rb', line 50 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
41 42 43 44 45 46 47 |
# File 'lib/raykit/git/repository.rb', line 41 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
35 36 37 38 |
# File 'lib/raykit/git/repository.rb', line 35 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
65 66 67 68 69 70 71 72 |
# File 'lib/raykit/git/repository.rb', line 65 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
75 76 77 78 79 |
# File 'lib/raykit/git/repository.rb', line 75 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
31 32 33 |
# File 'lib/raykit/git/repository.rb', line 31 def relative_path @url.gsub("https://", "").gsub(".git", "").gsub("http://", "") end |
#short_name(url) ⇒ Object
17 18 19 |
# File 'lib/raykit/git/repository.rb', line 17 def short_name(url) @url.split("/").last.gsub(".git", "") end |
#to_json(*_args) ⇒ Object
21 22 23 |
# File 'lib/raykit/git/repository.rb', line 21 def to_json(*_args) JSON.generate({ "url" => @url }) end |