From b246d347999bda5629403592da7781dccc1ea0dd Mon Sep 17 00:00:00 2001 From: Wenxuan Zhang Date: Fri, 22 Nov 2019 17:16:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20path=20error=20on?= =?UTF-8?q?=20deleted=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: 🧨 Paths listed by forgit::diff will use repo's root as start point. Former-commit-id: 90e9235778a38c5adefe5ad22df3669dab573abb --- forgit.plugin.zsh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index dfebdc5..f6c002c 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -27,7 +27,7 @@ forgit::log() { # git diff viewer forgit::diff() { forgit::inside_work_tree || return 1 - local cmd files opts commit + local cmd files opts commit repo [[ $# -ne 0 ]] && { if git rev-parse "$1" -- &>/dev/null ; then commit="$1" && files=("${@:2}") @@ -36,14 +36,15 @@ forgit::diff() { fi } - cmd="git diff --color=always $commit -- {} | $forgit_pager" + repo="$(git rev-parse --show-toplevel)" + target="\$(echo {} | sed 's/.*] //')" + cmd="git diff --color=always $commit -- $repo/$target | $forgit_pager" opts=" $FORGIT_FZF_DEFAULT_OPTS +m -0 --preview=\"$cmd\" --bind=\"enter:execute($cmd |LESS='-R' less)\" $FORGIT_DIFF_FZF_OPTS " - cmd="echo" && hash realpath &>/dev/null && cmd="realpath --relative-to=." - eval "git diff --name-only $commit -- ${files[*]}| xargs -I% $cmd '$(git rev-parse --show-toplevel)/%'"| + eval "git diff --name-status $commit -- ${files[*]} | awk '{printf \"[%2s] \", \$1; \$1=\"\"; print \$0}'" | FZF_DEFAULT_OPTS="$opts" fzf } @@ -61,6 +62,7 @@ forgit::add() { --preview=\"git diff --color=always -- {-1} | $forgit_pager\" $FORGIT_ADD_FZF_OPTS " + # TODO: fix path contains blanks files=$(git -c color.status=always -c status.relativePaths=true status --short | grep -F -e "$changed" -e "$unmerged" -e "$untracked" | awk '{printf "[%10s] ", $1; $1=""; print $0}' |