From: "Mikael Magnusson" <mikachu@gmail.com>
To: zsh-workers@sunsite.dk
Subject: Re: git checkout improvement
Date: Thu, 21 Aug 2008 07:19:47 +0200 [thread overview]
Message-ID: <237967ef0808202219u30360689u3388a6e5b0bcc660@mail.gmail.com> (raw)
In-Reply-To: <20080821050452.GA24497@scru.org>
2008/8/21 Clint Adams <clint@zsh.org>:
> 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@gmail.com>
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
prev parent reply other threads:[~2008-08-21 5:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-21 0:09 Clint Adams
2008-08-21 0:20 ` Mikael Magnusson
2008-08-21 0:52 ` Clint Adams
2008-08-21 2:18 ` Mikael Magnusson
2008-08-21 2:22 ` Mikael Magnusson
2008-08-21 5:04 ` Clint Adams
2008-08-21 5:19 ` Mikael Magnusson [this message]
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=237967ef0808202219u30360689u3388a6e5b0bcc660@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@sunsite.dk \
/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).