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>
Linus Torvalds committed
Jan 22, 2014 at 15:23 UTC
dc2eacc58c1118ad68b9d6973033a60b6ed9be1f
1 file changed
+29
-21
git-request-pull.sh
+29
-21
@@ -47,19 +47,23 @@ fi
47
48
#
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'.
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")}
59
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"
62
63
# This also verifies that the resulting head is unique:
64
# "git show-ref" could have shown multiple matching refs..
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"
67
68
# Was it a branch with a description?
69
branch_name=${head#refs/heads/}
@@ -69,9 +73,6 @@ then
73
branch_name=
74
fi
75
72
-prettyhead=${head#refs/}
73
-prettyhead=${prettyhead#heads/}
74
-
76
merge_base=$(git merge-base $baserev $headrev) ||
77
die "fatal: No commits in common between $base and $head"
78
@@ -81,30 +82,37 @@ die "fatal: No commits in common between $base and $head"
82
#
83
# Otherwise find a random ref that matches $headrev.
84
find_matching_ref='
84
- my ($exact,$found);
85
+ my ($head,$headrev) = (@ARGV);
86
+ my ($found);
87
+
88
while (<STDIN>) {
89
+ chomp;
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;
100
}
91
- if ($sha1 eq $ARGV[0]) {
101
+ if ($sha1 eq $head) {
102
$found = $sha1;
103
}
104
}
95
- if ($exact) {
96
- print "$exact\n";
97
- } elsif ($found) {
105
+ if ($found) {
106
print "$found\n";
107
}
108
'
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")
111
112
if test -z "$ref"
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
116
status=1
117
fi
118
@@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:
124
125
are available in the git repository at:
126
' $merge_base &&
119
-echo " $url $prettyhead" &&
127
+echo " $url $remote" &&
128
git show -s --format='
129
for you to fetch changes up to %H:
130