Skip to content

Commit 682853e

Browse files
committed
request-pull: really favor a matching tag
After tagging the tip of "dev" branch with a "for-linus" tag and pushing both out, running $ git request-pull $url $last_release dev would produce an output asking the 'dev' branch of $url to be pulled, because that is what the user asked the message to say. We already detect this situation locally and include the contents of the tag in the output; if the $url has that tag, favor that tag (i.e. "for-linus") in the generated message over the branch name the user gave us (i.e. "dev") from the command line, to make the output look more consistent. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26e5c5d commit 682853e

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

git-request-pull.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ headrev=$(git rev-parse --verify "$head"^0) || exit
5757
merge_base=$(git merge-base $baserev $headrev) ||
5858
die "fatal: No commits in common between $base and $head"
5959

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.
6367
find_matching_ref='
6468
sub abbr {
6569
my $ref = shift;
@@ -70,24 +74,29 @@ find_matching_ref='
7074
}
7175
}
7276
73-
my ($exact, $found);
77+
my ($tagged, $branch, $found);
7478
while (<STDIN>) {
7579
my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
7680
next unless ($sha1 eq $ARGV[1]);
7781
$found = abbr($ref);
82+
if ($deref && $ref eq "tags/$ARGV[2]") {
83+
$tagged = $found;
84+
last;
85+
}
7886
if ($ref =~ m|/\Q$ARGV[0]\E$|) {
7987
$exact = $found;
80-
last;
8188
}
8289
}
83-
if ($exact) {
90+
if ($tagged) {
91+
print "$tagged\n";
92+
} elsif ($exact) {
8493
print "$exact\n";
8594
} elsif ($found) {
8695
print "$found\n";
8796
}
8897
'
8998

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")
91100

92101
url=$(git ls-remote --get-url "$url")
93102

@@ -114,6 +123,12 @@ fi &&
114123

115124
if test -n "$tag_name"
116125
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
117132
git cat-file tag "$tag_name" |
118133
sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
119134
echo

0 commit comments

Comments
 (0)