Skip to content

Commit

Permalink
Fix ga, gsp & gcf with older git versions (#335)
Browse files Browse the repository at this point in the history
Removes the usage of --pathspec-file-nul (which is not available in older git versions) in favor of storing the file names passed to the git command in an array instead of a string.
  • Loading branch information
sandr01d authored Apr 9, 2024
1 parent 131f2c1 commit 1c34d0d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,15 @@ _forgit_add() {
--bind=\"alt-e:execute-silent($FORGIT edit_add_file {})+refresh-preview\"
$FORGIT_ADD_FZF_OPTS
"
files=$(git -c color.status=always -c status.relativePaths=true status -su |
files=()
while IFS='' read -r file; do
files+=("$file")
done < <(git -c color.status=always -c status.relativePaths=true status -su |
grep -F -e "$changed" -e "$unmerged" -e "$untracked" |
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' |
FZF_DEFAULT_OPTS="$opts" fzf |
_forgit_get_single_file_from_add_line)
[[ -n "$files" ]] && echo "$files"| tr '\n' '\0' | _forgit_git_add --pathspec-file-nul --pathspec-from-file - && git status -su && return
[[ "${#files[@]}" -gt 0 ]] && _forgit_git_add "${files[@]}" && git status -su && return
echo 'Nothing to add.'
}

Expand Down Expand Up @@ -458,9 +461,13 @@ _forgit_stash_push() {
$FORGIT_STASH_PUSH_FZF_OPTS
"
# Show both modified and untracked files
files=$(git ls-files --exclude-standard --modified --others | FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}")
[[ -z "$files" ]] && return 1
echo "${files[@]}" | tr '\n' '\0' | _forgit_git_stash_push ${msg:+-m "$msg"} -u --pathspec-file-nul --pathspec-from-file -
files=()
while IFS='' read -r file; do
files+=("$file")
done < <(git ls-files --exclude-standard --modified --others |
FZF_DEFAULT_OPTS="$opts" fzf --preview="$FORGIT stash_push_preview {}")
[[ "${#files[@]}" -eq 0 ]] && return 1
_forgit_git_stash_push ${msg:+-m "$msg"} -u "${files[@]}"
}

# git clean selector
Expand Down Expand Up @@ -651,8 +658,12 @@ _forgit_checkout_file() {
--preview=\"$FORGIT checkout_file_preview {}\"
$FORGIT_CHECKOUT_FILE_FZF_OPTS
"
files="$(git ls-files --modified "$(git rev-parse --show-toplevel)"| FZF_DEFAULT_OPTS="$opts" fzf)"
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | _forgit_git_checkout_file --pathspec-file-nul --pathspec-from-file -
files=()
while IFS='' read -r file; do
files+=("$file")
done < <(git ls-files --modified "$(git rev-parse --show-toplevel)" |
FZF_DEFAULT_OPTS="$opts" fzf)
[[ "${#files[@]}" -gt 0 ]] && _forgit_git_checkout_file "${files[@]}"
}

_forgit_git_checkout_branch() {
Expand Down

0 comments on commit 1c34d0d

Please sign in to comment.