about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2022-10-22 20:26:23 -0700
committerBart Schaefer <schaefer@zsh.org>2022-10-22 20:26:23 -0700
commita7e4394d1b06cbd004c85b5fecfe864eb93b4385 (patch)
treed11102f1a3d3ab4fc4b8ac8ea8e36864c0ee029a
parentb82e8e10355aba96cf3cf4e75bae71a6a3f8b235 (diff)
downloadzsh-a7e4394d1b06cbd004c85b5fecfe864eb93b4385.tar.gz
zsh-a7e4394d1b06cbd004c85b5fecfe864eb93b4385.tar.xz
zsh-a7e4394d1b06cbd004c85b5fecfe864eb93b4385.zip
50714: also complete in the 2nd argument of "git diff" anything that could
be in the 1st argument.

This probably shouldn't complete ranges but all other code is in common,
so leaving it to someone more familiar with _git to clean up.
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Unix/Command/_git27
2 files changed, 17 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 61390fc9d..0c11fe53b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-10-22  Bart Schaefer  <schaefer@Macadamia>
+
+	* 50714: Completion/Unix/Command/_git (_git-diff): also complete
+	in the 2nd argument position anything that could be in the 1st.
+
 2022-10-17  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 50786: Functions/Misc/add-zle-hook-widget: make match
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index cecb80ac3..6a1c4158a 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -808,18 +808,6 @@ _git-diff () {
 
       # Otherwise, more complex conditions need to be checked.
       case $CURRENT in
-        (1)
-          local files_alt='files::__git_changed-in-working-tree_files'
-          if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
-            files_alt='files::__git_changed-in-index_files'
-          fi
-
-          _alternative \
-            'commit-ranges::__git_commit_ranges' \
-            'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
-            $files_alt \
-            'blobs::__git_blobs ' && ret=0
-          ;;
         (2)
           # Check if first argument is something special. In case of committish ranges and committishs offer a full list compatible completions.
           if __git_is_committish_range $line[1]; then
@@ -841,10 +829,19 @@ _git-diff () {
           elif [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
             # Example: git diff --cached file1 <tab>
             __git_changed-in-index_files && ret=0
-          else
-            # Example: git diff file1 <tab>
-            __git_changed-in-working-tree_files && ret=0
           fi
+          ;&
+        (1)
+          local files_alt='files::__git_changed-in-working-tree_files'
+          if [[ -n ${opt_args[(I)--cached|--staged]} ]]; then
+            files_alt='files::__git_changed-in-index_files'
+          fi
+
+          _alternative \
+            'commit-ranges::__git_commit_ranges' \
+            'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
+            $files_alt \
+            'blobs::__git_blobs ' && ret=0
           ;;
         (*)
           if __git_is_committish_range $line[1]; then