summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-07-29 20:15:00 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-07-31 08:28:03 +0200
commit8ab05d6834dc1e3bf9b270f9faad8907e99f507c (patch)
tree6cecb3196a32984a3e93cb50377ae69a7b485985 /pkg
parent774df817fd7b3f8c1a08a41ad5d23b08ed24f0b0 (diff)
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.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/commit_loader.go3
-rw-r--r--pkg/commands/git_commands/commit_loader_test.go2
2 files changed, 3 insertions, 2 deletions
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index 22b92ea0a..ab13e6523 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -495,7 +495,8 @@ func (self *CommitLoader) commitFromPatch(content string) *models.Commit {
func setCommitMergedStatuses(ancestor string, commits []*models.Commit) []*models.Commit {
passedAncestor := false
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
}
if commit.Status != models.StatusPushed && commit.Status != models.StatusUnpushed {
diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go
index a281cb775..c3cfb0585 100644
--- a/pkg/commands/git_commands/commit_loader_test.go
+++ b/pkg/commands/git_commands/commit_loader_test.go
@@ -541,7 +541,7 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
expectedCommits: []*models.Commit{
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
{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},
},
},
}