Skip to content

Commit 2b022f6

Browse files
committed
Merge branch 'jc/request-pull-match-tagname'
"git request-pull $url dev" when the tip of "dev" branch was tagged with "ext4-for-linus" used the contents from the tag in the output but still asked the "dev" branch to be pulled, not the tag. * jc/request-pull-match-tagname: request-pull: really favor a matching tag
2 parents 486fcbc + 682853e commit 2b022f6

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)