Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Expected exactly one original SHA, found 0" error while trying to amend to non-HEAD merge commit #3421

Closed
brandondong opened this issue Mar 23, 2024 · 2 comments · Fixed by #3510
Labels
bug Something isn't working

Comments

@brandondong
Copy link
Contributor

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:

return nil, fmt.Errorf("Expected exactly one original SHA, found %d", originalShaCount)

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
image

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.

@brandondong brandondong added the bug Something isn't working label Mar 23, 2024
@stefanhaller
Copy link
Collaborator

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.

@brandondong
Copy link
Contributor Author

I had some spare time to look into this and it turned out to just be a simple one-liner. #3510

stefanhaller added a commit that referenced this issue Apr 22, 2024
- **PR Description**

Resolves #3421

The error is "Expected exactly one original SHA, found 0" but the merge
commit hash (`d6a7a04c626e40071133de26ebe8fdd225caa5c0`) is present in
the rebase TODO file.


![image](https://github.com/jesseduffield/lazygit/assets/13722457/2e6d5fdb-af9f-4eae-9972-8e51a77ba614)

![image](https://github.com/jesseduffield/lazygit/assets/13722457/65dd4b1b-b080-47b0-9079-71c5e0d76cd2)

However, the commit is missed during search because the filter is only
looking for pick commits:
https://github.com/jesseduffield/lazygit/blob/580818e935e19a67f7fe1bbb148224a95781879c/pkg/utils/rebase_todo.go#L238

Checking for merge commits as well fixes the issue.

I believe only pick and merge should be valid here. If already in an
interactive rebase, lazygit only allows amending to the current HEAD
commit. When that happens, this whole interactive rebase logic is
bypassed and lazygit just performs `git commit --amend`:
https://github.com/jesseduffield/lazygit/blob/580818e935e19a67f7fe1bbb148224a95781879c/pkg/gui/controllers/local_commits_controller.go#L668

This is the reason why amending to a HEAD merge commit currently works
whereas non-HEAD does not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants