Class: EacLauncher::Git::Base

Inherits:
Path
  • Object
show all
Includes:
Eac::SimpleCache, Subrepo, Underlying
Defined in:
lib/eac_launcher/git/base.rb,
lib/eac_launcher/git/base/subrepo.rb,
lib/eac_launcher/git/base/underlying.rb

Defined Under Namespace

Modules: Subrepo, Underlying

Instance Method Summary collapse

Methods included from Underlying

#execute!, #system!

Methods included from Subrepo

#subrepo_status

Methods inherited from Path

#basename, #find_file_with_extension, #find_files_with_extension, #subpath

Instance Method Details

#assert_remote_url(remote_name, url) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/eac_launcher/git/base.rb', line 58

def assert_remote_url(remote_name, url)
  r = git.remote(remote_name)
  if !r.url || r.url != url
    r.remove if r.url
    git.add_remote(remote_name, url)
  end
  r
end

#current_branchObject



90
91
92
# File 'lib/eac_launcher/git/base.rb', line 90

def current_branch
  execute!(%w[symbolic-ref -q HEAD]).gsub(%r{\Arefs/heads/}, '').strip
end

#descendant?(descendant, ancestor) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
# File 'lib/eac_launcher/git/base.rb', line 37

def descendant?(descendant, ancestor)
  base = merge_base(descendant, ancestor)
  return false if base.blank?
  revparse = execute!('rev-parse', '--verify', ancestor).strip
  base == revparse
end

#fetch(remote_name, options = {}) ⇒ Object



84
85
86
87
88
# File 'lib/eac_launcher/git/base.rb', line 84

def fetch(remote_name, options = {})
  args = ['fetch', '-p', remote_name]
  args << '--tags' if options[:tags]
  execute!(*args)
end

#init_bareObject



11
12
13
14
15
# File 'lib/eac_launcher/git/base.rb', line 11

def init_bare
  FileUtils.mkdir_p(self)
  ::EacRubyUtils::Envs.local.command('git', 'init', '--bare', self).execute! unless
  File.exist?(subpath('.git'))
end

#merge_base(*commits) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/eac_launcher/git/base.rb', line 44

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

#push(remote_name, refspecs, options = {}) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/eac_launcher/git/base.rb', line 71

def push(remote_name, refspecs, options = {})
  refspecs = [refspecs] unless refspecs.is_a?(Array)
  args = ['push']
  args << '--dry-run' if options[:dryrun]
  args << '--force' if options[:force]
  system!(args + [remote_name] + refspecs)
end

#push_all(remote_name) ⇒ Object



79
80
81
82
# File 'lib/eac_launcher/git/base.rb', line 79

def push_all(remote_name)
  system!('push', '--all', remote_name)
  system!('push', '--tags', remote_name)
end

#remote_branch_sha(remote_name, branch_name) ⇒ Object



67
68
69
# File 'lib/eac_launcher/git/base.rb', line 67

def remote_branch_sha(remote_name, branch_name)
  remote_hashs(remote_name)["refs/heads/#{branch_name}"]
end

#remote_exist?(remote_name) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/eac_launcher/git/base.rb', line 33

def remote_exist?(remote_name)
  git.remote(remote_name).url.present?
end

#remote_hashs(remote_name) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/eac_launcher/git/base.rb', line 24

def remote_hashs(remote_name)
  r = {}
  execute!(['ls-remote', remote_name]).each_line do |line|
    x = line.strip.split(/\s+/)
    r[x[1]] = x[0]
  end
  r
end

#reset_hard(ref) ⇒ Object



94
95
96
# File 'lib/eac_launcher/git/base.rb', line 94

def reset_hard(ref)
  execute!('reset', '--hard', ref)
end

#rev_parse(ref) ⇒ Object



17
18
19
20
21
22
# File 'lib/eac_launcher/git/base.rb', line 17

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

#subtree_split(prefix) ⇒ Object



54
55
56
# File 'lib/eac_launcher/git/base.rb', line 54

def subtree_split(prefix)
  execute!('subtree', '-q', 'split', '-P', prefix).strip
end