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 <gitster@pobox.com>

Junio C Hamano committed Jun 1, 2012 at 12:38 UTC 682853e687ff0106bea25bdb5e9d60d9657cecb3
1 file changed +22 -7
git-request-pull.sh
+22 -7
@@ -57,9 +57,13 @@ headrev=$(git rev-parse --verify "$head"^0) || exit
57 merge_base=$(git merge-base $baserev $headrev) ||
58 die "fatal: No commits in common between $base and $head"
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.
67 find_matching_ref='
68 sub abbr {
69 my $ref = shift;
@@ -70,24 +74,29 @@ find_matching_ref='
74 }
75 }
76
73 - my ($exact, $found);
77 + my ($tagged, $branch, $found);
78 while (<STDIN>) {
79 my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
80 next unless ($sha1 eq $ARGV[1]);
81 $found = abbr($ref);
82 + if ($deref && $ref eq "tags/$ARGV[2]") {
83 + $tagged = $found;
84 + last;
85 + }
86 if ($ref =~ m|/\Q$ARGV[0]\E$|) {
87 $exact = $found;
80 - last;
88 }
89 }
83 - if ($exact) {
90 + if ($tagged) {
91 + print "$tagged\n";
92 + } elsif ($exact) {
93 print "$exact\n";
94 } elsif ($found) {
95 print "$found\n";
96 }
97 '
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")
100
101 url=$(git ls-remote --get-url "$url")
102
@@ -114,6 +123,12 @@ fi &&
123
124 if test -n "$tag_name"
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
132 git cat-file tag "$tag_name" |
133 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
134 echo