wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.32k stars 136 forks source link

Fix opening files in editor when path contains spaces or file was renamed #323

Closed sandr01d closed 10 months ago

sandr01d commented 10 months ago

Check list

Description

Escaped variables in _forgit_add() and _forgit_diff() to fix opening files that contain spaces. Added a separate sed command for retrieving a file in _forgit_diff() that correctly handles renamed files (when opening the editor while diffing staged changes).

Type of change

Test environment

carlfriedrich commented 10 months ago

Hi @sandr01d can you give a minimal example to reproduce the error you're fixing here?

sandr01d commented 10 months ago

Hi @sandr01d can you give a minimal example to reproduce the error you're fixing here?

Reading back my description I really could have done a better job explaining this. So there are two issues that I fixed with this PR. The first one is that variables were not properly escaped, which led to issues trying to open them in the editor using the ctrl+e shortcut. You can reproduce it like this:

  1. Create a file with a name that contains spaces
  2. Use ga
  3. Press ctrl+e to edit the file you just created

Your editor will open, but it will open the wrong file (the file name will be everything before the first space).

The second issue affects files that were renamed:

# create any file
touch file
# commit the file
git add file
git commit -m "some message"
# rename the file
mv file new-name
# add the changes
git add .
# inspect the staged changed
gd --staged

The renamed file will show up correctly, but if you try to edit it by pressing ctrl+e, you editor will open a file that consists of both file names (testnew-name in this example).

carlfriedrich commented 10 months ago

@sandr01d Great, thanks a lot! Can confirm that the fix works for me.