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 ⇒ Object
Constructor Details
Instance Attribute Details
#clone_directory ⇒ Object
Returns the value of attribute clone_directory.
7 8 9 |
# File 'lib/raykit/git/repository.rb', line 7 def clone_directory @clone_directory end |
#url ⇒ Object
The url of the remote repository
6 7 8 |
# File 'lib/raykit/git/repository.rb', line 6 def url @url end |
#work_directory ⇒ Object
Returns the value of attribute work_directory.
8 9 10 |
# File 'lib/raykit/git/repository.rb', line 8 def work_directory @work_directory end |
Class Method Details
.parse(json) ⇒ Object
20 21 22 23 24 |
# File 'lib/raykit/git/repository.rb', line 20 def self.parse(json) hash=JSON.parse(json) repo=Repository.new(hash["url"]) repo 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 = Array.new update_local_clone_directory if(Dir.exist?(local_clone_directory)) Dir.chdir(local_clone_directory) do `git branch`.split('\n').each{|line| branch = line.gsub('*','').strip results.insert(-1,branch) if(branch.length > 0) } 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 == 0) 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) return "#{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 76 |
# File 'lib/raykit/git/repository.rb', line 71 def latest_tag(branch) if(checkout_local_clone_directory_branch(branch)) return `git describe --abbrev=0`.strip end '' 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 ⇒ Object
16 17 18 |
# File 'lib/raykit/git/repository.rb', line 16 def to_json JSON.generate({"url" => @url}) end |