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

[PATCH] Fix the option handling in __git_tree_files



Currently, completion attempts such as the following won't complete any
file (or directory) names beginning with "f":

	git ls-tree HEAD f<Tab>
	git archive HEAD f<Tab>

They fail because the __git_tree_files function (which is responsible
for extracting the contents of trees) doesn't handle its arguments
correctly.

Actually, there are two problems.

__git_tree_files expects the first parameter to specify the path of the
directory the caller is interested in (usually ".") and the remaining
parameters to specify the tree(s) which should be considered.  After
doing its job, __git_tree_files passes the list of extraced path names
on to _multi_parts.  The problem is that it also passes $@, which still
holds the list of trees (while the first parameter---that is, the
directory path---has been shifted away).

This could be fixed by simply not passing $@ on to _multi_parts.
However, __git_tree_files is sometimes called via functions such as
_alternative or _arguments, which might add compadd options in front of
the list of __git_tree_files arguments.  In this case, the assumptions
that $1 holds the directory path name and that the rest of $* specifies
the trees to consider are wrong.  (And passing $@ with the first
argument shifted away on to _multi_parts doesn't make sense in this
case, either.)

This patch fixes both problems and makes sure that any compadd options
are properly passed on to _multi_parts.
---
 Completion/Unix/Command/_git |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 83132b6..9c2d486 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2946,7 +2946,9 @@ __git_tree_files () {
   local multi_parts_opts
   local tree Path
   integer at_least_one_tree_added
-  local -a tree_files
+  local -a tree_files compadd_opts
+
+  zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
 
   [[ "$1" == */ ]] && Path="$1" || Path="${1:h}/"
   shift
@@ -2961,7 +2963,7 @@ __git_tree_files () {
   fi
 
   local expl
-  _wanted files expl 'tree file' _multi_parts -f $@ -- / tree_files
+  _wanted files expl 'tree file' _multi_parts -f $compadd_opts -- / tree_files
 }
 
 # TODO: deal with things that __git_heads and __git_tags has in common (i.e.,
-- 
Holger



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