jesseduffield / lazygit

simple terminal UI for git commands
MIT License
48.05k stars 1.73k forks source link

Unable to unstage submodule changes when there are uncommitted changes within the submodule #3641

Open RetoranPetra opened 4 weeks ago

RetoranPetra commented 4 weeks ago

Describe the bug As described above, when attempting to unstage a submodule's changes with spacebar after staging said changes, instead of unstaging the currently staged changes within the submodule it quickly moves the changes from "staged" to "unstaged" and back again. This behaviour only occurs when the submodule has uncommitted changes within itself.

To Reproduce

  1. Create a git repository
  2. Create a submodule within said git repository
  3. Make a change and commit it within the submodule
  4. Make a change and DON'T commit it within the submodule
  5. Back out of the submodule, and press "spacebar" on the submodule to stage the committed changes.
  6. Press "spacebar" again on the submodule, and the submodule's changes will not be unstaged.

Expected behavior When there are unstaged changes within the submodule that cannot be staged due to those changes themselves not being staged within the submodule, pressing spacebar should unstage the current change to the submodule's commit hash. Spacebar should call git reset $SUBMODULE_NAME instead of git add $SUBMODULE_NAME

Screenshots Submodule has modified content that has not yet been committed to the submodule, as well as changes that have been committed to the submodule. Screenshot 2024-06-06 161136 When attempting to unstage this with a "spacebar" keypress, lazygit will attempt to stage the uncommitted changes in the submodule despite it not having a commit. Screenshot (2) After this doesn't work, lazygit will reset to the first screenshot showing that the submodule contains modified content.

Version info: commit=, build date=, build source=unknown, version=unversioned, os=windows, arch=amd64, git version=2.45.1.windows.1 git version 2.45.1.windows.1

Additional context Version info as of writing seems to be broken on my machine, likely as I've installed lazygit through go install on windows through MSYS2 specific go. The build I'm using is v0.42.1, but I've had this issue ever since I've been using lazygit.

I'll likely put in a pull request for this issue myself at some point as it doesn't seem too hard to solve.

RyanTalbot commented 4 weeks ago

Happy to take this on and give it a go this weekend. Like @RetoranPetra said, it doesn't seem too difficult so not expecting any surprises.

RetoranPetra commented 3 weeks ago

Happy to take this on and give it a go this weekend. Like @RetoranPetra said, it doesn't seem too difficult so not expecting any surprises.

Sounds great, I had a quick look today and didn't manage to make a dent in it and I'll be busy this weekend.

RyanTalbot commented 3 weeks ago

No trouble recreating the issue. Still working on the actual fix. Will most likely share what I have at this stage for some guidance if no more progress is made soon.