Created
September 19, 2013 15:55
-
-
Save InPermutation/6625573 to your computer and use it in GitHub Desktop.
Check if a treeish is a ref or a (partial) sha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$treeish = "my_tag" | |
# $treeish = "my_branch" | |
# $treeish = "900fe0a22ea332fcbfdb4b0bc7136760ea30cc19" | |
# $treeish = "900fe0a22" | |
$exists = [bool](git rev-parse --quiet --verify $treeish) | |
$ref = [bool](git show-ref $treeish) | |
$sha = -not $ref | |
# Check if it's a tag. (Careful; --list uses shell wildcard syntax) | |
$tag = [bool](git tag --list $treeish) |
Wow, and I totally butchered the definition of tree-ish
. Oh well.
(e.g. master:test.bat
would set $exists=$true
and $sha=$true
, which is obviously bogus.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't test this with ancestry references (
HEAD^
,900fe0a22^2
) or reflog shortnames {HEAD@{2.months.ago}
}, so those will probably give you bogus results.