Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH v2] _git-grep: Complete files when outside git repos



---
 Completion/Unix/Command/_git | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 05e2a23..2847d1c 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1033,10 +1033,21 @@ _git-grep () {
     ': :_guard "^-*" pattern' \
     '*:: :->tree-or-file' && ret=0
 
-  # TODO: If --cached, --no-index, -O, or --open-files-in-pager was given,
+  # TODO: If --cached, -O, or --open-files-in-pager was given,
   # don't complete treeishs.
   case $state in
     (tree-or-file)
+      # Check if we're not in a git repository
+      # from the exit status of an arbitrary git command.
+      if ! git rev-parse 2>/dev/null && [[
+        words[(I)--no-index] -ne 0 ||
+        "$(_call_program get-grep-fallbacktonoindex-option git config --type=bool grep.fallbackToNoIndex)" \
+        == 'true'
+      ]]; then
+        _files && ret=0
+        return ret
+      fi
+
       integer first_tree last_tree start end i
 
       (( start = words[(I)(-f|-e)] > 0 ? 1 : 2 ))
@@ -1052,7 +1063,7 @@ _git-grep () {
         fi
       done
 
-      # TODO: Need to respect --cached and --no-index here.
+      # TODO: Need to respect --cached here.
       if (( last_tree == 0 || last_tree == end )); then
         if (( first_tree == 0 )); then
           _alternative \
-- 
2.28.0





Messages sorted by: Reverse Date, Date, Thread, Author