Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit dc2eacc

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 024d34c commit dc2eacc

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

git-request-pull.sh

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,23 @@ fi
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..
6165
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"
6367

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

72-
prettyhead=${head#refs/}
73-
prettyhead=${prettyhead#heads/}
74-
7576
merge_base=$(git merge-base $baserev $headrev) ||
7677
die "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.
8384
find_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

104112
if test -z "$ref"
105113
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
108116
status=1
109117
fi
110118

@@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:
116124
117125
are available in the git repository at:
118126
' $merge_base &&
119-
echo " $url $prettyhead" &&
127+
echo " $url $remote" &&
120128
git show -s --format='
121129
for you to fetch changes up to %H:
122130

0 commit comments

Comments
 (0)