mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
Make getHydratedRebasingCommits more robust
So far the algorithm worked on the assumption that the output of the "git show" command corresponds one-to-one to the lines of the rebase-todo file. This assumption doesn't hold once we start to include todo lines that don't have a sha (like update-ref), or when the todo file contains multiple entries for the same sha. This should never happen normally, but it can if users manually edit the todo file and duplicate a line.
This commit is contained in:
parent
c53c5e47ef
commit
a0d179b6dc
@ -194,8 +194,8 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
commitShas := slices.Map(commits, func(commit *models.Commit) string {
|
commitShas := slices.FilterMap(commits, func(commit *models.Commit) (string, bool) {
|
||||||
return commit.Sha
|
return commit.Sha, commit.Sha != ""
|
||||||
})
|
})
|
||||||
|
|
||||||
// note that we're not filtering these as we do non-rebasing commits just because
|
// note that we're not filtering these as we do non-rebasing commits just because
|
||||||
@ -209,20 +209,26 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode
|
|||||||
),
|
),
|
||||||
).DontLog()
|
).DontLog()
|
||||||
|
|
||||||
hydratedCommits := make([]*models.Commit, 0, len(commits))
|
fullCommits := map[string]*models.Commit{}
|
||||||
i := 0
|
|
||||||
err = cmdObj.RunAndProcessLines(func(line string) (bool, error) {
|
err = cmdObj.RunAndProcessLines(func(line string) (bool, error) {
|
||||||
commit := self.extractCommitFromLine(line)
|
commit := self.extractCommitFromLine(line)
|
||||||
matchingCommit := commits[i]
|
fullCommits[commit.Sha] = commit
|
||||||
commit.Action = matchingCommit.Action
|
|
||||||
commit.Status = matchingCommit.Status
|
|
||||||
hydratedCommits = append(hydratedCommits, commit)
|
|
||||||
i++
|
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hydratedCommits := make([]*models.Commit, 0, len(commits))
|
||||||
|
for _, rebasingCommit := range commits {
|
||||||
|
if rebasingCommit.Sha == "" {
|
||||||
|
hydratedCommits = append(hydratedCommits, rebasingCommit)
|
||||||
|
} else if commit := fullCommits[rebasingCommit.Sha]; commit != nil {
|
||||||
|
commit.Action = rebasingCommit.Action
|
||||||
|
commit.Status = rebasingCommit.Status
|
||||||
|
hydratedCommits = append(hydratedCommits, commit)
|
||||||
|
}
|
||||||
|
}
|
||||||
return hydratedCommits, nil
|
return hydratedCommits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user