From cc316ab6de40c3b6fd3666b5ce0241eeee4680e8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 27 Jun 2023 19:11:38 +0200 Subject: [PATCH] Fix interactive rebase with git 2.25.1 and earlier The code in getHydratedRebasingCommits relied on the assumption that the git-rebase-todo file contains full SHAs. This has only been true from 2.25.2 on, before that it would contain abbreviated SHAs. Fix this by storing fullCommits in a slice instead of a map, and using a linear search. --- pkg/commands/git_commands/commit_loader.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 148c96776..32d470fc8 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -222,11 +222,24 @@ func (self *CommitLoader) getHydratedRebasingCommits(rebaseMode enums.RebaseMode return nil, err } + findFullCommit := lo.Ternary(self.version.IsOlderThan(2, 25, 2), + func(sha string) *models.Commit { + for s, c := range fullCommits { + if strings.HasPrefix(s, sha) { + return c + } + } + return nil + }, + func(sha string) *models.Commit { + return fullCommits[sha] + }) + 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 { + } else if commit := findFullCommit(rebasingCommit.Sha); commit != nil { commit.Action = rebasingCommit.Action commit.Status = rebasingCommit.Status hydratedCommits = append(hydratedCommits, commit)