Class: Circus::Repos::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/repos/git.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Git

Returns a new instance of Git.



20
21
22
# File 'lib/circus/repos/git.rb', line 20

def initialize(dir)
  @dir = dir
end

Class Method Details

.accepts_dir?(dir_name) ⇒ Boolean

Checks if the current directory (or a parent) are Git working trees. Uses a call to git remote to test (which will fail with a non-zero exit if the tree isn’t a valid git tree)

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/circus/repos/git.rb', line 7

def self.accepts_dir? dir_name
  `git remote >/dev/null 2>/dev/null`
  $? == 0
end

.accepts_id?(key) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/circus/repos/git.rb', line 12

def self.accepts_id?(key)
  key == 'git'
end

.type_idObject



16
17
18
# File 'lib/circus/repos/git.rb', line 16

def self.type_id
  'git'
end

Instance Method Details

#current_revisionObject



31
32
33
34
# File 'lib/circus/repos/git.rb', line 31

def current_revision
  result = `(cd #{@dir}; git rev-parse HEAD)`
  return result.strip unless $?.exitstatus != 0
end

#repo_urlObject



24
25
26
27
28
29
# File 'lib/circus/repos/git.rb', line 24

def repo_url
  first_remote = `(cd #{@dir}; git remote -v) | grep fetch`.lines.first
  return nil unless first_remote
  
  first_remote.split(' ', 2)[1].gsub('(fetch)', '').strip
end

#write_patch(patch_fn) ⇒ Object



36
37
38
# File 'lib/circus/repos/git.rb', line 36

def write_patch(patch_fn)
  `(cd #{@dir}; git diff HEAD >#{patch_fn})`.strip
end