summaryrefslogtreecommitdiff
path: root/tool/vcs.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-31 02:30:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-05-31 10:55:37 +0900
commit1e9057b54a53e7bc1fa3d0e3eaef1dd33707d044 (patch)
treee87edb1c9fd1432f5c25330ecaf99fa06b6d8467 /tool/vcs.rb
parentfd658ec821f07e0a2254fcd62ce29cc644d61302 (diff)
Prefer the current branch or tag name
Diffstat (limited to 'tool/vcs.rb')
-rw-r--r--tool/vcs.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/tool/vcs.rb b/tool/vcs.rb
index 8379b3b..56924ff 100644
--- a/tool/vcs.rb
+++ b/tool/vcs.rb
@@ -408,8 +408,21 @@ class VCS
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.to_a
- branch_list.delete_if {|b| /detached at/ =~ b}
- (branch = branch_list[0]).strip! unless branch_list.empty?
+ branch, = branch_list.grep(/\A\*/)
+ case branch
+ when /\A\* *\(\S+ detached at (.*)\)\Z/
+ branch = $1
+ branch = nil if last.start_with?(branch)
+ when /\A\* (\S+)\Z/
+ branch = $1
+ else
+ branch = nil
+ end
+ unless branch
+ branch_list.each {|b| b.strip!}
+ branch_list.delete_if {|b| / / =~ b}
+ branch = branch_list.min_by(&:length) || ""
+ end
end
branch.chomp!
branch = ":detached:" if branch.empty?