diff --git a/models/issue_comment.go b/models/issue_comment.go index e23fae6715cf8..3f2ee8b7d951e 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -1129,7 +1129,7 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch return nil, false, err } - if oldCommitBranch == "undefined" { + if oldCommitBranch == "" { commitIDs = make([]string, 2) commitIDs[0] = oldCommitID commitIDs[1] = newCommitID diff --git a/modules/git/commit.go b/modules/git/commit.go index 8c7732a26b155..61428d23a40e8 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 } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index a7a8d30d09190..d87d220f246b5 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -309,6 +309,7 @@ func Diff(ctx *context.Context) { ctx.Data["BranchName"], err = commit.GetBranchName() if err != nil { ctx.ServerError("commit.GetBranchName", err) + return } ctx.HTML(200, tplCommitPage) } diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index f884bee7bef7b..7a91663ec830e 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -27,7 +27,9 @@ {{if IsMultilineCommitMessage .Commit.Message}}
{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{end}} - {{svg "octicon-git-branch" 16}}{{.BranchName}} + {{if .BranchName}} + {{svg "octicon-git-branch" 16}}{{.BranchName}} + {{end}}