Class: Chicanery::Git::Repo
- Inherits:
-
Object
- Object
- Chicanery::Git::Repo
- Includes:
- FileUtils
- Defined in:
- lib/chicanery/git.rb
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#remotes ⇒ Object
readonly
Returns the value of attribute remotes.
Instance Method Summary collapse
- #git(command) ⇒ Object
- #head(branch) ⇒ Object
- #in_repo ⇒ Object
-
#initialize(name, path, params = {}) ⇒ Repo
constructor
A new instance of Repo.
- #prepare ⇒ Object
- #remote_head(url, branch) ⇒ Object
- #sha(command) ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(name, path, params = {}) ⇒ Repo
Returns a new instance of Repo.
10 11 12 13 14 |
# File 'lib/chicanery/git.rb', line 10 def initialize name, path, params={} @name, @path = name, path @branches = params[:branches] || [] @remotes = params[:remotes] || {} end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
8 9 10 |
# File 'lib/chicanery/git.rb', line 8 def branches @branches end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/chicanery/git.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/chicanery/git.rb', line 8 def path @path end |
#remotes ⇒ Object (readonly)
Returns the value of attribute remotes.
8 9 10 |
# File 'lib/chicanery/git.rb', line 8 def remotes @remotes end |
Instance Method Details
#git(command) ⇒ Object
52 53 54 |
# File 'lib/chicanery/git.rb', line 52 def git command `git #{command}`.chomp end |
#head(branch) ⇒ Object
44 45 46 |
# File 'lib/chicanery/git.rb', line 44 def head branch sha "log -n 1 #{branch} --pretty=oneline" end |
#in_repo ⇒ Object
16 17 18 |
# File 'lib/chicanery/git.rb', line 16 def in_repo Dir.chdir(path) { yield } end |
#prepare ⇒ Object
20 21 22 23 24 |
# File 'lib/chicanery/git.rb', line 20 def prepare return if File.exists? path mkdir_p path in_repo { git 'init' } end |
#remote_head(url, branch) ⇒ Object
40 41 42 |
# File 'lib/chicanery/git.rb', line 40 def remote_head url, branch sha "ls-remote #{url} #{branch}" end |
#sha(command) ⇒ Object
48 49 50 |
# File 'lib/chicanery/git.rb', line 48 def sha command git(command).split.first end |
#state ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chicanery/git.rb', line 26 def state prepare response = {} in_repo do remotes.each do |name, remote| (remote[:branches] || ['master']).each do |branch| response["#{name}/#{branch}"] = remote_head remote[:url], branch end end branches.each { |branch| response[branch] = head branch } end response end |