47
47
48
48
#
49
49
# $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'.
51
52
#
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 " )}
55
59
56
60
# 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 "
58
62
59
63
# This also verifies that the resulting head is unique:
60
64
# "git show-ref" could have shown multiple matching refs..
61
65
headrev=$( 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 "
63
67
64
68
# Was it a branch with a description?
65
69
branch_name=${head# refs/ heads/ }
69
73
branch_name=
70
74
fi
71
75
72
- prettyhead=${head# refs/ }
73
- prettyhead=${prettyhead# heads/ }
74
-
75
76
merge_base=$( git merge-base $baserev $headrev ) ||
76
77
die " fatal: No commits in common between $base and $head "
77
78
@@ -81,30 +82,37 @@ die "fatal: No commits in common between $base and $head"
81
82
#
82
83
# Otherwise find a random ref that matches $headrev.
83
84
find_matching_ref='
84
- my ($exact,$found);
85
+ my ($head,$headrev) = (@ARGV);
86
+ my ($found);
87
+
85
88
while (<STDIN>) {
89
+ chomp;
86
90
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;
90
100
}
91
- if ($sha1 eq $ARGV[0] ) {
101
+ if ($sha1 eq $head ) {
92
102
$found = $sha1;
93
103
}
94
104
}
95
- if ($exact) {
96
- print "$exact\n";
97
- } elsif ($found) {
105
+ if ($found) {
98
106
print "$found\n";
99
107
}
100
108
'
101
109
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 " )
103
111
104
112
if test -z " $ref "
105
113
then
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
108
116
status=1
109
117
fi
110
118
@@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:
116
124
117
125
are available in the git repository at:
118
126
' $merge_base &&
119
- echo " $url $prettyhead " &&
127
+ echo " $url $remote " &&
120
128
git show -s --format='
121
129
for you to fetch changes up to %H:
122
130
0 commit comments