From 5642a1a7307c17d452271b9e7aaa8bcec6a47f53 Mon Sep 17 00:00:00 2001 From: Tim <45259958+carlfriedrich@users.noreply.github.com> Date: Mon, 8 May 2023 18:51:13 +0200 Subject: [PATCH] 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 --- bin/git-forgit | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index c45ab56..1b3b9de 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -314,10 +314,11 @@ _forgit_cherry_pick() { [[ $fzf_exitval != 0 ]] && return $fzf_exitval [[ -z "$fzf_selection" ]] && return $fzf_exitval - old_IFS=$IFS IFS=$'\n' + ${IFS+"false"} && unset old_IFS || old_IFS="$IFS" + IFS=$'\n' # shellcheck disable=2207 commits=($(echo "$fzf_selection" | sort --numeric-sort --key=1 | cut -f2 | cut -d' ' -f1 | _forgit_reverse_lines)) - IFS=${old_IFS} + ${old_IFS+"false"} && unset IFS || IFS="$old_IFS" [ ${#commits[@]} -eq 0 ] && return 1 $git_cherry_pick "${commits[@]}" @@ -553,7 +554,8 @@ _forgit_revert_commit() { files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command preview="echo {} | cut -f2- | $_forgit_extract_sha | xargs -I% git show --color=always % -- $files | $_forgit_show_pager" - old_IFS=$IFS IFS=$'\n' + ${IFS+"false"} && unset old_IFS || old_IFS="$IFS" + IFS=$'\n' # shellcheck disable=2207 commits=($(eval "$cmd" | nl | @@ -561,7 +563,7 @@ _forgit_revert_commit() { sort --numeric-sort --key=1 | cut -f2- | sed 's/^[^a-f^0-9]*\([a-f0-9]*\).*/\1/')) - IFS=${old_IFS} + ${old_IFS+"false"} && unset IFS || IFS="$old_IFS" [ ${#commits[@]} -eq 0 ] && return 1 @@ -607,11 +609,12 @@ _forgit_ignore() { --preview=\"eval $cmd\" $FORGIT_IGNORE_FZF_OPTS " - old_IFS=$IFS IFS=$'\n' + ${IFS+"false"} && unset old_IFS || old_IFS="$IFS" + IFS=$'\n' # shellcheck disable=SC2206,2207 args=($@) && [[ $# -eq 0 ]] && args=($(_forgit_ignore_list | nl -nrn -w4 -s' ' | FZF_DEFAULT_OPTS="$opts" fzf | awk '{print $2}')) - IFS=${old_IFS} + ${old_IFS+"false"} && unset IFS || IFS="$old_IFS" [ ${#args[@]} -eq 0 ] && return 1 # shellcheck disable=SC2068 _forgit_ignore_get ${args[@]}