4747
4848#
4949# $3 must be a symbolic ref, a unique ref, or
50- # a SHA object expression
50+ # a SHA object expression. It can also be of
51+ # the format 'local-name:remote-name'.
5152#
52- head=$( git symbolic-ref -q " ${3-HEAD} " )
53- head=${head:- $(git show-ref " ${3-HEAD} " | cut -d' ' -f2)}
54- head=${head:- $(git rev-parse --quiet --verify " $3 " )}
53+ local=${3%:* }
54+ local=${local:- HEAD}
55+ remote=${3#*: }
56+ head=$( git symbolic-ref -q " $local " )
57+ head=${head:- $(git show-ref --heads --tags " $local " | cut -d' ' -f2)}
58+ head=${head:- $(git rev-parse --quiet --verify " $local " )}
5559
5660# None of the above? Bad.
57- test -z " $head " && die " fatal: Not a valid revision: $3 "
61+ test -z " $head " && die " fatal: Not a valid revision: $local "
5862
5963# This also verifies that the resulting head is unique:
6064# "git show-ref" could have shown multiple matching refs..
6165headrev=$( git rev-parse --verify --quiet " $head " ^0)
62- test -z " $headrev " && die " fatal: Ambiguous revision: $3 "
66+ test -z " $headrev " && die " fatal: Ambiguous revision: $local "
6367
6468# Was it a branch with a description?
6569branch_name=${head# refs/ heads/ }
6973 branch_name=
7074fi
7175
72- prettyhead=${head# refs/ }
73- prettyhead=${prettyhead# heads/ }
74-
7576merge_base=$( git merge-base $baserev $headrev ) ||
7677die " fatal: No commits in common between $base and $head "
7778
@@ -81,30 +82,37 @@ die "fatal: No commits in common between $base and $head"
8182#
8283# Otherwise find a random ref that matches $headrev.
8384find_matching_ref='
84- my ($exact,$found);
85+ my ($head,$headrev) = (@ARGV);
86+ my ($found);
87+
8588 while (<STDIN>) {
89+ chomp;
8690 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
87- next unless ($sha1 eq $ARGV[1]);
88- if ($ref eq $ARGV[0]) {
89- $exact = $ref;
91+ my ($pattern);
92+ next unless ($sha1 eq $headrev);
93+
94+ $pattern="/$head\$";
95+ if ($ref eq $head) {
96+ $found = $ref;
97+ }
98+ if ($ref =~ /$pattern/) {
99+ $found = $ref;
90100 }
91- if ($sha1 eq $ARGV[0] ) {
101+ if ($sha1 eq $head ) {
92102 $found = $sha1;
93103 }
94104 }
95- if ($exact) {
96- print "$exact\n";
97- } elsif ($found) {
105+ if ($found) {
98106 print "$found\n";
99107 }
100108'
101109
102- ref=$( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " $head " " $headrev " )
110+ ref=$( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " ${remote :- HEAD} " " $headrev " )
103111
104112if test -z " $ref "
105113then
106- echo " warn: No match for $prettyhead found at $url " >&2
107- echo " warn: Are you sure you pushed '$prettyhead ' there?" >&2
114+ echo " warn: No match for commit $headrev found at $url " >&2
115+ echo " warn: Are you sure you pushed '${remote :- HEAD} ' there?" >&2
108116 status=1
109117fi
110118
@@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:
116124
117125are available in the git repository at:
118126' $merge_base &&
119- echo " $url $prettyhead " &&
127+ echo " $url $remote " &&
120128git show -s --format='
121129for you to fetch changes up to %H:
122130
0 commit comments