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

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

Merged
merged 1 commit into from
Aug 27, 2023

Conversation

sandr01d
Copy link
Collaborator

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation

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

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

…amed

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).
@carlfriedrich
Copy link
Collaborator

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

@sandr01d
Copy link
Collaborator Author

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
Copy link
Collaborator

carlfriedrich commented Aug 24, 2023

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

@sandr01d sandr01d merged commit 48e91da into wfxr:master Aug 27, 2023
4 checks passed
@sandr01d sandr01d mentioned this pull request Apr 3, 2024
15 tasks
@sandr01d sandr01d deleted the fix-editor branch April 5, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants