MitMaro / git-interactive-rebase-tool

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.
https://gitrebasetool.mitmaro.ca/
GNU General Public License v3.0
1.55k stars 48 forks source link

git rebase --edit-todo should not empty the file #739

Open forivall opened 1 year ago

forivall commented 1 year ago

I used git rebase --edit-todo to look at how many commits were left in my rebase, but when i didnt change the file, interactive-rebase-tool cleared the file to abort, and then the rebasing ended, and I had to continue the rebase with a cherry-pick of the remaining commits.

MitMaro commented 1 year ago

TIL! I didn't know about the --edit-todo flag! Very useful.

I've confirmed what you experienced, and although the tool is "working as expected", I can see how the wording around "abort" is confusing when using it to edit the rebase file after the start of the rebase. Git uses an empty rebase file to signal that the rebase should "abort", which does not make sense in the context of editing the todo file for an in progress rebase.

I fully agree that this behaviour is confusing and unexpected when using the --edit-todo flag.

I want to check to see if there is a way to detect the --edit-todo flag, and in those cases, have abort just exit the tool cleanly, without modifying the todo file. If not, I can add an "exit without writing changes option", or I will at least improve the documentation to further explain this situation.

For now, if you use --edit-todo, you can use the "write" command to continue the rebase, but it will write changes.

MitMaro commented 1 year ago

I did some digging this evening, and sadly, there isn't any way to determine if git --edit-todo was run, so the only option left if to add "Quit without writing file" feature.

Ideally, this would use the Q keybinding; however, I want to retain backwards compatibility. So, I will need to assign it a different binding.

forivall commented 1 year ago

Sounds good! Thank you so much for looking into it.

IIRC, I used the q keybinding, and it was my first time using --edit-todo, so i didn't anticipate that it would halt the rebase completely :sob:


Actually, I did a bit of digging, and while the editor isnt passed any special environment variables or arguments, I did find a difference between the initial rebase --interactive and --edit-todo:

Check the contents of $(git rev-parse --git-dir)/rebase-merge. In the initial git rebase --interactive, there's

git-rebase-todo  git-rebase-todo.backup  head-name  interactive
no-reschedule-failed-exec  onto  orig-head

but in --edit, there's

amend  author-script  done  end  git-rebase-todo  git-rebase-todo.backup
head-name  interactive  message  msgnum  no-reschedule-failed-exec
onto  orig-head  patch  stopped-sha

Overall, I think using the existing keybindings are good, but when those interactive rebase state files are present, just show some warnings.

forivall commented 1 year ago

(Honestly, at this point, I'm open to creating a PR myself this weekend for good ol' hacktoberfest, and to finally get my hands dirty with rust)

MitMaro commented 1 year ago

Thanks for digging in!

Absolutely support any effort to dig into this for hacktoberfest. I will also be happy to provide assistance. :)

but when those interactive rebase state files are present, just show some warnings.

I think I would avoid writing the file when using abort (q) in that case, since it's unexpected and leaves git in a odd state.

forivall commented 1 year ago

finally starting work on it. baby's first rust code https://github.com/forivall/git-interactive-rebase-tool/compare/forivall/vscode-settings...forivall:git-interactive-rebase-tool:forivall/edit-and-revise