zsh-workers
 help / color / mirror / code / Atom feed
* Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository
@ 2017-08-10 10:51 Tom M.
  2017-08-10 13:15 ` Tom M.
  0 siblings, 1 reply; 4+ messages in thread
From: Tom M. @ 2017-08-10 10:51 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]

Hello,

I'm using git bare repo and two aliases to manage my dotfile:

% grep dof .config/zsh/aliases
alias dofenv='GIT_DIR=$HOME/.dotfiles/ GIT_WORK_TREE=$HOME'
alias dof='dofenv git'

With the above, completion works for some git commands but not all:

dof sta [tab]
dof status

dof ad [tab]
dof add [tab]
---- not a git repository

zsh --version
zsh 5.3.1 (x86_64-unknown-linux-gnu)

How can I fix that?

T.

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

* Re: Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository
  2017-08-10 10:51 Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository Tom M.
@ 2017-08-10 13:15 ` Tom M.
  2017-08-10 17:14   ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Tom M. @ 2017-08-10 13:15 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 939 bytes --]

On 10 August 2017 at 11:51, Tom M. <boojum@stercus-accidit.com> wrote:

>
> % grep dof .config/zsh/aliases
> alias dofenv='GIT_DIR=$HOME/.dotfiles/ GIT_WORK_TREE=$HOME'
> alias dof='dofenv git'
>

I redefined the above aliases as a function:
dof() {
    if [[ $(pwd) = ${HOME} ]]; then
        /usr/bin/git --git-dir=${HOME}/.dotfiles --work-tree=${HOME} $@
    else
        /usr/bin/git $@
    fi
}

But this doesn't work either:

% dof status
fatal: Not a git repository: '/home/user/dotfiles'

The weird thing is that this is working:

% dof --work-tree=$HOME status
On branch master
Your branch is up-to-date with 'origin/master'.

But completion for add still doesn't:

% dof --work-tree=$HOME add [Tab]
---- not a git repository

The issues seems to be solely with git add or, in my case with dof add.
Things like {dof,g} log or show work like expected. Am I missing something
here or is it a bug in zsh completion for git add?


T.

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

* Re: Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository
  2017-08-10 13:15 ` Tom M.
@ 2017-08-10 17:14   ` Daniel Shahaf
       [not found]     ` <CACfAdfbiQDH1M32QGxZg21G3xqVFcq5JB+ZSaYbGd5-czNgLbg@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2017-08-10 17:14 UTC (permalink / raw)
  To: Tom M., zsh-workers

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


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

* Re: Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository
       [not found]       ` <1502401291.1328986.1069732648.63580361@webmail.messagingengine.com>
@ 2017-08-10 21:59         ` Tom M.
  0 siblings, 0 replies; 4+ messages in thread
From: Tom M. @ 2017-08-10 21:59 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

On 10 August 2017 at 22:41, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:

>
> Try moving --git-dir and --work-tree to between 'git' and 'add'.
>


% git --git-dir=$HOME/.dotfiles --work-tree=$HOME/ add -f back [Tab]
% git --git-dir=$HOME/.dotfiles --work-tree=$HOME/ add -f backup

It works! Albeit completion is very, very slow - only for this particular
use-case. I'm assuming that this is due to large number of files in $home?
Or can it be a bit speedier?

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

end of thread, other threads:[~2017-08-10 22:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-10 10:51 Zsh git filename completion with “--git-dir=… --work-tree=…”: not a git repository Tom M.
2017-08-10 13:15 ` Tom M.
2017-08-10 17:14   ` Daniel Shahaf
     [not found]     ` <CACfAdfbiQDH1M32QGxZg21G3xqVFcq5JB+ZSaYbGd5-czNgLbg@mail.gmail.com>
     [not found]       ` <1502401291.1328986.1069732648.63580361@webmail.messagingengine.com>
2017-08-10 21:59         ` Tom M.

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