checked_out?(sha)
click to toggle source
def checked_out?(sha)
current_commit_hash == sha
end
checkout!(reference, options ={ })
click to toggle source
def checkout!(reference, options ={ })
command = %W(checkout #{reference} --quiet)
command << "--force" if options[:force]
run!(command, :chdir => true)
end
clean!()
click to toggle source
def clean!
command = %w(clean -x -d --force --force)
run!(command, :chdir => true)
end
clone!(repository_url)
click to toggle source
def clone!(repository_url)
command = %W(clone #{repository_url} . --quiet)
run!(command, :chdir => true)
end
current_commit_hash()
click to toggle source
def current_commit_hash
command = %W(rev-parse HEAD --quiet)
run!(command, :chdir => true).strip!
end
default_remote()
click to toggle source
def default_remote
"origin"
end
fetch!(remote, options = { })
click to toggle source
def fetch!(remote, options = { })
command = %W(fetch #{remote} --quiet)
command << "--tags" if options[:tags]
run!(command, :chdir => true)
end
git?()
click to toggle source
def git?
path.join('.git').exist?
end
has_commit?(sha)
click to toggle source
def has_commit?(sha)
command = %W(log -1 --no-color --format=tformat:%H #{sha})
run!(command, :chdir => true).strip == sha
rescue Posix::CommandFailure => e
false
end
hash_from(remote, reference)
click to toggle source
def hash_from(remote, reference)
branch_names = remote_branch_names[remote]
if branch_names.include?(reference)
reference = "#{remote}/#{reference}"
end
command = %W(rev-list #{reference} -1)
run!(command, :chdir => true).strip
end
remote_branch_names()
click to toggle source
def remote_branch_names
remotes = remote_names.sort_by(&:length).reverse
command = %W(branch -r --no-color)
names = run!(command, :chdir => true).strip.lines.map(&:strip).to_a
names.each{|n| n.gsub!(/\s*->.*$/, "")}
names.reject!{|n| n =~ /\/HEAD$/}
Hash[remotes.map do |r|
matching_names = names.select{|n| n.start_with?("#{r}/")}
matching_names.each{|n| names.delete(n)}
matching_names.each{|n| n.slice!(0, r.size + 1)}
[r, matching_names]
end]
end
remote_names()
click to toggle source
def remote_names
command = %W(remote)
run!(command, :chdir => true).strip.lines.map(&:strip)
end
reset_hard!()
click to toggle source
def reset_hard!
command = %W(reset --hard --quiet)
run!(command, :chdir => true)
end