From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
Cc: zsh-workers@zsh.org
Subject: Re: _git-reset doesn't complete newly staged files
Date: Wed, 09 Mar 2016 23:33:18 +0000 [thread overview]
Message-ID: <20160309233318.GA27898@tarsus.local2> (raw)
In-Reply-To: <20160309132444.GA2428@tarsus.local2>
[-- Attachment #1: Type: text/plain, Size: 708 bytes --]
Daniel Shahaf wrote on Wed, Mar 09, 2016 at 13:24:44 +0000:
> Jun T. wrote on Mon, Mar 07, 2016 at 12:16:54 +0900:
> > In the case of
> >
> > % git reset commit <TAB> # commit is not HEAD
> >
> > I have no idea what to do, so I just added __git_ignore_line
> > to the original code.
>
> I think you're looking for «git diff-index --cached -z --name-only
> $treeish».
Turns out there was already a helper function that did almost exactly
that, so we can just reuse it. Patch attached.
I took the liberty of changing the tag and description you used, since
"staged files" isn't exactly right for this syntax: files that are in
$treeish but not staged may also be completed.
WDYT?
Thanks,
Daniel
[-- Attachment #2: 0001-NNNNN-after-38074-_git-reset-treeish-complete-only-s.patch --]
[-- Type: text/x-diff, Size: 3390 bytes --]
>From 92fcd0ed18f4c0122f7cdda7930979cd624a33cd Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Wed, 9 Mar 2016 22:11:22 +0000
Subject: [PATCH] NNNNN (after 38074): _git reset $treeish: complete only
staged files
---
Completion/Unix/Command/_git | 56 ++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 36 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 2dd9a80..b1a7431 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1373,16 +1373,11 @@ _git-reset () {
case $state in
(file)
- local commit=HEAD
- if [[ -n $line[1] ]] && __git_is_committish $line[1]; then
- commit=$line[1]
+ local tree=HEAD
+ if [[ -n $line[1] ]] && __git_is_treeish $line[1]; then
+ tree=$line[1]
fi
- if [[ $commit == HEAD ]]; then
- __git_ignore_line __git_staged_files && ret=0
- else
- __git_ignore_line __git_tree_files ${PREFIX:-.} $commit && ret=0
- fi
- ;;
+ __git_ignore_line __git_treeish-to-index_files $tree && ret=0
esac
return ret
@@ -6077,16 +6072,28 @@ __git_killed_files () {
__git_files --killed killed-files 'killed file' $*
}
-(( $+functions[__git_changed-in-index_files] )) ||
-__git_changed-in-index_files () {
+(( $+functions[__git_diff-index_files] )) ||
+__git_diff-index_files () {
+ local tree=$1 description=$2 tag=$3; shift 3
local files expl
- files=$(_call_program files git diff-index -z --name-only --no-color --cached HEAD 2>/dev/null)
+ files=$(_call_program files git diff-index -z --name-only --no-color --cached $tree 2>/dev/null)
__git_command_successful $pipestatus || return 1
files=(${(0)"$(__git_files_relative $files)"})
__git_command_successful $pipestatus || return 1
- _wanted changed-in-index-files expl 'changed in index file' _multi_parts $@ - / files
+ _wanted $tag expl $description _multi_parts $@ - / files
+}
+
+(( $+functions[__git_changed-in-index_files] )) ||
+__git_changed-in-index_files () {
+ __git_diff-index_files HEAD 'changed in index file' changed-in-index-files "$@"
+}
+
+(( $+functions[__git_treeish-to-index_files] )) ||
+__git_treeish-to-index_files () {
+ local tree=$1; shift
+ __git_diff-index_files $tree "files different between ${(qq)tree} and the index" treeish-to-index-files "$@"
}
(( $+functions[__git_changed-in-working-tree_files] )) ||
@@ -6145,29 +6152,6 @@ __git_tree_files () {
_wanted files expl 'tree file' _multi_parts -f $compadd_opts -- / tree_files
}
-(( $+functions[__git_staged_files] )) ||
-__git_staged_files () {
- local -a slist staged_files
- local item expl i
-
- slist=(${(0)"$(_call_program staged-files git status -z -uno 2>/dev/null)"})
- __git_command_successful $pipestatus || return 1
-
- for (( i = 1; i <= $#slist; ++i )) do
- item=$slist[i]
- if [[ $item == (DD|AA|U|?U)* ]]; then
- continue #XXX skip unmerged files
- elif [[ $item == R* ]]; then
- staged_files+=( $item[4,-1] $slist[++i] )
- elif [[ $item == [ACDM]* ]]; then
- staged_files+=( $item[4,-1] )
- fi
- done
- staged_files=( ${(0)"$(__git_files_relative ${(pj:\0:)staged_files})"} )
-
- _wanted staged-files expl 'staged file' compadd "$@" -a - staged_files
-}
-
# Repository Argument Types
(( $+functions[__git_remote_repositories] )) ||
next prev parent reply other threads:[~2016-03-09 23:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 8:08 Jun T.
2016-03-03 5:07 ` Jun T.
2016-03-07 3:16 ` Jun T.
2016-03-09 13:24 ` Daniel Shahaf
2016-03-09 23:33 ` Daniel Shahaf [this message]
2016-03-10 23:15 ` [PATCH] _git: Fix completion of diffs against the index when treeish isn't shell-safe Daniel Shahaf
2016-03-10 12:03 ` _git-reset doesn't complete newly staged files Jun T.
2016-03-10 14:35 ` Mikael Magnusson
2016-03-10 23:20 ` __git_ignore_line positional argument (un)escaping (was: Re: _git-reset doesn't complete newly staged files) Daniel Shahaf
2016-03-11 8:24 ` Jun T.
2016-03-11 22:13 ` 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=20160309233318.GA27898@tarsus.local2 \
--to=d.s@daniel.shahaf.name \
--cc=takimoto-j@kba.biglobe.ne.jp \
--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).