diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2019-05-28 10:15:43 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-05-28 20:06:25 (GMT) |
commit | 0454220d66581f28b9688bc1b687f52cb9561798 (patch) | |
tree | a05a4bc3c0178898c136fb8f89b890a4c8cbe033 /git-request-pull.sh | |
parent | 5731dfce06a19f59aa1be2bd2120584864d8983b (diff) | |
download | git-0454220d66581f28b9688bc1b687f52cb9561798.zip git-0454220d66581f28b9688bc1b687f52cb9561798.tar.gz git-0454220d66581f28b9688bc1b687f52cb9561798.tar.bz2 |
request-pull: warn if the remote object is not the same as the local one
In some cases, git request-pull might be invoked with remote and
local objects that differ even though they point to the same commit.
For example, the remote object might be a lightweight tag
vs. an annotated tag on the local side; or the user might have
reworded the tag locally and forgotten to push it.
When this happens git-request-pull will not warn, because it only
checks that "git ls-remote" returns an SHA1 that matches the local
commit (known as $headrev in the script). This patch makes
git-request-pull retrieve the tag object SHA1 while processing
the "git ls-remote" output, so that it can be matched against the
local object.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-request-pull.sh')
-rwxr-xr-x | git-request-pull.sh | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/git-request-pull.sh b/git-request-pull.sh index 0d128be..2d0e446 100755 --- a/git-request-pull.sh +++ b/git-request-pull.sh @@ -65,6 +65,8 @@ test -z "$head" && die "fatal: Not a valid revision: $local" headrev=$(git rev-parse --verify --quiet "$head"^0) test -z "$headrev" && die "fatal: Ambiguous revision: $local" +local_sha1=$(git rev-parse --verify --quiet "$head") + # Was it a branch with a description? branch_name=${head#refs/heads/} if test "z$branch_name" = "z$headref" || @@ -77,42 +79,53 @@ merge_base=$(git merge-base $baserev $headrev) || die "fatal: No commits in common between $base and $head" # $head is the refname from the command line. -# If a ref with the same name as $head exists at the remote -# and their values match, use that. -# -# Otherwise find a random ref that matches $headrev. +# Find a ref with the same name as $head that exists at the remote +# and points to the same commit as the local object. find_matching_ref=' my ($head,$headrev) = (@ARGV); my $pattern = qr{/\Q$head\E$}; - my ($found); + my ($remote_sha1, $found); while (<STDIN>) { chomp; my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/; - next unless ($sha1 eq $headrev); - if ($ref eq $head) { - $found = $ref; - } - if ($ref =~ $pattern) { - $found = $ref; - } if ($sha1 eq $head) { - $found = $sha1; + $found = $remote_sha1 = $sha1; + break; + } + + if ($ref eq $head || $ref =~ $pattern) { + if ($deref eq "") { + # Remember the matching object on the remote side + $remote_sha1 = $sha1; + } + if ($sha1 eq $headrev) { + $found = $ref; + break; + } } } if ($found) { - print "$found\n"; + $remote_sha1 = $headrev if ! defined $remote_sha1; + print "$remote_sha1 $found\n"; } ' -ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") +set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") +remote_sha1=$2 +ref=$3 if test -z "$ref" then echo "warn: No match for commit $headrev found at $url" >&2 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 status=1 +elif test "$local_sha1" != "$remote_sha1" +then + echo "warn: $head found at $url but points to a different object" >&2 + echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 + status=1 fi # Special case: turn "for_linus" to "tags/for_linus" when it is correct |