@@ -57,12 +57,38 @@ 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
- 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
+
66
92
url=$( git ls-remote --get-url " $url " )
67
93
68
94
git show -s --format=' The following changes since commit %H:
@@ -71,7 +97,7 @@ git show -s --format='The following changes since commit %H:
71
97
72
98
are available in the git repository at:
73
99
' $baserev &&
74
- echo " $url ${branch + $branch } " &&
100
+ echo " $url ${ref + $ref } " &&
75
101
git show -s --format='
76
102
for you to fetch changes up to %H:
77
103
@@ -81,7 +107,7 @@ for you to fetch changes up to %H:
81
107
82
108
if test -n " $branch_name "
83
109
then
84
- echo " (from the branch description for $branch local branch)"
110
+ echo " (from the branch description for $branch_name local branch)"
85
111
echo
86
112
git config " branch.$branch_name .description"
87
113
fi &&
@@ -101,7 +127,7 @@ fi &&
101
127
git shortlog ^$baserev $headrev &&
102
128
git diff -M --stat --summary $patch $merge_base ..$headrev || status=1
103
129
104
- if test -z " $branch "
130
+ if test -z " $ref "
105
131
then
106
132
echo " warn: No branch of $url is at:" >&2
107
133
git show -s --format=' warn: %h: %s' $headrev >&2
0 commit comments