about summary refs log tree commit diff
path: root/Completion/Unix/Command/_git
diff options
context:
space:
mode:
authorGastón Haro <harogaston@users.noreply.github.com>2020-01-21 21:39:29 -0300
committerDaniel Shahaf <d.s@daniel.shahaf.name>2020-03-28 22:49:41 +0000
commitf306221674af05422c9fd60410f2ab054e123255 (patch)
tree066eea085567592d5ca3ff432a565d10733d9f75 /Completion/Unix/Command/_git
parent2f2aa360bc9a966f819474d349b79fd13191cb16 (diff)
downloadzsh-f306221674af05422c9fd60410f2ab054e123255.tar.gz
zsh-f306221674af05422c9fd60410f2ab054e123255.tar.xz
zsh-f306221674af05422c9fd60410f2ab054e123255.zip
github #46: Better restrict git-restore(1) file completions
Add support to the -S and -W options.

Remove the facility for completing files from the tree specified by the
--source argument since, upon testing in git 2.26.0, that doesn't seem
to be correct behaviour.  (Note git-restore(1) says the command is
experimental and its semantics may change.)  See discussion on the PR
for details.
Diffstat (limited to 'Completion/Unix/Command/_git')
-rw-r--r--Completion/Unix/Command/_git14
1 files changed, 9 insertions, 5 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 9a44ddbbe..15280db70 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1567,13 +1567,17 @@ _git-restore() {
 
   case $state in
     pathspecs)
-      if [[ -z ${opt_args[(I)-s|--source|-S|--staged]} ]] &&
-	# use index as a default base unless -S is specified
-	__git_ignore_line __git_modified_files
+      integer opt_S opt_W
+      [[ -n ${opt_args[(I)-S|--staged]} ]] && opt_S=1
+      [[ -n ${opt_args[(I)-W|--worktree]} ]] && opt_W=1
+      if (( opt_S && opt_W ))
       then
-	ret=0
+        __git_ignore_line __git_changed_files && ret=0
+      elif (( opt_S ))
+      then
+        __git_ignore_line __git_changed-in-index_files && ret=0
       else
-	__git_ignore_line __git_tree_files ${PREFIX:-.} ${(Qv)opt_args[(i)-s|--source]:-HEAD} && ret=0
+        __git_ignore_line __git_changed-in-working-tree_files && ret=0
       fi
     ;;
     sources)