summaryrefslogtreecommitdiffstats
path: root/modules/git/commit.go
diff options
context:
space:
mode:
authorCirno the Strongest <1447794+CirnoT@users.noreply.github.com>2020-06-11 21:42:55 +0200
committerGitHub <noreply@github.com>2020-06-11 15:42:55 -0400
commitb682a2c1b2d5efde24378858453903b5b89d6df8 (patch)
treed123a90d1bb87d836a7afdf2492d1b1142a5b636 /modules/git/commit.go
parente282fbe75380e05b802e228348179774b2975745 (diff)
downloadgitea-b682a2c1b2d5efde24378858453903b5b89d6df8.tar.gz
gitea-b682a2c1b2d5efde24378858453903b5b89d6df8.zip
Show exact tag for commit on diff view (#11846)
* Show exact tag for commit on diff view * Fix comment Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/git/commit.go')
-rw-r--r--modules/git/commit.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index a114c902dd..d6448bf26e 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -466,7 +466,7 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
return nil, nil
}
-// GetBranchName gets the closes branch name (as returned by 'git name-rev --name-only')
+// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')
func (c *Commit) GetBranchName() (string, error) {
data, err := NewCommand("name-rev", "--exclude", "refs/tags/*", "--name-only", "--no-undefined", c.ID.String()).RunInDir(c.repo.Path)
if err != nil {
@@ -482,6 +482,21 @@ func (c *Commit) GetBranchName() (string, error) {
return strings.SplitN(strings.TrimSpace(data), "~", 2)[0], nil
}
+// GetTagName gets the current tag name for given commit
+func (c *Commit) GetTagName() (string, error) {
+ data, err := NewCommand("describe", "--exact-match", "--tags", c.ID.String()).RunInDir(c.repo.Path)
+ if err != nil {
+ // handle special case where there is no tag for this commit
+ if strings.Contains(err.Error(), "no tag exactly matches") {
+ return "", nil
+ }
+
+ return "", err
+ }
+
+ return strings.TrimSpace(data), nil
+}
+
// CommitFileStatus represents status of files in a commit.
type CommitFileStatus struct {
Added []string