Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: git checkout improvement
- X-seq: zsh-workers 25499
- From: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: git checkout improvement
- Date: Thu, 21 Aug 2008 07:19:47 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=hC4l9TqjNLTiiLizVAD8BwlLGhrG/fUFWM/e16MWnKo=; b=QyXEbqcBwb5T4DBktldF6X9jK/YJ/qAp3xB/NGgCf+E/ayna3GQJKUXYrGVMkntAsA Gvis8a345irS7OsU2cSMCfWwVYvO6FLeqVGstr0HH7Lm0+k0LTtXZ3eDAsld2hvfdDof tBBMC9zuPM+PaT7/yqiUb8r26qgZIrsNM7msg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=vTdcCvufd0v7qUbQN3ZAYvclnhox7tlwXsdEW+T9Za15s2oJuLakgZGcDwXZe6bRHM 8EyuZKsQ8Lt7/+a6/jdFiihbTkeCvKJjV3W8qfjTG+UMDfdwGWlGVb4YlG2FFkn9JyYu ndYHN+sXUzH0Jh9JQri0rY6cp+ezZ2NzgtfYc=
- In-reply-to: <20080821050452.GA24497@xxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080821000948.GA20166@xxxxxxxx> <237967ef0808201720x594dae53x215b078420b1ccb6@xxxxxxxxxxxxxx> <20080821005259.GA21325@xxxxxxxx> <237967ef0808201918t4c21baefj456fb9be0605d430@xxxxxxxxxxxxxx> <237967ef0808201922g91dd092w5da31759495b74b7@xxxxxxxxxxxxxx> <20080821050452.GA24497@xxxxxxxx>
2008/8/21 Clint Adams <clint@xxxxxxx>:
> On Thu, Aug 21, 2008 at 04:22:08AM +0200, Mikael Magnusson wrote:
>> Another problem is you can do
>> git checkout git.c NEWS
>> but then we try to use git.c as a tree-ish which obviously doesn't work.
>> Probably we should check if words[1] (or whatever) is a valid tree-ish,
>> and if not, complete files from the index instead.
>
> Great, how do you validate a tree-ish?
This seems to work :)
commit b619c9a4c193380d8b974753257c60faf713f6f6
Author: Mikael Magnusson <mikachu@xxxxxxxxx>
Date: Thu Aug 21 07:18:50 2008 +0200
_git: Make sure the first argument is a treeish.
The first rev-parse is needed in case the user wrote something
like HEAD:, HEAD:^{tree}
is not valid syntax, so get the sha1 first and then append the ^{tree}.
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 6603371..7e48c19 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1529,6 +1529,13 @@ _git-branch () {
}
__git_zstyle_default
':completion::complete:git-branch:delete-argument-rest:*' ignore-line
yes
+(( $+functions[__git_is_treeish] )) ||
+__git_is_treeish () {
+ local sha1
+ sha1="$(git rev-parse $1)"
+ [[ "$(git cat-file -t "${sha1}^{tree}" 2> /dev/null)" == tree ]]
+}
+
# TODO: __git_tree_ishs is just stupid. It should be giving us a list of tags
# and perhaps also allow all that just with ^{tree} and so on. Not quite sure
# how to do that, though.
@@ -1568,7 +1575,7 @@ _git-checkout () {
#What's the variable that holds the tree-ish argument? Is it even
reliably possible?
case $state in
(files)
- if [[ -n $line[1] ]]; then
+ if [[ -n $line[1] ]] && __git_is_treeish $line[1]; then
__git_tree_files . $line[1] && ret=0
else
__git_cached_files && ret=0
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author