From ff7c95dfd9b6aa1b4a83c18172e2845f7e6a4e7f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 1 Sep 2019 18:10:50 +0900 Subject: [PATCH] Support git tags --- tool/lib/vcs.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb index 8896c3458a..622e55858f 100644 --- a/tool/lib/vcs.rb +++ b/tool/lib/vcs.rb @@ -457,8 +457,9 @@ class VCS end def _get_revisions(path, srcdir = nil) + ref = Branch === path ? path.to_str : 'HEAD' gitcmd = [COMMAND] - last = cmd_read_at(srcdir, [[*gitcmd, 'rev-parse', 'HEAD']]).rstrip + last = cmd_read_at(srcdir, [[*gitcmd, 'rev-parse', ref]]).rstrip log = cmd_read_at(srcdir, [[*gitcmd, 'log', '-n1', '--date=iso', '--pretty=fuller', *path]]) changed = log[/\Acommit (\h+)/, 1] modified = log[/^CommitDate:\s+(.*)/, 1] @@ -470,9 +471,12 @@ class VCS end changed = rev end - branch = cmd_read_at(srcdir, [gitcmd + %W[symbolic-ref --short HEAD]]) + branch = cmd_read_at(srcdir, [gitcmd + %W[symbolic-ref --short #{ref}]]) if branch.empty? - branch_list = cmd_read_at(srcdir, [gitcmd + %W[branch --list --contains HEAD]]).lines.to_a + branch = cmd_read_at(srcdir, [gitcmd + %W[tag --list #{ref}]]).strip + end + if branch.empty? + branch_list = cmd_read_at(srcdir, [gitcmd + %W[branch --list --contains #{ref}]]).lines.to_a branch, = branch_list.grep(/\A\*/) case branch when /\A\* *\(\S+ detached at (.*)\)\Z/ @@ -493,7 +497,7 @@ class VCS branch = ":detached:" if branch.empty? upstream = cmd_read_at(srcdir, [gitcmd + %W[branch --list --format=%(upstream:short) #{branch}]]) upstream.chomp! - title = cmd_read_at(srcdir, [gitcmd + %W[log --format=%s -n1 #{upstream}..HEAD]]) + title = cmd_read_at(srcdir, [gitcmd + %W[log --format=%s -n1 #{upstream}..#{ref}]]) title = nil if title.empty? [last, changed, modified, branch, title] end