Skip to content

Commit 835fbdb

Browse files
committed
Merge branch 'jc/request-pull-show-head-4'
* jc/request-pull-show-head-4: request-pull: do not emit "tag" before the tagname request-pull: update the "pull" command generation logic
2 parents 4d466b6 + f032d66 commit 835fbdb

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

git-request-pull.sh

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,38 @@ headrev=$(git rev-parse --verify "$head"^0) || exit
5757
merge_base=$(git merge-base $baserev $headrev) ||
5858
die "fatal: No commits in common between $base and $head"
5959

60-
find_matching_branch="/^$headrev "'refs\/heads\//{
61-
s/^.* refs\/heads\///
62-
p
63-
q
64-
}'
65-
branch=$(git ls-remote "$url" | sed -n -e "$find_matching_branch")
60+
# $head is the token given from the command line. If a ref with that
61+
# name exists at the remote and their values match, we should use it.
62+
# Otherwise find a ref that matches $headrev.
63+
find_matching_ref='
64+
sub abbr {
65+
my $ref = shift;
66+
if ($ref =~ s|refs/heads/|| || $ref =~ s|refs/tags/||) {
67+
return $ref;
68+
} else {
69+
return $ref;
70+
}
71+
}
72+
73+
my ($exact, $found);
74+
while (<STDIN>) {
75+
my ($sha1, $ref, $deref) = /^(\S+)\s+(\S+?)(\^\{\})?$/;
76+
next unless ($sha1 eq $ARGV[1]);
77+
$found = abbr($ref);
78+
if ($ref =~ m|/\Q$ARGV[0]\E$|) {
79+
$exact = $found;
80+
last;
81+
}
82+
}
83+
if ($exact) {
84+
print "$exact\n";
85+
} elsif ($found) {
86+
print "$found\n";
87+
}
88+
'
89+
90+
ref=$(git ls-remote "$url" | perl -e "$find_matching_ref" "$head" "$headrev")
91+
6692
url=$(git ls-remote --get-url "$url")
6793

6894
git show -s --format='The following changes since commit %H:
@@ -71,7 +97,7 @@ git show -s --format='The following changes since commit %H:
7197
7298
are available in the git repository at:
7399
' $baserev &&
74-
echo " $url${branch+ $branch}" &&
100+
echo " $url${ref+ $ref}" &&
75101
git show -s --format='
76102
for you to fetch changes up to %H:
77103
@@ -81,7 +107,7 @@ for you to fetch changes up to %H:
81107

82108
if test -n "$branch_name"
83109
then
84-
echo "(from the branch description for $branch local branch)"
110+
echo "(from the branch description for $branch_name local branch)"
85111
echo
86112
git config "branch.$branch_name.description"
87113
fi &&
@@ -101,7 +127,7 @@ fi &&
101127
git shortlog ^$baserev $headrev &&
102128
git diff -M --stat --summary $patch $merge_base..$headrev || status=1
103129

104-
if test -z "$branch"
130+
if test -z "$ref"
105131
then
106132
echo "warn: No branch of $url is at:" >&2
107133
git show -s --format='warn: %h: %s' $headrev >&2

t/t5150-request-pull.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ test_expect_success 'setup: two scripts for reading pull requests' '
6767
6868
cat <<-\EOT >read-request.sed &&
6969
#!/bin/sed -nf
70+
# Note that a request could ask for "tag $tagname"
7071
/ in the git repository at:$/!d
7172
n
7273
/^$/ n
74+
s/ tag \([^ ]*\)$/ tag--\1/
7375
s/^[ ]*\(.*\) \([^ ]*\)/please pull\
7476
\1\
7577
\2/p
@@ -178,6 +180,7 @@ test_expect_success 'request names an appropriate branch' '
178180
read branch
179181
} <digest &&
180182
{
183+
test "$branch" = full ||
181184
test "$branch" = master ||
182185
test "$branch" = for-upstream
183186
}

0 commit comments

Comments
 (0)