summaryrefslogtreecommitdiff
path: root/tool/vcs.rb
diff options
context:
space:
mode:
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 8379b3b548..56924ff8bc 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?