From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] _git-cat-file blob completion fix
Date: Wed, 19 Aug 2015 02:05:36 +0000 [thread overview]
Message-ID: <20150819020536.GE2005@tarsus.local2> (raw)
'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
next reply other threads:[~2015-08-19 2:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-19 2:05 Daniel Shahaf [this message]
2015-08-19 2:10 ` Mikael Magnusson
2015-08-19 23:24 ` Daniel Shahaf
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=20150819020536.GE2005@tarsus.local2 \
--to=d.s@daniel.shahaf.name \
--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).