zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _git-cat-file blob completion fix
@ 2015-08-19  2:05 Daniel Shahaf
  2015-08-19  2:10 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2015-08-19  2:05 UTC (permalink / raw)
  To: zsh-workers

'git cat-file HEAD:<TAB>', when cwd is a subdirectory of a repository,
completes files within that subdirectory, but should complete files
relative to the repository root.  The attach patch implements that.

Review would be appreciated — I might have missed something while
reverse-engineering the semantics of everything.  (I already checked
gitrevisions(7) and tested 'git rev-parse HEAD:<TAB>'.)

I didn't make --root-relative a zparseopts option because I didn't want
to have to name the same as git option it maps to.

Cheers,

Daniel


diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 6922393..e9adc70 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5739,7 +5739,7 @@ __git_tree_ishs () {
 __git_objects () {
   compset -P '*:'
   if [[ -n $IPREFIX ]]; then
-    __git_tree_files "$PREFIX" "${IPREFIX%:}"
+    __git_tree_files --root-relative "$PREFIX" "${IPREFIX%:}"
   else
     _alternative \
       'revisions::__git_revisions' \
@@ -5984,12 +5984,23 @@ __git_changed_files () {
     'changed-in-working-tree-files::__git_changed-in-working-tree_files'
 }
 
+#     __git_tree_files [--root-relative] FSPATH TREEISH [TREEISH...] [COMPADD OPTIONS]
+#
+# Complete [presently: a single level of] repository files under FSPATH.
+# FSPATH is interpreted as a directory path within each TREEISH.
+# FSPATH is relative to cwd, unless --root-relative is specified, in
+# which case it is relative to the repository root.
 (( $+functions[__git_tree_files] )) ||
 __git_tree_files () {
   local multi_parts_opts
   local tree Path
   integer at_least_one_tree_added
   local -a tree_files compadd_opts
+  local -a extra_args
+
+  if [[ $1 == --root-relative ]]; then
+    extra_args+=(--full-tree)
+  fi
 
   zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
 
@@ -5997,7 +6008,7 @@ __git_tree_files () {
   shift
   (( at_least_one_tree_added = 0 ))
   for tree in $*; do
-    tree_files+=(${(ps:\0:)"$(_call_program tree-files git ls-tree --name-only -z $tree $Path 2>/dev/null)"})
+    tree_files+=(${(ps:\0:)"$(_call_program tree-files git ls-tree $extra_args --name-only -z $tree $Path 2>/dev/null)"})
     __git_command_successful $pipestatus && (( at_least_one_tree_added = 1 ))
   done
 


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

* Re: [PATCH] _git-cat-file blob completion fix
  2015-08-19  2:05 [PATCH] _git-cat-file blob completion fix Daniel Shahaf
@ 2015-08-19  2:10 ` Mikael Magnusson
  2015-08-19 23:24   ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2015-08-19  2:10 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh workers

On Wed, Aug 19, 2015 at 4:05 AM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> 'git cat-file HEAD:<TAB>', when cwd is a subdirectory of a repository,
> completes files within that subdirectory, but should complete files
> relative to the repository root.  The attach patch implements that.
>
> Review would be appreciated — I might have missed something while
> reverse-engineering the semantics of everything.  (I already checked
> gitrevisions(7) and tested 'git rev-parse HEAD:<TAB>'.)
>
> I didn't make --root-relative a zparseopts option because I didn't want
> to have to name the same as git option it maps to.

You can say HEAD:./foo to specify foo relative to the current
directory. However, this doesn't work in the current completer either
afaict, so it's not a regression to apply this patch :).

-- 
Mikael Magnusson


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

* Re: [PATCH] _git-cat-file blob completion fix
  2015-08-19  2:10 ` Mikael Magnusson
@ 2015-08-19 23:24   ` Daniel Shahaf
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2015-08-19 23:24 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh workers

Mikael Magnusson wrote on Wed, Aug 19, 2015 at 04:10:42 +0200:
> On Wed, Aug 19, 2015 at 4:05 AM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > 'git cat-file HEAD:<TAB>', when cwd is a subdirectory of a repository,
> > completes files within that subdirectory, but should complete files
> > relative to the repository root.  The attach patch implements that.
> >
> > Review would be appreciated — I might have missed something while
> > reverse-engineering the semantics of everything.  (I already checked
> > gitrevisions(7) and tested 'git rev-parse HEAD:<TAB>'.)
> >
> > I didn't make --root-relative a zparseopts option because I didn't want
> > to have to name the same as git option it maps to.
> 
> You can say HEAD:./foo to specify foo relative to the current
> directory. However, this doesn't work in the current completer either
> afaict, so it's not a regression to apply this patch :).

To be applied on top of the previous.

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 23113ac..18df09e 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5739,7 +5739,11 @@ __git_tree_ishs () {
 __git_objects () {
   compset -P '*:'
   if [[ -n $IPREFIX ]]; then
-    __git_tree_files --root-relative "$PREFIX" "${IPREFIX%:}"
+    if compset -P ./ ; then
+      __git_tree_files                 "$PREFIX" "${IPREFIX%:./}"
+    else
+      __git_tree_files --root-relative "$PREFIX" "${IPREFIX%:}"
+    fi
   else
     _alternative \
       'revisions::__git_revisions' \


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

end of thread, other threads:[~2015-08-19 23:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19  2:05 [PATCH] _git-cat-file blob completion fix Daniel Shahaf
2015-08-19  2:10 ` Mikael Magnusson
2015-08-19 23:24   ` Daniel Shahaf

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