Fix merge status of commits when update-ref command is present

Update-ref commands have an empty sha, and strings.HasPrefix returns true when
called with an empty second argument, so whenever an update-ref command is
present in a rebase, all commits from there on down were drawn with a green sha.
This commit is contained in:
Stefan Haller 2023-07-29 20:15:00 +02:00
parent 774df817fd
commit 8ab05d6834
2 changed files with 3 additions and 2 deletions

View file

@ -495,7 +495,8 @@ func (self *CommitLoader) commitFromPatch(content string) *models.Commit {
func setCommitMergedStatuses(ancestor string, commits []*models.Commit) []*models.Commit { func setCommitMergedStatuses(ancestor string, commits []*models.Commit) []*models.Commit {
passedAncestor := false passedAncestor := false
for i, commit := range commits { for i, commit := range commits {
if strings.HasPrefix(ancestor, commit.Sha) { // some commits aren't really commits and don't have sha's, such as the update-ref todo
if commit.Sha != "" && strings.HasPrefix(ancestor, commit.Sha) {
passedAncestor = true passedAncestor = true
} }
if commit.Status != models.StatusPushed && commit.Status != models.StatusUnpushed { if commit.Status != models.StatusPushed && commit.Status != models.StatusUnpushed {

View file

@ -541,7 +541,7 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
expectedCommits: []*models.Commit{ expectedCommits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed}, {Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone}, {Sha: "", Name: "", Action: todo.UpdateRef, Status: models.StatusNone},
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged}, // Wrong, expect Pushed {Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
}, },
}, },
} }