about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Unix/Command/_git14
2 files changed, 14 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 57a397ce1..05d228d62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-28  Gastón Haro  <harogaston@users.noreply.github.com>
+
+	* github #46: Completion/Unix/Command/_git: Better restrict
+	git-restore(1) file completions
+
 2020-03-28  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
 	* 45644: Functions/VCS_Info/Backends/VCS_INFO_get_data_git:
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)