zsh-workers
 help / color / mirror / Atom feed
* [PATCH v2] _git-grep: Complete files when outside git repos
@ 2020-09-25  7:47 Guido Cella
  2020-09-25  7:52 ` Guido Cella
  2020-09-26 10:23 ` [PATCH v3] " Guido Cella
  0 siblings, 2 replies; 4+ messages in thread
From: Guido Cella @ 2020-09-25  7:47 UTC (permalink / raw)
  To: zsh-workers

---
 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] _git-grep: Complete files when outside git repos
  2020-09-25  7:47 [PATCH v2] _git-grep: Complete files when outside git repos Guido Cella
@ 2020-09-25  7:52 ` Guido Cella
  2020-09-26  5:27   ` Mikael Magnusson
  2020-09-26 10:23 ` [PATCH v3] " Guido Cella
  1 sibling, 1 reply; 4+ messages in thread
From: Guido Cella @ 2020-09-25  7:52 UTC (permalink / raw)
  To: zsh-workers

Sorry, I noticed that this only works because I have configured
grep.fallbacktonoindex after sending the patch. =(.
And sorry again for not replying to the existing thread, I'm not
familiar with sending patches by email and thought git send-email would
prompt me for the In-Reply-To Message-ID when sending the updated patch
but it didn't.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] _git-grep: Complete files when outside git repos
  2020-09-25  7:52 ` Guido Cella
@ 2020-09-26  5:27   ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2020-09-26  5:27 UTC (permalink / raw)
  To: Guido Cella; +Cc: zsh-workers

On 9/25/20, Guido Cella <guidocella91@gmail.com> wrote:
> Sorry, I noticed that this only works because I have configured
> grep.fallbacktonoindex after sending the patch. =(.
> And sorry again for not replying to the existing thread, I'm not
> familiar with sending patches by email and thought git send-email would
> prompt me for the In-Reply-To Message-ID when sending the updated patch
> but it didn't.

If you want to do this, you have to give --in-reply-to='<blabla>' when
you use git send-email.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3] _git-grep: Complete files when outside git repos
  2020-09-25  7:47 [PATCH v2] _git-grep: Complete files when outside git repos Guido Cella
  2020-09-25  7:52 ` Guido Cella
@ 2020-09-26 10:23 ` Guido Cella
  1 sibling, 0 replies; 4+ messages in thread
From: Guido Cella @ 2020-09-26 10:23 UTC (permalink / raw)
  To: zsh-workers

This works only if you passed --no-index or have git config
grep.fallbackToNoIndex set to true, but we have no other completions to
provide outside of git repositories anyway so we skip the check.
---
I misunderstood the request to use _call_program as referring to getting
the config because I was in a rush to fix the error. Now this just
completes all files whenever we're outside a git repository but with the
ability to change the called program (I initially just used rev-parse
because it's called directly in 2 other places).

Also, we're not done with --no-index since it still has the effect of
not being able to complete treeishs within git repositories.

 Completion/Unix/Command/_git | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 05e2a23..4f5fdf4 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1037,6 +1037,11 @@ _git-grep () {
   # don't complete treeishs.
   case $state in
     (tree-or-file)
+      if ! _call_program within-repo git rev-parse >&/dev/null; then
+        _files && ret=0
+        return ret
+      fi
+
       integer first_tree last_tree start end i
 
       (( start = words[(I)(-f|-e)] > 0 ? 1 : 2 ))
-- 
2.28.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-26 10:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25  7:47 [PATCH v2] _git-grep: Complete files when outside git repos Guido Cella
2020-09-25  7:52 ` Guido Cella
2020-09-26  5:27   ` Mikael Magnusson
2020-09-26 10:23 ` [PATCH v3] " Guido Cella

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git