@@ -57,12 +57,38 @@ headrev=$(git rev-parse --verify "$head"^0) || exit
5757merge_base=$( git merge-base $baserev $headrev ) ||
5858die " fatal: No commits in common between $base and $head "
5959
60- find_matching_branch=" /^$headrev " ' refs\/heads\//{
61- s/^.* refs\/heads\///
62- p
63- q
64- }'
65- branch=$( git ls-remote " $url " | sed -n -e " $find_matching_branch " )
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.
63+ find_matching_ref='
64+ sub abbr {
65+ my $ref = shift;
66+ if ($ref =~ s|refs/heads/|| || $ref =~ s|refs/tags/||) {
67+ return $ref;
68+ } else {
69+ return $ref;
70+ }
71+ }
72+
73+ my ($exact, $found);
74+ while (<STDIN>) {
75+ my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
76+ next unless ($sha1 eq $ARGV[1]);
77+ $found = abbr($ref);
78+ if ($ref =~ m|/\Q$ARGV[0]\E$|) {
79+ $exact = $found;
80+ last;
81+ }
82+ }
83+ if ($exact) {
84+ print "$exact\n";
85+ } elsif ($found) {
86+ print "$found\n";
87+ }
88+ '
89+
90+ ref=$( git ls-remote " $url " | perl -e " $find_matching_ref " " $head " " $headrev " )
91+
6692url=$( git ls-remote --get-url " $url " )
6793
6894git show -s --format=' The following changes since commit %H:
@@ -71,7 +97,7 @@ git show -s --format='The following changes since commit %H:
7197
7298are available in the git repository at:
7399' $baserev &&
74- echo " $url ${branch + $branch } " &&
100+ echo " $url ${ref + $ref } " &&
75101git show -s --format='
76102for you to fetch changes up to %H:
77103
@@ -81,7 +107,7 @@ for you to fetch changes up to %H:
81107
82108if test -n " $branch_name "
83109then
84- echo " (from the branch description for $branch local branch)"
110+ echo " (from the branch description for $branch_name local branch)"
85111 echo
86112 git config " branch.$branch_name .description"
87113fi &&
@@ -101,7 +127,7 @@ fi &&
101127git shortlog ^$baserev $headrev &&
102128git diff -M --stat --summary $patch $merge_base ..$headrev || status=1
103129
104- if test -z " $branch "
130+ if test -z " $ref "
105131then
106132 echo " warn: No branch of $url is at:" >&2
107133 git show -s --format=' warn: %h: %s' $headrev >&2
0 commit comments