Skip to content

Commit

Permalink
Modify multiple files at once in ga & gcf (#279)
Browse files Browse the repository at this point in the history
Checkout/Add files in a single command in _forgit_add and _forgit_checkout_file() instead of processing each file individually with xargs. This has the following benefits:

    It's faster
    Prevents git from spamming "Updated 1 path from the index" for each file when checking out files
  • Loading branch information
sandr01d committed Jan 20, 2023
1 parent be8c306 commit c098bf2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/git-forgit
Expand Up @@ -170,7 +170,7 @@ _forgit_add() {
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' |
FZF_DEFAULT_OPTS="$opts" fzf |
sh -c "$extract")
[[ -n "$files" ]] && echo "$files"| tr '\n' '\0' |xargs -0 -I% git add % && git status -su && return
[[ -n "$files" ]] && echo "$files"| tr '\n' '\0' | git add --pathspec-file-nul --pathspec-from-file - && git status -su && return
echo 'Nothing to add.'
}

Expand Down Expand Up @@ -396,7 +396,7 @@ _forgit_checkout_file() {
$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' | xargs -0 -I% git checkout %
[[ -n "$files" ]] && echo "$files" | tr '\n' '\0' | git checkout --pathspec-file-nul --pathspec-from-file -
}

# git checkout-branch selector
Expand Down

0 comments on commit c098bf2

Please sign in to comment.