diff options
author | Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> | 2020-05-23 21:49:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-23 20:49:48 +0100 |
commit | 31df012968bd0acb3ed6748c7bf0f99d8ecc4031 (patch) | |
tree | d8a7a2798249129205734e086cd8f01e773de582 /modules | |
parent | 723b1992711dc55548f0014552cc3b0a98bb86e8 (diff) | |
download | gitea-31df012968bd0acb3ed6748c7bf0f99d8ecc4031.tar.gz gitea-31df012968bd0acb3ed6748c7bf0f99d8ecc4031.zip |
Properly handle and return empty string for dangling commits in GetBranchName (#11587)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/commit.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go index 8c7732a26b..61428d23a4 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -468,8 +468,13 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { // GetBranchName gets the closes branch name (as returned by 'git name-rev --name-only') func (c *Commit) GetBranchName() (string, error) { - data, err := NewCommand("name-rev", "--name-only", c.ID.String()).RunInDir(c.repo.Path) + data, err := NewCommand("name-rev", "--name-only", "--no-undefined", c.ID.String()).RunInDir(c.repo.Path) if err != nil { + // handle special case where git can not describe commit + if strings.Contains(err.Error(), "cannot describe") { + return "", nil + } + return "", err } |