Merge pull request #216 from carlfriedrich/improve-cherry-pick

Improve cherry-pick
This commit is contained in:
Wenxuan 2022-07-14 08:41:24 +08:00 committed by GitHub
commit d2c2848037
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -243,8 +243,9 @@ Customizing fzf options for each command individually is also supported:
| `gss` | `FORGIT_STASH_FZF_OPTS` |
| `gclean` | `FORGIT_CLEAN_FZF_OPTS` |
| `grb` | `FORGIT_REBASE_FZF_OPTS` |
| `gbl` | `FORGIT_BLAME_FZF_OPTS` |
| `gbl` | `FORGIT_BLAME_FZF_OPTS` |
| `gfu` | `FORGIT_FIXUP_FZF_OPTS` |
| `gcp` | `FORGIT_CHERRY_PICK_FZF_OPTS` |
Complete loading order of fzf options is:

View file

@ -12,6 +12,11 @@ function forgit::inside_work_tree
git rev-parse --is-inside-work-tree >/dev/null;
end
function forgit::reverse_lines
# tac is not available on OSX, tail -r is not available on Linux, so we use either of them
tac 2> /dev/null || tail -r
end
set -g forgit_pager "$FORGIT_PAGER"
set -g forgit_show_pager "$FORGIT_SHOW_PAGER"
set -g forgit_diff_pager "$FORGIT_DIFF_PAGER"
@ -339,12 +344,13 @@ function forgit::cherry::pick -d "git cherry-picking" --argument-names 'target'
set opts "
--preview=\"$preview\"
$FORGIT_FZF_DEFAULT_OPTS
-m -0
-m -0 --tiebreak=index
$FORGIT_CHERRY_PICK_FZF_OPTS
"
echo $base
echo $target
git cherry "$base" "$target" --abbrev -v | cut -d ' ' -f2- |
env FZF_DEFAULT_OPTS="$opts" fzf | cut -d' ' -f1 |
git cherry "$base" "$target" --abbrev -v | forgit::reverse_lines |
env FZF_DEFAULT_OPTS="$opts" fzf | cut -d' ' -f2 | forgit::reverse_lines |
xargs -I% git cherry-pick %
end

View file

@ -3,6 +3,8 @@
forgit::warn() { printf "%b[Warn]%b %s\n" '\e[0;33m' '\e[0m' "$@" >&2; }
forgit::info() { printf "%b[Info]%b %s\n" '\e[0;32m' '\e[0m' "$@" >&2; }
forgit::inside_work_tree() { git rev-parse --is-inside-work-tree >/dev/null; }
# tac is not available on OSX, tail -r is not available on Linux, so we use either of them
forgit::reverse_lines() { (tac 2> /dev/null || tail -r) }
# optional render emoji characters (https://github.com/wfxr/emoji-cli)
hash emojify &>/dev/null && forgit_emojify='|emojify'
@ -156,10 +158,11 @@ forgit::cherry::pick() {
opts="
$FORGIT_FZF_DEFAULT_OPTS
--preview=\"$preview\"
-m -0
-m -0 --tiebreak=index
$FORGIT_CHERRY_PICK_FZF_OPTS
"
git cherry "$base" "$target" --abbrev -v | cut -d ' ' -f2- |
FZF_DEFAULT_OPTS="$opts" fzf | cut -d' ' -f1 |
git cherry "$base" "$target" --abbrev -v | forgit::reverse_lines |
FZF_DEFAULT_OPTS="$opts" fzf | cut -d' ' -f2 | forgit::reverse_lines |
xargs -I% git cherry-pick %
}