@@ -57,9 +57,13 @@ headrev=$(git rev-parse --verify "$head"^0) || exit
57
57
merge_base=$( git merge-base $baserev $headrev ) ||
58
58
die " fatal: No commits in common between $base and $head "
59
59
60
- # $head is the token given from the command line. If a ref with that
61
- # name exists at the remote and their values match, we should use it.
62
- # Otherwise find a ref that matches $headrev.
60
+ # $head is the token given from the command line, and $tag_name, if
61
+ # exists, is the tag we are going to show the commit information for.
62
+ # If that tag exists at the remote and it points at the commit, use it.
63
+ # Otherwise, if a branch with the same name as $head exists at the remote
64
+ # and their values match, use that instead.
65
+ #
66
+ # Otherwise find a random ref that matches $headrev.
63
67
find_matching_ref='
64
68
sub abbr {
65
69
my $ref = shift;
@@ -70,24 +74,29 @@ find_matching_ref='
70
74
}
71
75
}
72
76
73
- my ($exact , $found);
77
+ my ($tagged, $branch , $found);
74
78
while (<STDIN>) {
75
79
my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
76
80
next unless ($sha1 eq $ARGV[1]);
77
81
$found = abbr($ref);
82
+ if ($deref && $ref eq "tags/$ARGV[2]") {
83
+ $tagged = $found;
84
+ last;
85
+ }
78
86
if ($ref =~ m|/\Q$ARGV[0]\E$|) {
79
87
$exact = $found;
80
- last;
81
88
}
82
89
}
83
- if ($exact) {
90
+ if ($tagged) {
91
+ print "$tagged\n";
92
+ } elsif ($exact) {
84
93
print "$exact\n";
85
94
} elsif ($found) {
86
95
print "$found\n";
87
96
}
88
97
'
89
98
90
- ref=$( git ls-remote " $url " | perl -e " $find_matching_ref " " $head " " $headrev " )
99
+ ref=$( git ls-remote " $url " | perl -e " $find_matching_ref " " $head " " $headrev " " $tag_name " )
91
100
92
101
url=$( git ls-remote --get-url " $url " )
93
102
@@ -114,6 +123,12 @@ fi &&
114
123
115
124
if test -n " $tag_name "
116
125
then
126
+ if test -z " $ref " || test " $ref " ! = " tags/$tag_name "
127
+ then
128
+ echo >&2 " warn: You locally have $tag_name but it does not (yet)"
129
+ echo >&2 " warn: appear to be at $url "
130
+ echo >&2 " warn: Do you want to push it there, perhaps?"
131
+ fi
117
132
git cat-file tag " $tag_name " |
118
133
sed -n -e ' 1,/^$/d' -e ' /^-----BEGIN PGP /q' -e p
119
134
echo
0 commit comments