Class: EacGit::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_git/local.rb,
lib/eac_git/local/commit.rb,
lib/eac_git/local/subrepo.rb,
lib/eac_git/local/dirty_files.rb,
lib/eac_git/local/commit/archive.rb,
lib/eac_git/local/subrepo/config.rb,
lib/eac_git/local/commit/changed_file.rb,
lib/eac_git/local/commit/diff_tree_line.rb

Overview

A Git repository in local filesystem.

Defined Under Namespace

Modules: DirtyFiles Classes: Commit, Subrepo

Constant Summary collapse

HEAD_REFERENCE =
'HEAD'

Instance Method Summary collapse

Instance Method Details

#command(*args) ⇒ Object



45
46
47
# File 'lib/eac_git/local.rb', line 45

def command(*args)
  ::EacGit::Executables.git.command('-C', root_path.to_path, *args)
end

#commit(ref, required = false) ⇒ Object



17
18
19
# File 'lib/eac_git/local.rb', line 17

def commit(ref, required = false)
  rev_parse(ref, required).if_present { |v| ::EacGit::Local::Commit.new(self, v) }
end

#descendant?(descendant, ancestor) ⇒ Boolean



21
22
23
24
25
26
27
# File 'lib/eac_git/local.rb', line 21

def descendant?(descendant, ancestor)
  base = merge_base(descendant, ancestor)
  return false if base.blank?

  revparse = command('rev-parse', '--verify', ancestor).execute!.strip
  base == revparse
end

#head(required = true) ⇒ EacGit::Local::Commit



30
31
32
# File 'lib/eac_git/local.rb', line 30

def head(required = true)
  commit(HEAD_REFERENCE, required)
end

#merge_base(*commits) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/eac_git/local.rb', line 34

def merge_base(*commits)
  refs = commits.dup
  while refs.count > 1
    refs[1] = merge_base_pair(refs[0], refs[1])
    return nil if refs[1].blank?

    refs.shift
  end
  refs.first
end

#raise_error(message) ⇒ Object



49
50
51
# File 'lib/eac_git/local.rb', line 49

def raise_error(message)
  raise "#{root_path}: #{message}"
end

#rev_parse(ref, required = false) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/eac_git/local.rb', line 53

def rev_parse(ref, required = false)
  r = command('rev-parse', ref).execute!(exit_outputs: { 128 => nil, 32_768 => nil })
  r.strip! if r.is_a?(String)
  return r if r.present?
  return nil unless required

  raise_error "Reference \"#{ref}\" not found"
end

#subrepo(subpath) ⇒ Object



62
63
64
# File 'lib/eac_git/local.rb', line 62

def subrepo(subpath)
  ::EacGit::Local::Subrepo.new(self, subpath)
end

#to_sObject



66
67
68
# File 'lib/eac_git/local.rb', line 66

def to_s
  "#{self.class}[#{root_path}]"
end