From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21152 invoked from network); 21 Aug 2008 05:20:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 21 Aug 2008 05:20:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 2426 invoked from network); 21 Aug 2008 05:20:03 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Aug 2008 05:20:03 -0000 Received: (qmail 3342 invoked by alias); 21 Aug 2008 05:19:53 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25499 Received: (qmail 3324 invoked from network); 21 Aug 2008 05:19:51 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 21 Aug 2008 05:19:51 -0000 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by bifrost.dotsrc.org (Postfix) with ESMTP id 9A74D801E2B4 for ; Thu, 21 Aug 2008 07:19:48 +0200 (CEST) Received: by nf-out-0910.google.com with SMTP id g13so1101857nfb.11 for ; Wed, 20 Aug 2008 22:19:48 -0700 (PDT) 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= Received: by 10.210.41.14 with SMTP id o14mr1296272ebo.82.1219295987957; Wed, 20 Aug 2008 22:19:47 -0700 (PDT) Received: by 10.210.19.20 with HTTP; Wed, 20 Aug 2008 22:19:47 -0700 (PDT) Message-ID: <237967ef0808202219u30360689u3388a6e5b0bcc660@mail.gmail.com> Date: Thu, 21 Aug 2008 07:19:47 +0200 From: "Mikael Magnusson" To: zsh-workers@sunsite.dk Subject: Re: git checkout improvement In-Reply-To: <20080821050452.GA24497@scru.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080821000948.GA20166@scru.org> <237967ef0808201720x594dae53x215b078420b1ccb6@mail.gmail.com> <20080821005259.GA21325@scru.org> <237967ef0808201918t4c21baefj456fb9be0605d430@mail.gmail.com> <237967ef0808201922g91dd092w5da31759495b74b7@mail.gmail.com> <20080821050452.GA24497@scru.org> X-Virus-Scanned: ClamAV 0.92.1/8061/Thu Aug 21 02:00:17 2008 on bifrost X-Virus-Status: Clean 2008/8/21 Clint Adams : > 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 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