about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2008-08-21 12:25:18 +0000
committerClint Adams <clint@users.sourceforge.net>2008-08-21 12:25:18 +0000
commit46c4588a2b52262353a83d0284bcf7160f8cf5cd (patch)
treeb4374b08234293015f31da4db0cf19151dde6f9a /Completion
parent7b559ca54aeaefac807b419150db3b16d983e3d4 (diff)
downloadzsh-46c4588a2b52262353a83d0284bcf7160f8cf5cd.tar.gz
zsh-46c4588a2b52262353a83d0284bcf7160f8cf5cd.tar.xz
zsh-46c4588a2b52262353a83d0284bcf7160f8cf5cd.zip
Mikael Magnusson: 25499: add function to validate tree-ishs.
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Command/_git9
1 files changed, 8 insertions, 1 deletions
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