summaryrefslogtreecommitdiff
path: root/t/t5702-protocol-v2.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t5702-protocol-v2.sh')
-rwxr-xr-xt/t5702-protocol-v2.sh554
1 files changed, 507 insertions, 47 deletions
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index 1b54c35..1ef540f 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -4,6 +4,9 @@ test_description='test git wire-protocol version 2'
TEST_NO_CREATE_REPO=1
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
# Test protocol v2 with 'git://' transport
@@ -13,7 +16,6 @@ start_git_daemon --export-all --enable=receive-pack
daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
test_expect_success 'create repo to be served by git-daemon' '
- test_oid_init &&
git init "$daemon_parent" &&
test_commit -C "$daemon_parent" one
'
@@ -25,9 +27,9 @@ test_expect_success 'list refs with git:// using protocol v2' '
ls-remote --symref "$GIT_DAEMON_URL/parent" >actual &&
# Client requested to use protocol v2
- grep "git> .*\\\0\\\0version=2\\\0$" log &&
+ grep "ls-remote> .*\\\0\\\0version=2\\\0$" log &&
# Server responded using protocol v2
- grep "git< version 2" log &&
+ grep "ls-remote< version 2" log &&
git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
test_cmp expect actual
@@ -37,10 +39,10 @@ test_expect_success 'ref advertisement is filtered with ls-remote using protocol
test_when_finished "rm -f log" &&
GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
- ls-remote "$GIT_DAEMON_URL/parent" master >actual &&
+ ls-remote "$GIT_DAEMON_URL/parent" main >actual &&
cat >expect <<-EOF &&
- $(git -C "$daemon_parent" rev-parse refs/heads/master)$(printf "\t")refs/heads/master
+ $(git -C "$daemon_parent" rev-parse refs/heads/main)$(printf "\t")refs/heads/main
EOF
test_cmp expect actual
@@ -70,7 +72,7 @@ test_expect_success 'fetch with git:// using protocol v2' '
GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
fetch &&
- git -C daemon_child log -1 --format=%s origin/master >actual &&
+ git -C daemon_child log -1 --format=%s origin/main >actual &&
git -C "$daemon_parent" log -1 --format=%s >expect &&
test_cmp expect actual &&
@@ -119,7 +121,7 @@ test_expect_success 'push with git:// and a config of v2 does not request v2' '
test_commit -C daemon_child three &&
# Push to another branch, as the target repository has the
- # master branch checked out and we cannot push into it.
+ # main branch checked out and we cannot push into it.
GIT_TRACE_PACKET="$(pwd)/log" git -C daemon_child -c protocol.version=2 \
push origin HEAD:client_branch &&
@@ -149,7 +151,7 @@ test_expect_success 'list refs with file:// using protocol v2' '
ls-remote --symref "file://$(pwd)/file_parent" >actual &&
# Server responded using protocol v2
- grep "git< version 2" log &&
+ grep "ls-remote< version 2" log &&
git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
test_cmp expect actual
@@ -159,10 +161,10 @@ test_expect_success 'ref advertisement is filtered with ls-remote using protocol
test_when_finished "rm -f log" &&
GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
- ls-remote "file://$(pwd)/file_parent" master >actual &&
+ ls-remote "file://$(pwd)/file_parent" main >actual &&
cat >expect <<-EOF &&
- $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
+ $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
EOF
test_cmp expect actual
@@ -172,10 +174,10 @@ test_expect_success 'server-options are sent when using ls-remote' '
test_when_finished "rm -f log" &&
GIT_TRACE_PACKET="$(pwd)/log" git -c protocol.version=2 \
- ls-remote -o hello -o world "file://$(pwd)/file_parent" master >actual &&
+ ls-remote -o hello -o world "file://$(pwd)/file_parent" main >actual &&
cat >expect <<-EOF &&
- $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
+ $(git -C file_parent rev-parse refs/heads/main)$(printf "\t")refs/heads/main
EOF
test_cmp expect actual &&
@@ -185,10 +187,10 @@ test_expect_success 'server-options are sent when using ls-remote' '
test_expect_success 'warn if using server-option with ls-remote with legacy protocol' '
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -c protocol.version=0 \
- ls-remote -o hello -o world "file://$(pwd)/file_parent" master 2>err &&
+ ls-remote -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
- test_i18ngrep "see protocol.version in" err &&
- test_i18ngrep "server options require protocol version 2 or later" err
+ test_grep "see protocol.version in" err &&
+ test_grep "server options require protocol version 2 or later" err
'
test_expect_success 'clone with file:// using protocol v2' '
@@ -210,6 +212,126 @@ test_expect_success 'clone with file:// using protocol v2' '
grep "ref-prefix refs/tags/" log
'
+test_expect_success 'clone of empty repo propagates name of default branch' '
+ test_when_finished "rm -rf file_empty_parent file_empty_child" &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=main -c protocol.version=2 \
+ clone "file://$(pwd)/file_empty_parent" file_empty_child &&
+ echo refs/heads/mydefaultbranch >expect &&
+ git -C file_empty_child symbolic-ref HEAD >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '...but not if explicitly forbidden by config' '
+ test_when_finished "rm -rf file_empty_parent file_empty_child" &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
+ test_config -C file_empty_parent lsrefs.unborn ignore &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=main -c protocol.version=2 \
+ clone "file://$(pwd)/file_empty_parent" file_empty_child &&
+ echo refs/heads/main >expect &&
+ git -C file_empty_child symbolic-ref HEAD >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'bare clone propagates empty default branch' '
+ test_when_finished "rm -rf file_empty_parent file_empty_child.git" &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=mydefaultbranch init file_empty_parent &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=main -c protocol.version=2 \
+ clone --bare \
+ "file://$(pwd)/file_empty_parent" file_empty_child.git &&
+ echo "refs/heads/mydefaultbranch" >expect &&
+ git -C file_empty_child.git symbolic-ref HEAD >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'clone propagates unborn HEAD from non-empty repo' '
+ test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
+
+ git init file_unborn_parent &&
+ (
+ cd file_unborn_parent &&
+ git checkout -b branchwithstuff &&
+ test_commit --no-tag stuff &&
+ git symbolic-ref HEAD refs/heads/mydefaultbranch
+ ) &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=main -c protocol.version=2 \
+ clone "file://$(pwd)/file_unborn_parent" \
+ file_unborn_child 2>stderr &&
+ echo "refs/heads/mydefaultbranch" >expect &&
+ git -C file_unborn_child symbolic-ref HEAD >actual &&
+ test_cmp expect actual &&
+ grep "warning: remote HEAD refers to nonexistent ref" stderr
+'
+
+test_expect_success 'clone propagates object-format from empty repo' '
+ test_when_finished "rm -fr src256 dst256" &&
+
+ echo sha256 >expect &&
+ git init --object-format=sha256 src256 &&
+ git clone src256 dst256 &&
+ git -C dst256 rev-parse --show-object-format >actual &&
+
+ test_cmp expect actual
+'
+
+test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
+ test_when_finished "rm -rf file_unborn_parent file_unborn_child.git" &&
+
+ git init file_unborn_parent &&
+ (
+ cd file_unborn_parent &&
+ git checkout -b branchwithstuff &&
+ test_commit --no-tag stuff &&
+ git symbolic-ref HEAD refs/heads/mydefaultbranch
+ ) &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=main -c protocol.version=2 \
+ clone --bare "file://$(pwd)/file_unborn_parent" \
+ file_unborn_child.git 2>stderr &&
+ echo "refs/heads/mydefaultbranch" >expect &&
+ git -C file_unborn_child.git symbolic-ref HEAD >actual &&
+ test_cmp expect actual &&
+ ! grep "warning:" stderr
+'
+
+test_expect_success 'defaulted HEAD uses remote branch if available' '
+ test_when_finished "rm -rf file_unborn_parent file_unborn_child" &&
+
+ git init file_unborn_parent &&
+ (
+ cd file_unborn_parent &&
+ git config lsrefs.unborn ignore &&
+ git checkout -b branchwithstuff &&
+ test_commit --no-tag stuff &&
+ git symbolic-ref HEAD refs/heads/mydefaultbranch
+ ) &&
+
+ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
+ git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \
+ clone "file://$(pwd)/file_unborn_parent" \
+ file_unborn_child 2>stderr &&
+ echo "refs/heads/branchwithstuff" >expect &&
+ git -C file_unborn_child symbolic-ref HEAD >actual &&
+ test_cmp expect actual &&
+ test_path_is_file file_unborn_child/stuff.t &&
+ ! grep "warning:" stderr
+'
+
test_expect_success 'fetch with file:// using protocol v2' '
test_when_finished "rm -f log" &&
@@ -218,7 +340,7 @@ test_expect_success 'fetch with file:// using protocol v2' '
GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
fetch origin &&
- git -C file_child log -1 --format=%s origin/master >actual &&
+ git -C file_child log -1 --format=%s origin/main >actual &&
git -C file_parent log -1 --format=%s >expect &&
test_cmp expect actual &&
@@ -233,13 +355,13 @@ test_expect_success 'ref advertisement is filtered during fetch using protocol v
git -C file_parent branch unwanted-branch three &&
GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
- fetch origin master &&
+ fetch origin main &&
- git -C file_child log -1 --format=%s origin/master >actual &&
+ git -C file_child log -1 --format=%s origin/main >actual &&
git -C file_parent log -1 --format=%s >expect &&
test_cmp expect actual &&
- grep "refs/heads/master" log &&
+ grep "refs/heads/main" log &&
! grep "refs/heads/unwanted-branch" log
'
@@ -249,9 +371,9 @@ test_expect_success 'server-options are sent when fetching' '
test_commit -C file_parent four &&
GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
- fetch -o hello -o world origin master &&
+ fetch -o hello -o world origin main &&
- git -C file_child log -1 --format=%s origin/master >actual &&
+ git -C file_child log -1 --format=%s origin/main >actual &&
git -C file_parent log -1 --format=%s >expect &&
test_cmp expect actual &&
@@ -265,10 +387,10 @@ test_expect_success 'warn if using server-option with fetch with legacy protocol
git init temp_child &&
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C temp_child -c protocol.version=0 \
- fetch -o hello -o world "file://$(pwd)/file_parent" master 2>err &&
+ fetch -o hello -o world "file://$(pwd)/file_parent" main 2>err &&
- test_i18ngrep "see protocol.version in" err &&
- test_i18ngrep "server options require protocol version 2 or later" err
+ test_grep "see protocol.version in" err &&
+ test_grep "server options require protocol version 2 or later" err
'
test_expect_success 'server-options are sent when cloning' '
@@ -289,8 +411,8 @@ test_expect_success 'warn if using server-option with clone with legacy protocol
clone --server-option=hello --server-option=world \
"file://$(pwd)/file_parent" myclone 2>err &&
- test_i18ngrep "see protocol.version in" err &&
- test_i18ngrep "server options require protocol version 2 or later" err
+ test_grep "see protocol.version in" err &&
+ test_grep "server options require protocol version 2 or later" err
'
test_expect_success 'upload-pack respects config using protocol v2' '
@@ -326,7 +448,7 @@ test_expect_success 'partial clone' '
grep "version 2" trace &&
# Ensure that the old version of the file is missing
- git -C client rev-list --quiet --objects --missing=print master \
+ git -C client rev-list --quiet --objects --missing=print main \
>observed.oids &&
grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
@@ -351,7 +473,7 @@ test_expect_success 'partial fetch' '
SERVER="file://$(pwd)/server" &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
- fetch --filter=blob:none "$SERVER" master:refs/heads/other &&
+ fetch --filter=blob:none "$SERVER" main:refs/heads/other &&
grep "version 2" trace &&
# Ensure that the old version of the file is missing
@@ -385,7 +507,7 @@ test_expect_success 'partial clone warns if filter is not advertised' '
git -C server config uploadpack.allowfilter 0 &&
git -c protocol.version=2 \
clone --filter=blob:none "file://$(pwd)/server" client 2>err &&
- test_i18ngrep "filtering not recognized by server, ignoring" err
+ test_grep "filtering not recognized by server, ignoring" err
'
test_expect_success 'even with handcrafted request, filter does not work if not advertised' '
@@ -396,7 +518,7 @@ test_expect_success 'even with handcrafted request, filter does not work if not
command=fetch
object-format=$(test_oid algo)
0001
- want $(git -C server rev-parse master)
+ want $(git -C server rev-parse main)
filter blob:none
0000
EOF
@@ -540,7 +662,7 @@ test_expect_success 'deepen-relative' '
test_commit -C server four &&
# Sanity check that only "three" is downloaded
- git -C client log --pretty=tformat:%s master >actual &&
+ git -C client log --pretty=tformat:%s main >actual &&
echo three >expected &&
test_cmp expected actual &&
@@ -549,7 +671,7 @@ test_expect_success 'deepen-relative' '
# Ensure that protocol v2 is used
grep "fetch< version 2" trace &&
- git -C client log --pretty=tformat:%s origin/master >actual &&
+ git -C client log --pretty=tformat:%s origin/main >actual &&
cat >expected <<-\EOF &&
four
three
@@ -558,6 +680,123 @@ test_expect_success 'deepen-relative' '
test_cmp expected actual
'
+setup_negotiate_only () {
+ SERVER="$1"
+ URI="$2"
+
+ rm -rf "$SERVER" client
+
+ git init "$SERVER"
+ test_commit -C "$SERVER" one
+ test_commit -C "$SERVER" two
+
+ git clone "$URI" client
+ test_commit -C client three
+}
+
+test_expect_success 'usage: --negotiate-only without --negotiation-tip' '
+ SERVER="server" &&
+ URI="file://$(pwd)/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ cat >err.expect <<-\EOF &&
+ fatal: --negotiate-only needs one or more --negotiation-tip=*
+ EOF
+
+ test_must_fail git -c protocol.version=2 -C client fetch \
+ --negotiate-only \
+ origin 2>err.actual &&
+ test_cmp err.expect err.actual
+'
+
+test_expect_success 'usage: --negotiate-only with --recurse-submodules' '
+ cat >err.expect <<-\EOF &&
+ fatal: options '\''--negotiate-only'\'' and '\''--recurse-submodules'\'' cannot be used together
+ EOF
+
+ test_must_fail git -c protocol.version=2 -C client fetch \
+ --negotiate-only \
+ --recurse-submodules \
+ origin 2>err.actual &&
+ test_cmp err.expect err.actual
+'
+
+test_expect_success 'file:// --negotiate-only' '
+ SERVER="server" &&
+ URI="file://$(pwd)/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ git -c protocol.version=2 -C client fetch \
+ --no-tags \
+ --negotiate-only \
+ --negotiation-tip=$(git -C client rev-parse HEAD) \
+ origin >out &&
+ COMMON=$(git -C "$SERVER" rev-parse two) &&
+ grep "$COMMON" out
+'
+
+test_expect_success 'file:// --negotiate-only with protocol v0' '
+ SERVER="server" &&
+ URI="file://$(pwd)/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ test_must_fail git -c protocol.version=0 -C client fetch \
+ --no-tags \
+ --negotiate-only \
+ --negotiation-tip=$(git -C client rev-parse HEAD) \
+ origin 2>err &&
+ test_grep "negotiate-only requires protocol v2" err
+'
+
+test_expect_success 'push with custom path does not request v2' '
+ rm -f env.trace &&
+ git -C client push \
+ --receive-pack="env >../env.trace; git-receive-pack" \
+ origin HEAD:refs/heads/custom-push-test &&
+ test_path_is_file env.trace &&
+ ! grep ^GIT_PROTOCOL env.trace
+'
+
+test_expect_success 'fetch with custom path does request v2' '
+ rm -f env.trace &&
+ git -C client fetch \
+ --upload-pack="env >../env.trace; git-upload-pack" \
+ origin HEAD &&
+ grep ^GIT_PROTOCOL=version=2 env.trace
+'
+
+test_expect_success 'archive with custom path does not request v2' '
+ rm -f env.trace &&
+ git -C client archive \
+ --exec="env >../env.trace; git-upload-archive" \
+ --remote=origin \
+ HEAD >/dev/null &&
+ test_path_is_file env.trace &&
+ ! grep ^GIT_PROTOCOL env.trace
+'
+
+test_expect_success 'reject client packfile-uris if not advertised' '
+ {
+ packetize command=fetch &&
+ packetize object-format=$(test_oid algo) &&
+ printf 0001 &&
+ packetize packfile-uris https &&
+ packetize done &&
+ printf 0000
+ } >input &&
+ test_must_fail env GIT_PROTOCOL=version=2 \
+ git upload-pack client <input &&
+ test_must_fail env GIT_PROTOCOL=version=2 \
+ git -c uploadpack.blobpackfileuri \
+ upload-pack client <input &&
+ GIT_PROTOCOL=version=2 \
+ git -c uploadpack.blobpackfileuri=anything \
+ upload-pack client <input
+'
+
# Test protocol v2 with 'http://' transport
#
. "$TEST_DIRECTORY"/lib-httpd.sh
@@ -601,7 +840,7 @@ test_expect_success 'clone repository with http:// using protocol v2 with incomp
# Server responded using protocol v2
grep "git< version 2" log &&
# Client reported appropriate failure
- test_i18ngrep "bytes of length header were received" err
+ test_grep "bytes of length header were received" err
'
test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' '
@@ -618,7 +857,7 @@ test_expect_success 'clone repository with http:// using protocol v2 with incomp
# Server responded using protocol v2
grep "git< version 2" log &&
# Client reported appropriate failure
- test_i18ngrep "bytes of body are still expected" err
+ test_grep "bytes of body are still expected" err
'
test_expect_success 'clone with http:// using protocol v2 and invalid parameters' '
@@ -648,7 +887,7 @@ test_expect_success 'clone big repository with http:// using protocol v2' '
echo "data 0" &&
echo "M 644 inline bla.txt" &&
echo "data 4" &&
- echo "bla"
+ echo "bla" || return 1
done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
@@ -671,7 +910,7 @@ test_expect_success 'fetch with http:// using protocol v2' '
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
fetch &&
- git -C http_child log -1 --format=%s origin/master >actual &&
+ git -C http_child log -1 --format=%s origin/main >actual &&
git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" log -1 --format=%s >expect &&
test_cmp expect actual &&
@@ -699,11 +938,11 @@ test_expect_success 'fetch from namespaced repo respects namespaces' '
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
- update-ref refs/namespaces/ns/refs/heads/master one &&
+ update-ref refs/namespaces/ns/refs/heads/main one &&
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
fetch "$HTTPD_URL/smart_namespace/nsrepo" \
- refs/heads/master:refs/heads/theirs &&
+ refs/heads/main:refs/heads/theirs &&
# Server responded using protocol v2
grep "fetch< version 2" log &&
@@ -734,7 +973,7 @@ test_expect_success 'push with http:// and a config of v2 does not request v2' '
test_commit -C http_child three &&
# Push to another branch, as the target repository has the
- # master branch checked out and we cannot push into it.
+ # main branch checked out and we cannot push into it.
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
push origin HEAD:client_branch &&
@@ -765,7 +1004,7 @@ test_expect_success 'when server sends "ready", expect DELIM' '
test_must_fail git -C http_child -c protocol.version=2 \
fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
- test_i18ngrep "expected packfile to be sent after .ready." err
+ test_grep "expected packfile to be sent after .ready." err
'
test_expect_success 'when server does not send "ready", expect FLUSH' '
@@ -793,7 +1032,7 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
fetch "$HTTPD_URL/one_time_perl/http_parent" 2> err &&
grep "fetch< .*acknowledgments" log &&
! grep "fetch< .*ready" log &&
- test_i18ngrep "expected no other sections to be sent after no .ready." err
+ test_grep "expected no other sections to be sent after no .ready." err
'
configure_exclusion () {
@@ -829,9 +1068,9 @@ test_expect_success 'part of packfile response provided as URI' '
# Ensure that my-blob and other-blob are in separate packfiles.
for idx in http_child/.git/objects/pack/*.idx
do
- git verify-pack --verbose $idx >out &&
+ git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
{
- grep "^[0-9a-f]\{16,\} " out || :
+ grep -E "^[0-9a-f]{16,} " out || :
} >out.objectlist &&
if test_line_count = 1 out.objectlist
then
@@ -843,16 +1082,38 @@ test_expect_success 'part of packfile response provided as URI' '
then
>h2found
fi
- fi
+ fi || return 1
done &&
test -f hfound &&
test -f h2found &&
- # Ensure that there are exactly 6 files (3 .pack and 3 .idx).
- ls http_child/.git/objects/pack/* >filelist &&
+ # Ensure that there are exactly 3 packfiles with associated .idx
+ ls http_child/.git/objects/pack/*.pack \
+ http_child/.git/objects/pack/*.idx >filelist &&
test_line_count = 6 filelist
'
+test_expect_success 'packfile URIs with fetch instead of clone' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ configure_exclusion "$P" my-blob >h &&
+
+ git init http_child &&
+
+ GIT_TEST_SIDEBAND_ALL=1 \
+ git -C http_child -c protocol.version=2 \
+ -c fetch.uriprotocols=http,https \
+ fetch "$HTTPD_URL/smart/http_parent"
+'
+
test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
rm -rf "$P" http_child log &&
@@ -881,7 +1142,206 @@ test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
git -c protocol.version=2 \
-c fetch.uriprotocols=http,https \
clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
- test_i18ngrep "pack downloaded from.*does not match expected hash" err
+ test_grep "pack downloaded from.*does not match expected hash" err
+'
+
+test_expect_success 'packfile-uri with transfer.fsckobjects' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ configure_exclusion "$P" my-blob >h &&
+
+ sane_unset GIT_TEST_SIDEBAND_ALL &&
+ git -c protocol.version=2 -c transfer.fsckobjects=1 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ # Ensure that there are exactly 2 packfiles with associated .idx
+ ls http_child/.git/objects/pack/*.pack \
+ http_child/.git/objects/pack/*.idx >filelist &&
+ test_line_count = 4 filelist
+'
+
+test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ cat >bogus-commit <<-EOF &&
+ tree $EMPTY_TREE
+ author Bugs Bunny 1234567890 +0000
+ committer Bugs Bunny <bugs@bun.ni> 1234567890 +0000
+
+ This commit object intentionally broken
+ EOF
+ BOGUS=$(git -C "$P" hash-object -t commit -w --stdin --literally <bogus-commit) &&
+ git -C "$P" branch bogus-branch "$BOGUS" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ configure_exclusion "$P" my-blob >h &&
+
+ sane_unset GIT_TEST_SIDEBAND_ALL &&
+ test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child 2>error &&
+ test_grep "invalid author/committer line - missing email" error
+'
+
+test_expect_success 'packfile-uri with transfer.fsckobjects succeeds when .gitmodules is separate from tree' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo "[submodule libfoo]" >"$P/.gitmodules" &&
+ echo "path = include/foo" >>"$P/.gitmodules" &&
+ echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" &&
+ git -C "$P" add .gitmodules &&
+ git -C "$P" commit -m x &&
+
+ configure_exclusion "$P" .gitmodules >h &&
+
+ sane_unset GIT_TEST_SIDEBAND_ALL &&
+ git -c protocol.version=2 -c transfer.fsckobjects=1 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ # Ensure that there are exactly 2 packfiles with associated .idx
+ ls http_child/.git/objects/pack/*.pack \
+ http_child/.git/objects/pack/*.idx >filelist &&
+ test_line_count = 4 filelist
+'
+
+test_expect_success 'packfile-uri with transfer.fsckobjects fails when .gitmodules separate from tree is invalid' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child err &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo "[submodule \"..\"]" >"$P/.gitmodules" &&
+ echo "path = include/foo" >>"$P/.gitmodules" &&
+ echo "url = git://example.com/git/lib.git" >>"$P/.gitmodules" &&
+ git -C "$P" add .gitmodules &&
+ git -C "$P" commit -m x &&
+
+ configure_exclusion "$P" .gitmodules >h &&
+
+ sane_unset GIT_TEST_SIDEBAND_ALL &&
+ test_must_fail git -c protocol.version=2 -c transfer.fsckobjects=1 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child 2>err &&
+ test_grep "disallowed submodule name" err
+'
+
+test_expect_success 'packfile-uri path redacted in trace' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ git -C "$P" hash-object my-blob >objh &&
+ git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+ git -C "$P" config --add \
+ "uploadpack.blobpackfileuri" \
+ "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ git -c protocol.version=2 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ grep -F "clone< \\1$(cat packh) $HTTPD_URL/<redacted>" log
+'
+
+test_expect_success 'packfile-uri path not redacted in trace when GIT_TRACE_REDACT=0' '
+ P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+ rm -rf "$P" http_child log &&
+
+ git init "$P" &&
+ git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+ echo my-blob >"$P/my-blob" &&
+ git -C "$P" add my-blob &&
+ git -C "$P" commit -m x &&
+
+ git -C "$P" hash-object my-blob >objh &&
+ git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh &&
+ git -C "$P" config --add \
+ "uploadpack.blobpackfileuri" \
+ "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" &&
+
+ GIT_TRACE_PACKET="$(pwd)/log" \
+ GIT_TRACE_REDACT=0 \
+ git -c protocol.version=2 \
+ -c fetch.uriprotocols=http,https \
+ clone "$HTTPD_URL/smart/http_parent" http_child &&
+
+ grep -F "clone< \\1$(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" log
+'
+
+test_expect_success 'http:// --negotiate-only' '
+ SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+ URI="$HTTPD_URL/smart/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ git -c protocol.version=2 -C client fetch \
+ --no-tags \
+ --negotiate-only \
+ --negotiation-tip=$(git -C client rev-parse HEAD) \
+ origin >out &&
+ COMMON=$(git -C "$SERVER" rev-parse two) &&
+ grep "$COMMON" out
+'
+
+test_expect_success 'http:// --negotiate-only without wait-for-done support' '
+ SERVER="server" &&
+ URI="$HTTPD_URL/one_time_perl/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ echo "s/ wait-for-done/ xxxx-xxx-xxxx/" \
+ >"$HTTPD_ROOT_PATH/one-time-perl" &&
+
+ test_must_fail git -c protocol.version=2 -C client fetch \
+ --no-tags \
+ --negotiate-only \
+ --negotiation-tip=$(git -C client rev-parse HEAD) \
+ origin 2>err &&
+ test_grep "server does not support wait-for-done" err
+'
+
+test_expect_success 'http:// --negotiate-only with protocol v0' '
+ SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
+ URI="$HTTPD_URL/smart/server" &&
+
+ setup_negotiate_only "$SERVER" "$URI" &&
+
+ test_must_fail git -c protocol.version=0 -C client fetch \
+ --no-tags \
+ --negotiate-only \
+ --negotiation-tip=$(git -C client rev-parse HEAD) \
+ origin 2>err &&
+ test_grep "negotiate-only requires protocol v2" err
'
# DO NOT add non-httpd-specific tests here, because the last part of this