request-pull: allow "local:remote" to specify names on both ends

This allows a user to say that a local branch has a different name on
the remote server, using the same syntax that "git push" uses to create
that situation.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Linus Torvalds 2014-01-22 15:23:48 -08:00 committed by Junio C Hamano
parent 024d34cb08
commit dc2eacc58c
1 changed files with 29 additions and 21 deletions

View File

@ -47,19 +47,23 @@ fi


# #
# $3 must be a symbolic ref, a unique ref, or # $3 must be a symbolic ref, a unique ref, or
# a SHA object expression # a SHA object expression. It can also be of
# the format 'local-name:remote-name'.
# #
head=$(git symbolic-ref -q "${3-HEAD}") local=${3%:*}
head=${head:-$(git show-ref "${3-HEAD}" | cut -d' ' -f2)} local=${local:-HEAD}
head=${head:-$(git rev-parse --quiet --verify "$3")} remote=${3#*:}
head=$(git symbolic-ref -q "$local")
head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
head=${head:-$(git rev-parse --quiet --verify "$local")}


# None of the above? Bad. # None of the above? Bad.
test -z "$head" && die "fatal: Not a valid revision: $3" test -z "$head" && die "fatal: Not a valid revision: $local"


# This also verifies that the resulting head is unique: # This also verifies that the resulting head is unique:
# "git show-ref" could have shown multiple matching refs.. # "git show-ref" could have shown multiple matching refs..
headrev=$(git rev-parse --verify --quiet "$head"^0) headrev=$(git rev-parse --verify --quiet "$head"^0)
test -z "$headrev" && die "fatal: Ambiguous revision: $3" test -z "$headrev" && die "fatal: Ambiguous revision: $local"


# Was it a branch with a description? # Was it a branch with a description?
branch_name=${head#refs/heads/} branch_name=${head#refs/heads/}
@ -69,9 +73,6 @@ then
branch_name= branch_name=
fi fi


prettyhead=${head#refs/}
prettyhead=${prettyhead#heads/}

merge_base=$(git merge-base $baserev $headrev) || merge_base=$(git merge-base $baserev $headrev) ||
die "fatal: No commits in common between $base and $head" die "fatal: No commits in common between $base and $head"


@ -81,30 +82,37 @@ die "fatal: No commits in common between $base and $head"
# #
# Otherwise find a random ref that matches $headrev. # Otherwise find a random ref that matches $headrev.
find_matching_ref=' find_matching_ref='
my ($exact,$found); my ($head,$headrev) = (@ARGV);
my ($found);

while (<STDIN>) { while (<STDIN>) {
chomp;
my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/; my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
next unless ($sha1 eq $ARGV[1]); my ($pattern);
if ($ref eq $ARGV[0]) { next unless ($sha1 eq $headrev);
$exact = $ref;
$pattern="/$head\$";
if ($ref eq $head) {
$found = $ref;
} }
if ($sha1 eq $ARGV[0]) { if ($ref =~ /$pattern/) {
$found = $ref;
}
if ($sha1 eq $head) {
$found = $sha1; $found = $sha1;
} }
} }
if ($exact) { if ($found) {
print "$exact\n";
} elsif ($found) {
print "$found\n"; print "$found\n";
} }
' '


ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "$head" "$headrev") ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")


if test -z "$ref" if test -z "$ref"
then then
echo "warn: No match for $prettyhead found at $url" >&2 echo "warn: No match for commit $headrev found at $url" >&2
echo "warn: Are you sure you pushed '$prettyhead' there?" >&2 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
status=1 status=1
fi fi


@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:


are available in the git repository at: are available in the git repository at:
' $merge_base && ' $merge_base &&
echo " $url $prettyhead" && echo " $url $remote" &&
git show -s --format=' git show -s --format='
for you to fetch changes up to %H: for you to fetch changes up to %H: