in lib/grit/git-ruby.rb [74:114]
def rev_parse(options, string)
raise RuntimeError, "invalid string: #{string.inspect}" unless string.is_a?(String)
if string !~ /:/ && string =~ /\.\./
(sha1, sha2) = string.split('..')
return [rev_parse({}, sha1), rev_parse({}, sha2)]
end
if /^[0-9a-f]{40}$/.match(string)
return string.chomp
end
head = File.join(@git_dir, 'refs', 'heads', string)
return File.read(head).chomp if File.file?(head)
head = File.join(@git_dir, 'refs', 'remotes', string)
return File.read(head).chomp if File.file?(head)
head = File.join(@git_dir, 'refs', 'tags', string)
return File.read(head).chomp if File.file?(head)
packref = File.join(@git_dir, 'packed-refs')
if File.file?(packref)
File.readlines(packref).each do |line|
if m = /^(\w{40}) refs\/.+?\/(.*?)$/.match(line)
next if !Regexp.new(Regexp.escape(string) + '$').match(m[3])
return m[1].chomp
end
end
end
return method_missing('rev-parse', options, string).chomp
end