class EacLauncher::Git::Base
Public Instance Methods
assert_remote_url(remote_name, url)
click to toggle source
# 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_branch()
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# 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_bare()
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/eac_launcher/git/base.rb, line 83 def raise(message) ::Kernel.raise EacLauncher::Git::Error.new(self, message) end
remote(name)
click to toggle source
@return [EacLauncher::Git::Remote]
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/eac_launcher/git/base/_remotes.rb, line 18 def remote_exist?(remote_name) remote(remote_name).exist? end
remote_hashs(remote_name)
click to toggle source
# File lib/eac_launcher/git/base/_remotes.rb, line 14 def remote_hashs(remote_name) remote(remote_name).ls end
reset_hard(ref)
click to toggle source
# File lib/eac_launcher/git/base.rb, line 79 def reset_hard(ref) execute!('reset', '--hard', ref) end
rev_parse(ref, required = false)
click to toggle source
# 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)
click to toggle source
# File lib/eac_launcher/git/base.rb, line 52 def subtree_split(prefix) execute!('subtree', '-q', 'split', '-P', prefix).strip end
Private Instance Methods
merge_base_pair(commit1, commit2)
click to toggle source
# File lib/eac_launcher/git/base.rb, line 89 def merge_base_pair(commit1, commit2) execute!('merge-base', commit1, commit2, exit_outputs: { 256 => '' }).strip end