Make revIsHash a bit safer
This commit is contained in:
parent
4905dc62a5
commit
1b295ad217
|
|
@ -534,11 +534,21 @@ func hashForRev(ctx context.Context, rev, gitRoot string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func revIsHash(ctx context.Context, rev, gitRoot string) (bool, error) {
|
func revIsHash(ctx context.Context, rev, gitRoot string) (bool, error) {
|
||||||
// If rev is a tag name or HEAD, rev-parse will produce the git hash. If
|
// If git doesn't identify rev as a commit, we're done.
|
||||||
// rev is already a git hash, the output will be the same hash. Of course, a
|
output, err := runCommand(ctx, gitRoot, *flGitCmd, "cat-file", "-t", rev)
|
||||||
// user could specify "abc" and match "abcdef12345678", so we just do a
|
if err != nil {
|
||||||
// prefix match.
|
return false, err
|
||||||
output, err := hashForRev(ctx, rev, gitRoot)
|
}
|
||||||
|
o := strings.Trim(string(output), "\n")
|
||||||
|
if o != "commit" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// `git cat-file -t` also returns "commit" for tags. If rev is already a git
|
||||||
|
// hash, the output will be the same hash as the input. Of course, a user
|
||||||
|
// could specify "abc" and match "abcdef12345678", so we just do a prefix
|
||||||
|
// match.
|
||||||
|
output, err = hashForRev(ctx, rev, gitRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue