Properly handle and return empty string for dangling commits in GetBranchName (#11587)
This commit is contained in:
parent
723b199271
commit
31df012968
|
@ -1129,7 +1129,7 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldCommitBranch == "undefined" {
|
if oldCommitBranch == "" {
|
||||||
commitIDs = make([]string, 2)
|
commitIDs = make([]string, 2)
|
||||||
commitIDs[0] = oldCommitID
|
commitIDs[0] = oldCommitID
|
||||||
commitIDs[1] = newCommitID
|
commitIDs[1] = newCommitID
|
||||||
|
|
|
@ -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')
|
// GetBranchName gets the closes branch name (as returned by 'git name-rev --name-only')
|
||||||
func (c *Commit) GetBranchName() (string, error) {
|
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 {
|
if err != nil {
|
||||||
|
// handle special case where git can not describe commit
|
||||||
|
if strings.Contains(err.Error(), "cannot describe") {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,6 +309,7 @@ func Diff(ctx *context.Context) {
|
||||||
ctx.Data["BranchName"], err = commit.GetBranchName()
|
ctx.Data["BranchName"], err = commit.GetBranchName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("commit.GetBranchName", err)
|
ctx.ServerError("commit.GetBranchName", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
ctx.HTML(200, tplCommitPage)
|
ctx.HTML(200, tplCommitPage)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@
|
||||||
{{if IsMultilineCommitMessage .Commit.Message}}
|
{{if IsMultilineCommitMessage .Commit.Message}}
|
||||||
<pre class="commit-body">{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre>
|
<pre class="commit-body">{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre>
|
||||||
{{end}}
|
{{end}}
|
||||||
<span class="text grey">{{svg "octicon-git-branch" 16}}{{.BranchName}}</span>
|
{{if .BranchName}}
|
||||||
|
<span class="text grey">{{svg "octicon-git-branch" 16}}{{.BranchName}}</span>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<div class="ui attached info segment {{$class}}">
|
<div class="ui attached info segment {{$class}}">
|
||||||
<div class="ui stackable grid">
|
<div class="ui stackable grid">
|
||||||
|
|
Loading…
Reference in a new issue