2018-06-28 06:30:17 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='upload-pack ref-in-want'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
get_actual_refs () {
|
|
|
|
sed -n -e '/wanted-refs/,/0001/{
|
|
|
|
/wanted-refs/d
|
|
|
|
/0001/d
|
|
|
|
p
|
2018-09-10 01:36:28 +08:00
|
|
|
}' <out | test-tool pkt-line unpack >actual_refs
|
2018-06-28 06:30:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get_actual_commits () {
|
2020-03-26 12:37:38 +08:00
|
|
|
test-tool pkt-line unpack-sideband <out >o.pack &&
|
2018-06-28 06:30:17 +08:00
|
|
|
git index-pack o.pack &&
|
2019-11-28 03:53:38 +08:00
|
|
|
git verify-pack -v o.idx >objs &&
|
2021-01-23 21:00:44 +08:00
|
|
|
sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs >objs.sed &&
|
|
|
|
sort >actual_commits <objs.sed
|
2018-06-28 06:30:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
check_output () {
|
|
|
|
get_actual_refs &&
|
|
|
|
test_cmp expected_refs actual_refs &&
|
|
|
|
get_actual_commits &&
|
2019-11-28 03:53:38 +08:00
|
|
|
sort expected_commits >sorted_commits &&
|
|
|
|
test_cmp sorted_commits actual_commits
|
2018-06-28 06:30:17 +08:00
|
|
|
}
|
|
|
|
|
2020-06-20 01:55:57 +08:00
|
|
|
write_command () {
|
|
|
|
echo "command=$1"
|
|
|
|
|
|
|
|
if test "$(test_oid algo)" != sha1
|
|
|
|
then
|
|
|
|
echo "object-format=$(test_oid algo)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
# Write a complete fetch command to stdout, suitable for use with `test-tool
|
|
|
|
# pkt-line`. "want-ref", "want", and "have" lines are read from stdin.
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# write_fetch_command <<-EOF
|
|
|
|
# want-ref refs/heads/main
|
|
|
|
# have $(git rev-parse a)
|
|
|
|
# EOF
|
|
|
|
#
|
|
|
|
# write_fetch_command <<-EOF
|
|
|
|
# want $(git rev-parse b)
|
|
|
|
# have $(git rev-parse a)
|
|
|
|
# EOF
|
|
|
|
#
|
|
|
|
write_fetch_command () {
|
|
|
|
write_command fetch &&
|
|
|
|
echo "0001" &&
|
|
|
|
echo "no-progress" &&
|
|
|
|
cat &&
|
|
|
|
echo "done" &&
|
|
|
|
echo "0000"
|
|
|
|
}
|
|
|
|
|
2018-06-28 06:30:17 +08:00
|
|
|
# c(o/foo) d(o/bar)
|
|
|
|
# \ /
|
2020-12-17 09:07:07 +08:00
|
|
|
# b e(baz) f(main)
|
2018-06-28 06:30:17 +08:00
|
|
|
# \__ | __/
|
|
|
|
# \ | /
|
|
|
|
# a
|
|
|
|
test_expect_success 'setup repository' '
|
|
|
|
test_commit a &&
|
2020-12-17 09:07:07 +08:00
|
|
|
git branch -M main &&
|
2018-06-28 06:30:17 +08:00
|
|
|
git checkout -b o/foo &&
|
|
|
|
test_commit b &&
|
|
|
|
test_commit c &&
|
|
|
|
git checkout -b o/bar b &&
|
|
|
|
test_commit d &&
|
|
|
|
git checkout -b baz a &&
|
|
|
|
test_commit e &&
|
2020-12-17 09:07:07 +08:00
|
|
|
git checkout main &&
|
2018-06-28 06:30:17 +08:00
|
|
|
test_commit f
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'config controls ref-in-want advertisement' '
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --advertise-capabilities >out &&
|
2020-05-19 08:50:46 +08:00
|
|
|
perl -ne "/ref-in-want/ and print" out >out.filter &&
|
|
|
|
test_must_be_empty out.filter &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
|
|
|
git config uploadpack.allowRefInWant false &&
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --advertise-capabilities >out &&
|
2020-05-19 08:50:46 +08:00
|
|
|
perl -ne "/ref-in-want/ and print" out >out.filter &&
|
|
|
|
test_must_be_empty out.filter &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
|
|
|
git config uploadpack.allowRefInWant true &&
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --advertise-capabilities >out &&
|
2020-05-19 08:50:46 +08:00
|
|
|
perl -ne "/ref-in-want/ and print" out >out.filter &&
|
|
|
|
test_file_not_empty out.filter
|
2018-06-28 06:30:17 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'invalid want-ref line' '
|
2021-08-13 14:23:40 +08:00
|
|
|
write_fetch_command >pkt <<-EOF &&
|
2018-06-28 06:30:17 +08:00
|
|
|
want-ref refs/heads/non-existent
|
|
|
|
EOF
|
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
test-tool pkt-line pack <pkt >in &&
|
2019-04-18 21:16:51 +08:00
|
|
|
test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
grep "unknown ref" out
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'basic want-ref' '
|
2019-11-28 03:53:38 +08:00
|
|
|
oid=$(git rev-parse f) &&
|
2018-06-28 06:30:17 +08:00
|
|
|
cat >expected_refs <<-EOF &&
|
2020-12-17 09:07:07 +08:00
|
|
|
$oid refs/heads/main
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2019-11-28 03:53:38 +08:00
|
|
|
git rev-parse f >expected_commits &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
write_fetch_command >pkt <<-EOF &&
|
2020-12-17 09:07:07 +08:00
|
|
|
want-ref refs/heads/main
|
2021-08-13 14:23:40 +08:00
|
|
|
have $(git rev-parse a)
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2021-08-13 14:23:40 +08:00
|
|
|
test-tool pkt-line pack <pkt >in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --stateless-rpc >out <in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'multiple want-ref lines' '
|
2019-11-28 03:53:38 +08:00
|
|
|
oid_c=$(git rev-parse c) &&
|
|
|
|
oid_d=$(git rev-parse d) &&
|
2018-06-28 06:30:17 +08:00
|
|
|
cat >expected_refs <<-EOF &&
|
2019-11-28 03:53:38 +08:00
|
|
|
$oid_c refs/heads/o/foo
|
|
|
|
$oid_d refs/heads/o/bar
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2019-11-28 03:53:38 +08:00
|
|
|
git rev-parse c d >expected_commits &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
write_fetch_command >pkt <<-EOF &&
|
2018-06-28 06:30:17 +08:00
|
|
|
want-ref refs/heads/o/foo
|
|
|
|
want-ref refs/heads/o/bar
|
2021-08-13 14:23:40 +08:00
|
|
|
have $(git rev-parse b)
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2021-08-13 14:23:40 +08:00
|
|
|
test-tool pkt-line pack <pkt >in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --stateless-rpc >out <in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'mix want and want-ref' '
|
2019-11-28 03:53:38 +08:00
|
|
|
oid=$(git rev-parse f) &&
|
2018-06-28 06:30:17 +08:00
|
|
|
cat >expected_refs <<-EOF &&
|
2020-12-17 09:07:07 +08:00
|
|
|
$oid refs/heads/main
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2019-11-28 03:53:38 +08:00
|
|
|
git rev-parse e f >expected_commits &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
write_fetch_command >pkt <<-EOF &&
|
2020-12-17 09:07:07 +08:00
|
|
|
want-ref refs/heads/main
|
2018-06-28 06:30:17 +08:00
|
|
|
want $(git rev-parse e)
|
|
|
|
have $(git rev-parse a)
|
|
|
|
EOF
|
2021-08-13 14:23:40 +08:00
|
|
|
test-tool pkt-line pack <pkt >in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --stateless-rpc >out <in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'want-ref with ref we already have commit for' '
|
2019-11-28 03:53:38 +08:00
|
|
|
oid=$(git rev-parse c) &&
|
2018-06-28 06:30:17 +08:00
|
|
|
cat >expected_refs <<-EOF &&
|
2019-11-28 03:53:38 +08:00
|
|
|
$oid refs/heads/o/foo
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
|
|
|
>expected_commits &&
|
|
|
|
|
2021-08-13 14:23:40 +08:00
|
|
|
write_fetch_command >pkt <<-EOF &&
|
2018-06-28 06:30:17 +08:00
|
|
|
want-ref refs/heads/o/foo
|
2021-08-13 14:23:40 +08:00
|
|
|
have $(git rev-parse c)
|
2018-06-28 06:30:17 +08:00
|
|
|
EOF
|
2021-08-13 14:23:40 +08:00
|
|
|
test-tool pkt-line pack <pkt >in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
|
2019-04-18 21:16:51 +08:00
|
|
|
test-tool serve-v2 --stateless-rpc >out <in &&
|
2018-06-28 06:30:17 +08:00
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
2018-06-28 06:30:23 +08:00
|
|
|
REPO="$(pwd)/repo"
|
|
|
|
LOCAL_PRISTINE="$(pwd)/local_pristine"
|
|
|
|
|
|
|
|
# $REPO
|
|
|
|
# c(o/foo) d(o/bar)
|
|
|
|
# \ /
|
2020-12-17 09:07:07 +08:00
|
|
|
# b e(baz) f(main)
|
2018-06-28 06:30:23 +08:00
|
|
|
# \__ | __/
|
|
|
|
# \ | /
|
|
|
|
# a
|
|
|
|
#
|
|
|
|
# $LOCAL_PRISTINE
|
|
|
|
# s32(side)
|
|
|
|
# |
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# |
|
2020-12-17 09:07:07 +08:00
|
|
|
# a(main)
|
2018-06-28 06:30:23 +08:00
|
|
|
test_expect_success 'setup repos for fetching with ref-in-want tests' '
|
|
|
|
(
|
2020-12-17 09:07:07 +08:00
|
|
|
git init -b main "$REPO" &&
|
2018-06-28 06:30:23 +08:00
|
|
|
cd "$REPO" &&
|
|
|
|
test_commit a &&
|
|
|
|
|
|
|
|
# Local repo with many commits (so that negotiation will take
|
|
|
|
# more than 1 request/response pair)
|
|
|
|
rm -rf "$LOCAL_PRISTINE" &&
|
|
|
|
git clone "file://$REPO" "$LOCAL_PRISTINE" &&
|
|
|
|
cd "$LOCAL_PRISTINE" &&
|
|
|
|
git checkout -b side &&
|
2019-06-28 17:42:07 +08:00
|
|
|
test_commit_bulk --id=s 33 &&
|
2018-06-28 06:30:23 +08:00
|
|
|
|
|
|
|
# Add novel commits to upstream
|
2020-12-17 09:07:07 +08:00
|
|
|
git checkout main &&
|
2018-06-28 06:30:23 +08:00
|
|
|
cd "$REPO" &&
|
|
|
|
git checkout -b o/foo &&
|
|
|
|
test_commit b &&
|
|
|
|
test_commit c &&
|
|
|
|
git checkout -b o/bar b &&
|
|
|
|
test_commit d &&
|
|
|
|
git checkout -b baz a &&
|
|
|
|
test_commit e &&
|
2020-12-17 09:07:07 +08:00
|
|
|
git checkout main &&
|
2018-06-28 06:30:23 +08:00
|
|
|
test_commit f
|
|
|
|
) &&
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant true &&
|
|
|
|
git -C "$LOCAL_PRISTINE" config protocol.version 2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetching with exact OID' '
|
|
|
|
test_when_finished "rm -f log" &&
|
|
|
|
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2019-11-28 03:53:38 +08:00
|
|
|
oid=$(git -C "$REPO" rev-parse d) &&
|
2018-06-28 06:30:23 +08:00
|
|
|
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
|
2019-11-28 03:53:38 +08:00
|
|
|
"$oid":refs/heads/actual &&
|
2018-06-28 06:30:23 +08:00
|
|
|
|
|
|
|
git -C "$REPO" rev-parse "d" >expected &&
|
|
|
|
git -C local rev-parse refs/heads/actual >actual &&
|
|
|
|
test_cmp expected actual &&
|
2019-11-28 03:53:38 +08:00
|
|
|
grep "want $oid" log
|
2018-06-28 06:30:23 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetching multiple refs' '
|
|
|
|
test_when_finished "rm -f log" &&
|
|
|
|
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-12-17 09:07:07 +08:00
|
|
|
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin main baz &&
|
2018-06-28 06:30:23 +08:00
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
git -C "$REPO" rev-parse "main" "baz" >expected &&
|
|
|
|
git -C local rev-parse refs/remotes/origin/main refs/remotes/origin/baz >actual &&
|
2018-06-28 06:30:23 +08:00
|
|
|
test_cmp expected actual &&
|
2020-12-17 09:07:07 +08:00
|
|
|
grep "want-ref refs/heads/main" log &&
|
2018-06-28 06:30:23 +08:00
|
|
|
grep "want-ref refs/heads/baz" log
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetching ref and exact OID' '
|
|
|
|
test_when_finished "rm -f log" &&
|
|
|
|
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2019-11-28 03:53:38 +08:00
|
|
|
oid=$(git -C "$REPO" rev-parse b) &&
|
2018-06-28 06:30:23 +08:00
|
|
|
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
|
2020-12-17 09:07:07 +08:00
|
|
|
main "$oid":refs/heads/actual &&
|
2018-06-28 06:30:23 +08:00
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
git -C "$REPO" rev-parse "main" "b" >expected &&
|
|
|
|
git -C local rev-parse refs/remotes/origin/main refs/heads/actual >actual &&
|
2018-06-28 06:30:23 +08:00
|
|
|
test_cmp expected actual &&
|
2019-11-28 03:53:38 +08:00
|
|
|
grep "want $oid" log &&
|
2020-12-17 09:07:07 +08:00
|
|
|
grep "want-ref refs/heads/main" log
|
2018-06-28 06:30:23 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetching with wildcard that does not match any refs' '
|
|
|
|
test_when_finished "rm -f log" &&
|
|
|
|
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
|
|
|
git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
|
|
|
|
test_must_be_empty out
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetching with wildcard that matches multiple refs' '
|
|
|
|
test_when_finished "rm -f log" &&
|
|
|
|
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
|
|
|
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
|
|
|
|
|
|
|
|
git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
|
|
|
|
git -C local rev-parse "o/foo" "o/bar" >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
grep "want-ref refs/heads/o/foo" log &&
|
|
|
|
grep "want-ref refs/heads/o/bar" log
|
|
|
|
'
|
|
|
|
|
2021-08-13 14:23:50 +08:00
|
|
|
REPO="$(pwd)/repo-ns"
|
|
|
|
|
|
|
|
test_expect_success 'setup namespaced repo' '
|
|
|
|
(
|
|
|
|
git init -b main "$REPO" &&
|
|
|
|
cd "$REPO" &&
|
|
|
|
test_commit a &&
|
|
|
|
test_commit b &&
|
|
|
|
git checkout a &&
|
|
|
|
test_commit c &&
|
|
|
|
git checkout a &&
|
|
|
|
test_commit d &&
|
|
|
|
git update-ref refs/heads/ns-no b &&
|
|
|
|
git update-ref refs/namespaces/ns/refs/heads/ns-yes c &&
|
|
|
|
git update-ref refs/namespaces/ns/refs/heads/hidden d
|
|
|
|
) &&
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant true
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with namespace: want-ref is considered relative to namespace' '
|
|
|
|
wanted_ref=refs/heads/ns-yes &&
|
|
|
|
|
|
|
|
oid=$(git -C "$REPO" rev-parse "refs/namespaces/ns/$wanted_ref") &&
|
|
|
|
cat >expected_refs <<-EOF &&
|
|
|
|
$oid $wanted_ref
|
|
|
|
EOF
|
|
|
|
cat >expected_commits <<-EOF &&
|
|
|
|
$oid
|
|
|
|
$(git -C "$REPO" rev-parse a)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
GIT_NAMESPACE=ns test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with namespace: want-ref outside namespace is unknown' '
|
|
|
|
wanted_ref=refs/heads/ns-no &&
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
test_must_fail env GIT_NAMESPACE=ns \
|
|
|
|
test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
grep "unknown ref" out
|
|
|
|
'
|
|
|
|
|
|
|
|
# Cross-check refs/heads/ns-no indeed exists
|
|
|
|
test_expect_success 'without namespace: want-ref outside namespace succeeds' '
|
|
|
|
wanted_ref=refs/heads/ns-no &&
|
|
|
|
|
|
|
|
oid=$(git -C "$REPO" rev-parse $wanted_ref) &&
|
|
|
|
cat >expected_refs <<-EOF &&
|
|
|
|
$oid $wanted_ref
|
|
|
|
EOF
|
|
|
|
cat >expected_commits <<-EOF &&
|
|
|
|
$oid
|
|
|
|
$(git -C "$REPO" rev-parse a)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'with namespace: hideRefs is matched, relative to namespace' '
|
|
|
|
wanted_ref=refs/heads/hidden &&
|
|
|
|
git -C "$REPO" config transfer.hideRefs $wanted_ref &&
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
test_must_fail env GIT_NAMESPACE=ns \
|
|
|
|
test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
grep "unknown ref" out
|
|
|
|
'
|
|
|
|
|
|
|
|
# Cross-check refs/heads/hidden indeed exists
|
|
|
|
test_expect_success 'with namespace: want-ref succeeds if hideRefs is removed' '
|
|
|
|
wanted_ref=refs/heads/hidden &&
|
|
|
|
git -C "$REPO" config --unset transfer.hideRefs $wanted_ref &&
|
|
|
|
|
|
|
|
oid=$(git -C "$REPO" rev-parse "refs/namespaces/ns/$wanted_ref") &&
|
|
|
|
cat >expected_refs <<-EOF &&
|
|
|
|
$oid $wanted_ref
|
|
|
|
EOF
|
|
|
|
cat >expected_commits <<-EOF &&
|
|
|
|
$oid
|
|
|
|
$(git -C "$REPO" rev-parse a)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
GIT_NAMESPACE=ns test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'without namespace: relative hideRefs does not match' '
|
|
|
|
wanted_ref=refs/namespaces/ns/refs/heads/hidden &&
|
|
|
|
git -C "$REPO" config transfer.hideRefs refs/heads/hidden &&
|
|
|
|
|
|
|
|
oid=$(git -C "$REPO" rev-parse $wanted_ref) &&
|
|
|
|
cat >expected_refs <<-EOF &&
|
|
|
|
$oid $wanted_ref
|
|
|
|
EOF
|
|
|
|
cat >expected_commits <<-EOF &&
|
|
|
|
$oid
|
|
|
|
$(git -C "$REPO" rev-parse a)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
write_fetch_command >pkt <<-EOF &&
|
|
|
|
want-ref $wanted_ref
|
|
|
|
EOF
|
|
|
|
test-tool pkt-line pack <pkt >in &&
|
|
|
|
|
|
|
|
test-tool -C "$REPO" serve-v2 --stateless-rpc >out <in &&
|
|
|
|
check_output
|
|
|
|
'
|
|
|
|
|
|
|
|
|
2019-08-01 23:53:08 +08:00
|
|
|
. "$TEST_DIRECTORY"/lib-httpd.sh
|
|
|
|
start_httpd
|
|
|
|
|
|
|
|
REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
|
|
|
|
LOCAL_PRISTINE="$(pwd)/local_pristine"
|
|
|
|
|
|
|
|
test_expect_success 'setup repos for change-while-negotiating test' '
|
|
|
|
(
|
2020-12-17 09:07:07 +08:00
|
|
|
git init -b main "$REPO" &&
|
2019-08-01 23:53:08 +08:00
|
|
|
cd "$REPO" &&
|
|
|
|
>.git/git-daemon-export-ok &&
|
|
|
|
test_commit m1 &&
|
|
|
|
git tag -d m1 &&
|
|
|
|
|
|
|
|
# Local repo with many commits (so that negotiation will take
|
|
|
|
# more than 1 request/response pair)
|
|
|
|
rm -rf "$LOCAL_PRISTINE" &&
|
|
|
|
git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
|
|
|
|
cd "$LOCAL_PRISTINE" &&
|
|
|
|
git checkout -b side &&
|
|
|
|
test_commit_bulk --id=s 33 &&
|
|
|
|
|
|
|
|
# Add novel commits to upstream
|
2020-12-17 09:07:07 +08:00
|
|
|
git checkout main &&
|
2019-08-01 23:53:08 +08:00
|
|
|
cd "$REPO" &&
|
|
|
|
test_commit m2 &&
|
|
|
|
test_commit m3 &&
|
|
|
|
git tag -d m2 m3
|
|
|
|
) &&
|
t/lib-httpd: avoid using macOS' sed
Among other differences relative to GNU sed, macOS' sed always ends its
output with a trailing newline, even if the input did not have such a
trailing newline.
Surprisingly, this makes three httpd-based tests fail on macOS: t5616,
t5702 and t5703. ("Surprisingly" because those tests have been around
for some time, but apparently nobody runs them on macOS with a working
Apache2 setup.)
The reason is that we use `sed` in those tests to filter the response of
the web server. Apart from the fact that we use GNU constructs (such as
using a space after the `c` command instead of a backslash and a
newline), we have another problem: macOS' sed LF-only newlines while
webservers are supposed to use CR/LF ones.
Even worse, t5616 uses `sed` to replace a binary part of the response
with a new binary part (kind of hoping that the replaced binary part
does not contain a 0x0a byte which would be interpreted as a newline).
To that end, it calls on Perl to read the binary pack file and
hex-encode it, then calls on `sed` to prefix every hex digit pair with a
`\x` in order to construct the text that the `c` statement of the `sed`
invocation is supposed to insert. So we call Perl and sed to construct a
sed statement. The final nail in the coffin is that macOS' sed does not
even interpret those `\x<hex>` constructs.
Let's just replace all of that by Perl snippets. With Perl, at least, we
do not have to deal with GNU vs macOS semantics, we do not have to worry
about unwanted trailing newlines, and we do not have to spawn commands
to construct arguments for other commands to be spawned (i.e. we can
avoid a whole lot of shell scripting complexity).
The upshot is that this fixes t5616, t5702 and t5703 on macOS with
Apache2.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-27 21:23:11 +08:00
|
|
|
git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
|
2019-08-01 23:53:08 +08:00
|
|
|
git -C "$LOCAL_PRISTINE" config protocol.version 2
|
|
|
|
'
|
|
|
|
|
|
|
|
inconsistency () {
|
|
|
|
# Simulate that the server initially reports $2 as the ref
|
|
|
|
# corresponding to $1, and after that, $1 as the ref corresponding to
|
|
|
|
# $1. This corresponds to the real-life situation where the server's
|
|
|
|
# repository appears to change during negotiation, for example, when
|
|
|
|
# different servers in a load-balancing arrangement serve (stateless)
|
|
|
|
# RPCs during a single negotiation.
|
2019-11-28 03:53:36 +08:00
|
|
|
oid1=$(git -C "$REPO" rev-parse $1) &&
|
|
|
|
oid2=$(git -C "$REPO" rev-parse $2) &&
|
t/lib-httpd: avoid using macOS' sed
Among other differences relative to GNU sed, macOS' sed always ends its
output with a trailing newline, even if the input did not have such a
trailing newline.
Surprisingly, this makes three httpd-based tests fail on macOS: t5616,
t5702 and t5703. ("Surprisingly" because those tests have been around
for some time, but apparently nobody runs them on macOS with a working
Apache2 setup.)
The reason is that we use `sed` in those tests to filter the response of
the web server. Apart from the fact that we use GNU constructs (such as
using a space after the `c` command instead of a backslash and a
newline), we have another problem: macOS' sed LF-only newlines while
webservers are supposed to use CR/LF ones.
Even worse, t5616 uses `sed` to replace a binary part of the response
with a new binary part (kind of hoping that the replaced binary part
does not contain a 0x0a byte which would be interpreted as a newline).
To that end, it calls on Perl to read the binary pack file and
hex-encode it, then calls on `sed` to prefix every hex digit pair with a
`\x` in order to construct the text that the `c` statement of the `sed`
invocation is supposed to insert. So we call Perl and sed to construct a
sed statement. The final nail in the coffin is that macOS' sed does not
even interpret those `\x<hex>` constructs.
Let's just replace all of that by Perl snippets. With Perl, at least, we
do not have to deal with GNU vs macOS semantics, we do not have to worry
about unwanted trailing newlines, and we do not have to spawn commands
to construct arguments for other commands to be spawned (i.e. we can
avoid a whole lot of shell scripting complexity).
The upshot is that this fixes t5616, t5702 and t5703 on macOS with
Apache2.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-02-27 21:23:11 +08:00
|
|
|
echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
|
2019-08-01 23:53:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'server is initially ahead - no ref in want' '
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant false &&
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-12-17 09:07:07 +08:00
|
|
|
inconsistency main $(test_oid numeric) &&
|
2019-08-01 23:53:08 +08:00
|
|
|
test_must_fail git -C local fetch 2>err &&
|
|
|
|
test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'server is initially ahead - ref in want' '
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant true &&
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-12-17 09:07:07 +08:00
|
|
|
inconsistency main $(test_oid numeric) &&
|
2019-08-01 23:53:08 +08:00
|
|
|
git -C local fetch &&
|
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
git -C "$REPO" rev-parse --verify main >expected &&
|
|
|
|
git -C local rev-parse --verify refs/remotes/origin/main >actual &&
|
2019-08-01 23:53:08 +08:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'server is initially behind - no ref in want' '
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant false &&
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-12-17 09:07:07 +08:00
|
|
|
inconsistency main "main^" &&
|
2019-08-01 23:53:08 +08:00
|
|
|
git -C local fetch &&
|
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
git -C "$REPO" rev-parse --verify "main^" >expected &&
|
|
|
|
git -C local rev-parse --verify refs/remotes/origin/main >actual &&
|
2019-08-01 23:53:08 +08:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'server is initially behind - ref in want' '
|
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant true &&
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-12-17 09:07:07 +08:00
|
|
|
inconsistency main "main^" &&
|
2019-08-01 23:53:08 +08:00
|
|
|
git -C local fetch &&
|
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
git -C "$REPO" rev-parse --verify "main" >expected &&
|
|
|
|
git -C local rev-parse --verify refs/remotes/origin/main >actual &&
|
2019-08-01 23:53:08 +08:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2020-12-17 09:07:07 +08:00
|
|
|
test_expect_success 'server loses a ref - ref in want' '
|
2019-08-01 23:53:08 +08:00
|
|
|
git -C "$REPO" config uploadpack.allowRefInWant true &&
|
|
|
|
rm -rf local &&
|
|
|
|
cp -r "$LOCAL_PRISTINE" local &&
|
2020-10-23 22:00:02 +08:00
|
|
|
echo "s/main/rain/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
|
2019-08-01 23:53:08 +08:00
|
|
|
test_must_fail git -C local fetch 2>err &&
|
|
|
|
|
2020-10-23 22:00:02 +08:00
|
|
|
test_i18ngrep "fatal: remote error: unknown ref refs/heads/rain" err
|
2019-08-01 23:53:08 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
# DO NOT add non-httpd-specific tests here, because the last part of this
|
|
|
|
# test script is only executed when httpd is available and enabled.
|
|
|
|
|
2018-06-28 06:30:17 +08:00
|
|
|
test_done
|