Skip to content

Commit 5642a1a

Browse files
Use correct IFS store/restore mechanism (#306)
The previous implementation had the problem that if IFS was not set before, it was set to an empty string after restoring, which is not the same as being unset. This broke grc / git forgit revert_commit, since "git revert" was being interpreted as the command name instead of command and argument. The correct way is to check whether IFS is unset and, if so, unset it again afterwards. See for reference: https://unix.stackexchange.com/a/264947/317320
1 parent f74aa93 commit 5642a1a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

bin/git-forgit

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,11 @@ _forgit_cherry_pick() {
314314
[[ $fzf_exitval != 0 ]] && return $fzf_exitval
315315
[[ -z "$fzf_selection" ]] && return $fzf_exitval
316316

317-
old_IFS=$IFS IFS=$'\n'
317+
${IFS+"false"} && unset old_IFS || old_IFS="$IFS"
318+
IFS=$'\n'
318319
# shellcheck disable=2207
319320
commits=($(echo "$fzf_selection" | sort --numeric-sort --key=1 | cut -f2 | cut -d' ' -f1 | _forgit_reverse_lines))
320-
IFS=${old_IFS}
321+
${old_IFS+"false"} && unset IFS || IFS="$old_IFS"
321322
[ ${#commits[@]} -eq 0 ] && return 1
322323

323324
$git_cherry_pick "${commits[@]}"
@@ -553,15 +554,16 @@ _forgit_revert_commit() {
553554
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
554555
preview="echo {} | cut -f2- | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager"
555556

556-
old_IFS=$IFS IFS=$'\n'
557+
${IFS+"false"} && unset old_IFS || old_IFS="$IFS"
558+
IFS=$'\n'
557559
# shellcheck disable=2207
558560
commits=($(eval "$cmd" |
559561
nl |
560562
FZF_DEFAULT_OPTS="$opts" fzf --preview="$preview" -m |
561563
sort --numeric-sort --key=1 |
562564
cut -f2- |
563565
sed 's/^[^a-f^0-9]*\([a-f0-9]*\).*/\1/'))
564-
IFS=${old_IFS}
566+
${old_IFS+"false"} && unset IFS || IFS="$old_IFS"
565567

566568
[ ${#commits[@]} -eq 0 ] && return 1
567569

@@ -607,11 +609,12 @@ _forgit_ignore() {
607609
--preview=\"eval $cmd\"
608610
$FORGIT_IGNORE_FZF_OPTS
609611
"
610-
old_IFS=$IFS IFS=$'\n'
612+
${IFS+"false"} && unset old_IFS || old_IFS="$IFS"
613+
IFS=$'\n'
611614
# shellcheck disable=SC2206,2207
612615
args=($@) && [[ $# -eq 0 ]] && args=($(_forgit_ignore_list | nl -nrn -w4 -s' ' |
613616
FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $2}'))
614-
IFS=${old_IFS}
617+
${old_IFS+"false"} && unset IFS || IFS="$old_IFS"
615618
[ ${#args[@]} -eq 0 ] && return 1
616619
# shellcheck disable=SC2068
617620
_forgit_ignore_get ${args[@]}

0 commit comments

Comments
 (0)