Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Fix _git-reset bugs and add new options
- X-seq: zsh-workers 28019
- From: Holger Weiss <holger@xxxxxxxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxx>
- Subject: [PATCH] Fix _git-reset bugs and add new options
- Date: Wed, 9 Jun 2010 18:33:54 +0200
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Zsh Workers <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
In quite a few situations, the completion for git-reset(1) doesn't work
as expected. Here are some examples (which assume we're in a Git
repository which holds a single file named "file.txt"):
# This should complete "file.txt", but it doesn't:
git reset HEAD f<Tab>
# This shouldn't complete "file.txt", but it does (well, it
# tries, but it currently fails due to the __git_tree_files bug
# I described in an earlier posting¹):
git reset --mixed HEAD f<Tab>
# This suggests --hard, --mixed, and --soft; but none of these
# options may be combined with "--merge":
git reset --merge --<Tab>
This patch fixes these problems. While at it, the patch also adds
support for git-reset(1)'s -p/--patch and -q/--quiet options; and it
improves the descriptions for the --merge and --mixed options (most
notably, it makes clear that --mixed _does_ touch the index). The patch
requires a __git_is_committish function, see my previous posting.²
---
¹ http://www.zsh.org/mla/workers/2010/msg00468.html
² http://www.zsh.org/mla/workers/2010/msg00469.html
Completion/Unix/Command/_git | 39 +++++++++++++++++++++++++--------------
1 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index e53018f..c394e08 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1983,22 +1983,33 @@ _git-rerere () {
(( $+functions[_git-reset] )) ||
_git-reset () {
- local commit_arg path_arg
+ local curcontext=$curcontext state line
+ typeset -A opt_args
- if [[ $words[2] == --mixed ]]; then
- commit_arg=':commit:__git_revisions'
- path_arg="*:file:__git_tree_files . $words[3]"
- else
- commit_arg='::commit:__git_revisions'
- fi
+ _arguments -C -S -A '-*' \
+ '(-q --quiet)'{-q,--quiet}'[be quiet, only report errors]' \
+ '::commit:__git_revisions' \
+ - reset-head \
+ '( --soft --hard --merge --keep)--mixed[reset the index but not the working tree (default)]' \
+ '(--mixed --hard --merge --keep)--soft[do not touch the index file nor the working tree]' \
+ '(--mixed --soft --merge --keep)--hard[match the working tree and index to the given tree]' \
+ '(--mixed --soft --hard --keep)--merge[reset out of a conflicted merge]' \
+ '(--mixed --soft --hard --merge )--keep[like --hard, but keep local working tree changes]' \
+ - reset-paths \
+ '(-p --patch)'{-p,--patch}'[select diff hunks to remove from the index]' \
+ '*::file:->files' && ret=0
- _arguments -S -A '--*' \
- '( --soft --hard)--mixed[like --soft but report what has not been updated (default)]' \
- '(--mixed --hard)--soft[do not touch the index file nor the working tree]' \
- '(--mixed --soft )--hard[match the working tree and index to the given tree]' \
- '--merge[bring local changes along to new commit]' \
- $commit_arg \
- $path_arg && ret=0
+ case $state in
+ (files)
+ local commit
+ if [[ -n $line[1] ]] && __git_is_committish $line[1]; then
+ commit=$line[1]
+ else
+ commit=HEAD
+ fi
+ __git_tree_files . $commit && ret=0
+ ;;
+ esac
}
(( $+functions[_git-revert] )) ||
--
Holger
Messages sorted by:
Reverse Date,
Date,
Thread,
Author