summaryrefslogtreecommitdiff
path: root/tool/vcs.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-09 14:02:01 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-09 14:02:01 +0900
commiteb84b33c86280a72aaeedae1e582045528c534b2 (patch)
tree0e4126681d5f8caa724aaf02ac9fa4d23d71ea05 /tool/vcs.rb
parentc06ddfee878524168e4af07443217ed2f8d0954b (diff)
Search a branch name at a detached head
Diffstat (limited to 'tool/vcs.rb')
-rw-r--r--tool/vcs.rb11
1 files changed, 6 insertions, 5 deletions
diff --git a/tool/vcs.rb b/tool/vcs.rb
index 9310629..1d8fe90 100644
--- a/tool/vcs.rb
+++ b/tool/vcs.rb
@@ -392,15 +392,16 @@ class VCS
def self.get_revisions(path, srcdir = nil)
gitcmd = [COMMAND]
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]])
- else
- log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso']])
- end
+ log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso', *path]])
changed = log[/\Acommit (\h+)/, 1]
changed = changed[0, last.size]
modified = log[/^Date:\s+(.*)/, 1]
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!
upstream = cmd_read_at(srcdir, [gitcmd + %W[branch --list --format=%(upstream:short) #{branch}]])
upstream.chomp!