justinmk / vim-dirvish

Directory viewer for Vim :zap:
Other
1.19k stars 64 forks source link

`-` (with vim-fugitive) clobbers in-progress git commit messages #216

Closed chiphogg closed 2 years ago

chiphogg commented 2 years ago

I am using this with the widely used fugitive plugin.

To reproduce:

  1. Start writing a commit message. (In a git repository, run :Git, stage some files, and press cc to commit.)
  2. Make some changes, and re-enter normal mode.
  3. Press -. This takes you to the .git directory, with the cursor on the COMMIT_EDITMSG file.
  4. Hit Enter to return to the file... where did the changes go?

While writing this issue description, I figured out that what's happening is that upon leaving the COMMIT_EDITMSG window, a commit is attempted (presumably by the fugitive plugin). Since we haven't saved our content, it thinks we're committing with an empty message, and thus aborts the commit. This clobbers all of the content in the window. If we hit Enter to return to the file, there is no way that I could see to restore the old content (e.g., undo and redo have no effect).

The most natural solution I can think of is to disable the - mapping inside COMMIT_EDITMSG. While it's easy for me to do this locally, I think a global solution is worthwhile because there is a significant risk to lose work for people who use both of these commonly used plugins... and the risk is worse for people who take the time to write good commit messages.

I'm not sure if the issue should be filed here, or with fugitive, but I figured this is a good place to start the conversation! :slightly_smiling_face:

justinmk commented 2 years ago

2. Make some changes, and re-enter normal mode. 3. Press -. This takes you to the .git directory, with the cursor on the COMMIT_EDITMSG file. 4. Hit Enter to return to the file... where did the changes go?

At this point, fugitive should have performed git commit. Is that not the case? If you didn't :write in step 2, Dirvish should report "E37: No write since last change".

Even if the commit message is saved & written, it's neverthless annoying when I hit - without actually wanting to trigger a commit. So I'm thinking about guarding against this.

chiphogg commented 2 years ago

This works perfectly for me. Thanks!