From 46c4588a2b52262353a83d0284bcf7160f8cf5cd Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Thu, 21 Aug 2008 12:25:18 +0000 Subject: Mikael Magnusson: 25499: add function to validate tree-ishs. --- Completion/Unix/Command/_git | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Completion') diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 5d656569a..a6e75c64a 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. @@ -1566,7 +1573,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 -- cgit 1.4.1