mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
Fix merge status for update-ref command (#2845)
This commit is contained in:
@ -135,7 +135,7 @@ func (self *CommitLoader) GetCommits(opts GetCommitsOptions) ([]*models.Commit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ancestor != "" {
|
if ancestor != "" {
|
||||||
commits = self.setCommitMergedStatuses(ancestor, commits)
|
commits = setCommitMergedStatuses(ancestor, commits)
|
||||||
}
|
}
|
||||||
|
|
||||||
return commits, nil
|
return commits, nil
|
||||||
@ -492,10 +492,11 @@ func (self *CommitLoader) commitFromPatch(content string) *models.Commit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitLoader) 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 {
|
||||||
|
@ -506,3 +506,50 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
commits []*models.Commit
|
||||||
|
ancestor string
|
||||||
|
expectedCommits []*models.Commit
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
testName: "basic",
|
||||||
|
commits: []*models.Commit{
|
||||||
|
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
|
||||||
|
{Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusPushed},
|
||||||
|
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusPushed},
|
||||||
|
},
|
||||||
|
ancestor: "67890",
|
||||||
|
expectedCommits: []*models.Commit{
|
||||||
|
{Sha: "12345", Name: "1", Action: models.ActionNone, Status: models.StatusUnpushed},
|
||||||
|
{Sha: "67890", Name: "2", Action: models.ActionNone, Status: models.StatusMerged},
|
||||||
|
{Sha: "abcde", Name: "3", Action: models.ActionNone, Status: models.StatusMerged},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "with update-ref",
|
||||||
|
commits: []*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.StatusPushed},
|
||||||
|
},
|
||||||
|
ancestor: "deadbeef",
|
||||||
|
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.StatusPushed},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scenario := range scenarios {
|
||||||
|
t.Run(scenario.testName, func(t *testing.T) {
|
||||||
|
expectedCommits := setCommitMergedStatuses(scenario.ancestor, scenario.commits)
|
||||||
|
assert.Equal(t, scenario.expectedCommits, expectedCommits)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user