@@ -65,6 +65,8 @@ test -z "$head" && die "fatal: Not a valid revision: $local"
65
65
headrev=$( git rev-parse --verify --quiet " $head " ^0)
66
66
test -z " $headrev " && die " fatal: Ambiguous revision: $local "
67
67
68
+ local_sha1=$( git rev-parse --verify --quiet " $head " )
69
+
68
70
# Was it a branch with a description?
69
71
branch_name=${head# refs/ heads/ }
70
72
if test " z$branch_name " = " z$headref " ||
@@ -77,43 +79,53 @@ merge_base=$(git merge-base $baserev $headrev) ||
77
79
die " fatal: No commits in common between $base and $head "
78
80
79
81
# $head is the refname from the command line.
80
- # If a ref with the same name as $head exists at the remote
81
- # and their values match, use that.
82
- #
83
- # Otherwise find a random ref that matches $headrev.
82
+ # Find a ref with the same name as $head that exists at the remote
83
+ # and points to the same commit as the local object.
84
84
find_matching_ref='
85
85
my ($head,$headrev) = (@ARGV);
86
- my ($found);
86
+ my $pattern = qr{/\Q$head\E$};
87
+ my ($remote_sha1, $found);
87
88
88
89
while (<STDIN>) {
89
90
chomp;
90
91
my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
91
- my ($pattern);
92
- next unless ($sha1 eq $headrev);
93
92
94
- $pattern="/$head\$";
95
- if ($ref eq $head) {
96
- $found = $ref;
97
- }
98
- if ($ref =~ /$pattern/) {
99
- $found = $ref;
100
- }
101
93
if ($sha1 eq $head) {
102
- $found = $sha1;
94
+ $found = $remote_sha1 = $sha1;
95
+ break;
96
+ }
97
+
98
+ if ($ref eq $head || $ref =~ $pattern) {
99
+ if ($deref eq "") {
100
+ # Remember the matching object on the remote side
101
+ $remote_sha1 = $sha1;
102
+ }
103
+ if ($sha1 eq $headrev) {
104
+ $found = $ref;
105
+ break;
106
+ }
103
107
}
104
108
}
105
109
if ($found) {
106
- print "$found\n";
110
+ $remote_sha1 = $headrev if ! defined $remote_sha1;
111
+ print "$remote_sha1 $found\n";
107
112
}
108
113
'
109
114
110
- ref=$( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " ${remote:- HEAD} " " $headrev " )
115
+ set fnord $( git ls-remote " $url " | @@PERL@@ -e " $find_matching_ref " " ${remote:- HEAD} " " $headrev " )
116
+ remote_sha1=$2
117
+ ref=$3
111
118
112
119
if test -z " $ref "
113
120
then
114
121
echo " warn: No match for commit $headrev found at $url " >&2
115
122
echo " warn: Are you sure you pushed '${remote:- HEAD} ' there?" >&2
116
123
status=1
124
+ elif test " $local_sha1 " ! = " $remote_sha1 "
125
+ then
126
+ echo " warn: $head found at $url but points to a different object" >&2
127
+ echo " warn: Are you sure you pushed '${remote:- HEAD} ' there?" >&2
128
+ status=1
117
129
fi
118
130
119
131
# Special case: turn "for_linus" to "tags/for_linus" when it is correct
0 commit comments