"Expected exactly one original SHA, found 0" error while trying to amend to non-HEAD merge commit
Describe the bug
"Expected exactly one original SHA, found 0" error while trying to amend to non-HEAD merge commit
To Reproduce Steps to reproduce the behavior:
Run:
git init
touch base && git add . && git commit -m "Base commit"
git checkout -b a
git branch b
touch a && git add . && git commit -m "a"
git checkout b
touch b && git add . && git commit -m "b"
git merge a -m "Merge a into b"
touch c && git add . && git commit -m "c"
touch d && git add .
lazygit
Then, navigate to the commits panel and to the "Merge a into b" commit. Perform "Amend commit with staged changes" (A).
Upon doing so, I receive this error: https://github.com/jesseduffield/lazygit/blob/e1c3ef66295bf949de5e7781c0a60ac7f79c47ce/pkg/utils/rebase_todo.go#L235
and am left with a fixup commit containing the new file, d.
Expected behavior I'd expect the amend to just work. It works if commit "c" did not exist.
Screenshots
Version info:
Run lazygit --version and paste the result here
> lazygit --version
commit=v0.40.2, build date=2023-08-12T17:47:33Z, build source=binaryRelease, version=0.40.2, os=linux, arch=amd64, git version=2.44.0
Run git --version and paste the result here
> git --version
git version 2.44.0
Additional context Add any other context about the problem here.
Note: please try updating to the latest version or manually building the latest master to see if the issue still occurs.
Thanks for the detailed report, it's easy to reproduce.
It's not a regression in 0.41.0, it happens in earlier versions too, which makes it a little less urgent to fix. I'll see if I can come up with a reliable way to fix it next week; if not, we might just have to disable the command for merge commits.
There are several workarounds; the easiest might be to press shift-F instead of shift-A to create a fixup commit for the merge commit, then move it down to right after the merge commit using ctrl-j, and then press f there to squash it into its parent.
I had some spare time to look into this and it turned out to just be a simple one-liner. https://github.com/jesseduffield/lazygit/pull/3510