wfxr / forgit

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

Fix _forgit_diff on macOS #375

Closed sandr01d closed 3 months ago

sandr01d commented 3 months ago

Check list

Description

In bash 3.2 uninitialized arrays contain one entry: an empty string, whereas in modern versions of bash they do not contain any entry. I could not find documentation on this but the behavior can be verified by running the following script:

local arr
echo "length=${#arr[@]}"
echo "content=${arr[@]}"

On bash 5.2.26 this prints

length=0
content=

On bash 3.2.57 this prints

length=1
content=

This PR makes sure the $commits and $files arrays are explicitly initialized as empty arrays to allow git to fall back to diffing local changes instead of trying to diff against a revision with a name of an empty string.

Fixes #373

Type of change

Test environment

sandr01d commented 3 months ago

Since this is a regression from #326, I'd like to merge this before the release next week.

cjappl commented 3 months ago

This still works with mac and fish 👍

It appears I also have the newer version of bash, so that's why we hadn't seen it before. Thanks for the quick fix.

keatsfonam commented 3 months ago

FYI this still doesn't work with bash 3.2: https://github.com/wfxr/forgit/issues/373#issuecomment-2019185780

sandr01d commented 3 months ago

Thanks for the hint with the bash docker container @keatsfonam, this helped me track it down. Will keep that in mind for future issues. I got it working in bash 3.2 in the container. Could you give it another try?

keatsfonam commented 3 months ago

@sandr01d new fix works for me, thank you