1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Search a branch name at a detached head

This commit is contained in:
Nobuyoshi Nakada 2019-05-09 14:02:01 +09:00
parent c06ddfee87
commit eb84b33c86
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -392,15 +392,16 @@ class VCS
def self.get_revisions(path, srcdir = nil) def self.get_revisions(path, srcdir = nil)
gitcmd = [COMMAND] gitcmd = [COMMAND]
last = cmd_read_at(srcdir, [[*gitcmd, 'rev-parse', '--short=10', 'HEAD']]).rstrip last = cmd_read_at(srcdir, [[*gitcmd, 'rev-parse', '--short=10', 'HEAD']]).rstrip
if path log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso', *path]])
log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso', path]])
else
log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso']])
end
changed = log[/\Acommit (\h+)/, 1] changed = log[/\Acommit (\h+)/, 1]
changed = changed[0, last.size] changed = changed[0, last.size]
modified = log[/^Date:\s+(.*)/, 1] modified = log[/^Date:\s+(.*)/, 1]
branch = cmd_read_at(srcdir, [gitcmd + %W[symbolic-ref --short HEAD]]) branch = cmd_read_at(srcdir, [gitcmd + %W[symbolic-ref --short HEAD]])
if branch.empty?
branch_list = cmd_read_at(srcdir, [gitcmd + %W[branch --list --contains HEAD]]).lines
branch_list.delete_if {|b| /detached at/ =~ b}
(branch = branch_list[0]).strip! unless branch_list.empty?
end
branch.chomp! branch.chomp!
upstream = cmd_read_at(srcdir, [gitcmd + %W[branch --list --format=%(upstream:short) #{branch}]]) upstream = cmd_read_at(srcdir, [gitcmd + %W[branch --list --format=%(upstream:short) #{branch}]])
upstream.chomp! upstream.chomp!