Class: EacLauncher::Git::Base

Inherits:
Paths::Real show all
Includes:
Subrepo, Underlying, EacRubyUtils::SimpleCache
Defined in:
lib/eac_launcher/git/base.rb,
lib/eac_launcher/git/base/subrepo.rb,
lib/eac_launcher/git/base/_remotes.rb,
lib/eac_launcher/git/base/underlying.rb

Defined Under Namespace

Modules: Subrepo, Underlying

Instance Method Summary collapse

Methods included from Underlying

#execute!, #init, #system!

Methods included from Subrepo

#subrepo_remote_url, #subrepo_status

Methods inherited from Paths::Real

#basename, #dirname, #find_file_with_extension, #find_files_with_extension, #initialize, #subpath

Constructor Details

This class inherits a constructor from EacLauncher::Paths::Real

Instance Method Details

#assert_remote_url(remote_name, url) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/eac_launcher/git/base/_remotes.rb', line 22

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



75
76
77
# File 'lib/eac_launcher/git/base.rb', line 75

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

#descendant?(descendant, ancestor) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/eac_launcher/git/base.rb', line 33

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



69
70
71
72
73
# File 'lib/eac_launcher/git/base.rb', line 69

def fetch(remote_name, options = {})
  args = ['fetch', '-p', remote_name]
  args += %w[--tags --prune-tags --force] if options[:tags]
  execute!(*args)
end

#init_bareObject



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

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/eac_launcher/git/base.rb', line 41

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



56
57
58
59
60
61
62
# File 'lib/eac_launcher/git/base.rb', line 56

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



64
65
66
67
# File 'lib/eac_launcher/git/base.rb', line 64

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

#raise(message) ⇒ Object



83
84
85
# File 'lib/eac_launcher/git/base.rb', line 83

def raise(message)
  ::Kernel.raise EacLauncher::Git::Error.new(self, message)
end

#remote(name) ⇒ EacLauncher::Git::Remote



10
11
12
# File 'lib/eac_launcher/git/base/_remotes.rb', line 10

def remote(name)
  ::EacLauncher::Git::Remote.new(self, name)
end

#remote_branch_sha(remote_name, branch_name) ⇒ Object



31
32
33
# File 'lib/eac_launcher/git/base/_remotes.rb', line 31

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

#remote_exist?(remote_name) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/eac_launcher/git/base/_remotes.rb', line 18

def remote_exist?(remote_name)
  remote(remote_name).exist?
end

#remote_hashs(remote_name) ⇒ Object



14
15
16
# File 'lib/eac_launcher/git/base/_remotes.rb', line 14

def remote_hashs(remote_name)
  remote(remote_name).ls
end

#reset_hard(ref) ⇒ Object



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

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

#rev_parse(ref, required = false) ⇒ Object



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

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

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

#subtree_split(prefix) ⇒ Object



52
53
54
# File 'lib/eac_launcher/git/base.rb', line 52

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