zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: "Tom M." <boojum@stercus-accidit.com>, zsh-workers@zsh.org
Subject: Re: Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository
Date: Thu, 10 Aug 2017 17:14:16 +0000	[thread overview]
Message-ID: <1502385256.1253004.1069475528.211EB65F@webmail.messagingengine.com> (raw)
In-Reply-To: <CACfAdfa3-KTa6UJAEhkkjjVcxqa_8JdJweRE6ukTLmnAsj+8CA@mail.gmail.com>

Tom M. wrote on Thu, 10 Aug 2017 14:15 +0100:
> % dof --work-tree=$HOME add [Tab]
> ---- not a git repository

Could you try the following patch.  For me, it fixes «git add
--git-dir=$HOME/src/zsh/.git --work-tree=$HOME/src/zsh <TAB>».

@workers: Is ${(e)} the right thing to do in this context?  Without that
modifier, GIT_WORK_TREE would be set to '$HOME/src/zsh' literally (with the
dollar sign).

Supporting «GIT_DIR=/foo git bar <TAB>» would require a separate patch.

Cheers,

Daniel

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 518e6d198..45a0fa622 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6609,20 +6609,33 @@ __git_files_relative () {
 (( $+functions[__git_files] )) ||
 __git_files () {
   local compadd_opts opts tag description gitcdup gitprefix files expl
+  local pref
 
   zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
   zparseopts -D -E -a opts -- -cached -deleted -modified -others -ignored -unmerged -killed x+: --exclude+:
   tag=$1 description=$2; shift 2
 
-  gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
-  __git_command_successful $pipestatus || return 1
+  case $(_call_program gitinworktree git rev-parse --is-inside-work-tree 2>/dev/null) in
+    (true)
+      gitcdup=$(_call_program gitcdup git rev-parse --show-cdup 2>/dev/null)
+      __git_command_successful $pipestatus || return 1
 
-  gitprefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
-  __git_command_successful $pipestatus || return 1
+      gitprefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
+      __git_command_successful $pipestatus || return 1
+
+      local pref=$gitcdup$gitprefix$PREFIX
+      ;;
+    (false)
+      local pref=
+      ;;
+    (*)
+      # XXX what to do?
+      return 1
+      ;;
+  esac
 
   # TODO: --directory should probably be added to $opts when --others is given.
 
-  local pref=$gitcdup$gitprefix$PREFIX
 
   # First allow ls-files to pattern-match in case of remote repository
   files=(${(0)"$(_call_program files git ls-files -z --exclude-standard ${(q)opts} -- ${(q)${pref:+$pref\\\*}} 2>/dev/null)"})
@@ -7585,7 +7598,8 @@ _git() {
         ;;
       (option-or-argument)
         curcontext=${curcontext%:*:*}:git-$words[1]:
-	(( $+opt_args[--git-dir] )) && local -x GIT_DIR=$opt_args[--git-dir]
+        (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(e)opt_args[--git-dir]}
+        (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(e)opt_args[--work-tree]}
 	if ! _call_function ret _git-$words[1]; then
 	  if zstyle -T :completion:$curcontext: use-fallback; then
 	    _default && ret=0


  reply	other threads:[~2017-08-10 17:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-10 10:51 Tom M.
2017-08-10 13:15 ` Tom M.
2017-08-10 17:14   ` Daniel Shahaf [this message]
     [not found]     ` <CACfAdfbiQDH1M32QGxZg21G3xqVFcq5JB+ZSaYbGd5-czNgLbg@mail.gmail.com>
     [not found]       ` <1502401291.1328986.1069732648.63580361@webmail.messagingengine.com>
2017-08-10 21:59         ` Tom M.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502385256.1253004.1069475528.211EB65F@webmail.messagingengine.com \
    --to=d.s@daniel.shahaf.name \
    --cc=boojum@stercus-accidit.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).