Merge branch 'jt/push-negotiation-fixes' into maint
Bugfix for common ancestor negotiation recently introduced in "git push" codepath. * jt/push-negotiation-fixes: fetch: die on invalid --negotiation-tip hash send-pack: fix push nego. when remote has refs send-pack: fix push.negotiate with remote helper
This commit is contained in:
commit
6d71443d8e
@ -1428,7 +1428,9 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
|
||||
if (!has_glob_specials(s)) {
|
||||
struct object_id oid;
|
||||
if (get_oid(s, &oid))
|
||||
die("%s is not a valid object", s);
|
||||
die(_("%s is not a valid object"), s);
|
||||
if (!has_object(the_repository, &oid, 0))
|
||||
die(_("the object %s does not exist"), s);
|
||||
oid_array_append(oids, &oid);
|
||||
continue;
|
||||
}
|
||||
|
@ -230,6 +230,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
|
||||
args.atomic = atomic;
|
||||
args.stateless_rpc = stateless_rpc;
|
||||
args.push_options = push_options.nr ? &push_options : NULL;
|
||||
args.url = dest;
|
||||
|
||||
if (from_stdin) {
|
||||
if (args.stateless_rpc) {
|
||||
|
@ -425,8 +425,10 @@ static void get_commons_through_negotiation(const char *url,
|
||||
child.no_stdin = 1;
|
||||
child.out = -1;
|
||||
strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
|
||||
for (ref = remote_refs; ref; ref = ref->next)
|
||||
strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
|
||||
for (ref = remote_refs; ref; ref = ref->next) {
|
||||
if (!is_null_oid(&ref->new_oid))
|
||||
strvec_pushf(&child.args, "--negotiation-tip=%s", oid_to_hex(&ref->new_oid));
|
||||
}
|
||||
strvec_push(&child.args, url);
|
||||
|
||||
if (start_command(&child))
|
||||
|
@ -1214,6 +1214,19 @@ test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
|
||||
check_negotiation_tip
|
||||
'
|
||||
|
||||
test_expect_success '--negotiation-tip rejects missing OIDs' '
|
||||
setup_negotiation_tip server server 0 &&
|
||||
test_must_fail git -C client fetch \
|
||||
--negotiation-tip=alpha_1 \
|
||||
--negotiation-tip=$(test_oid zero) \
|
||||
origin alpha_s beta_s 2>err &&
|
||||
cat >fatal-expect <<-EOF &&
|
||||
fatal: the object $(test_oid zero) does not exist
|
||||
EOF
|
||||
grep fatal: err >fatal-actual &&
|
||||
test_cmp fatal-expect fatal-actual
|
||||
'
|
||||
|
||||
. "$TEST_DIRECTORY"/lib-httpd.sh
|
||||
start_httpd
|
||||
|
||||
|
@ -201,6 +201,7 @@ test_expect_success 'push with negotiation' '
|
||||
# Without negotiation
|
||||
mk_empty testrepo &&
|
||||
git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
|
||||
test_commit -C testrepo unrelated_commit &&
|
||||
git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
|
||||
echo now pushing without negotiation &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main &&
|
||||
@ -210,6 +211,7 @@ test_expect_success 'push with negotiation' '
|
||||
rm event &&
|
||||
mk_empty testrepo &&
|
||||
git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
|
||||
test_commit -C testrepo unrelated_commit &&
|
||||
git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
|
||||
grep_wrote 2 event # 1 commit, 1 tree
|
||||
@ -219,6 +221,7 @@ test_expect_success 'push with negotiation proceeds anyway even if negotiation f
|
||||
rm event &&
|
||||
mk_empty testrepo &&
|
||||
git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
|
||||
test_commit -C testrepo unrelated_commit &&
|
||||
git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
|
||||
GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \
|
||||
git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
|
||||
@ -1767,5 +1770,4 @@ test_expect_success 'denyCurrentBranch and worktrees' '
|
||||
git -C cloned push origin HEAD:new-wt &&
|
||||
test_must_fail git -C cloned push --delete origin new-wt
|
||||
'
|
||||
|
||||
test_done
|
||||
|
72
t/t5549-fetch-push-http.sh
Executable file
72
t/t5549-fetch-push-http.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='fetch/push functionality using the HTTP protocol'
|
||||
|
||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
. ./test-lib.sh
|
||||
. "$TEST_DIRECTORY"/lib-httpd.sh
|
||||
start_httpd
|
||||
|
||||
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server"
|
||||
URI="$HTTPD_URL/smart/server"
|
||||
|
||||
grep_wrote () {
|
||||
object_count=$1
|
||||
file_name=$2
|
||||
grep 'write_pack_file/wrote.*"value":"'$1'"' $2
|
||||
}
|
||||
|
||||
setup_client_and_server () {
|
||||
git init client &&
|
||||
test_when_finished 'rm -rf client' &&
|
||||
test_commit -C client first_commit &&
|
||||
test_commit -C client second_commit &&
|
||||
|
||||
git init "$SERVER" &&
|
||||
test_when_finished 'rm -rf "$SERVER"' &&
|
||||
test_config -C "$SERVER" http.receivepack true &&
|
||||
test_commit -C "$SERVER" unrelated_commit &&
|
||||
git -C client push "$URI" first_commit:refs/remotes/origin/first_commit &&
|
||||
git -C "$SERVER" config receive.hideRefs refs/remotes/origin/first_commit
|
||||
}
|
||||
|
||||
test_expect_success 'push without negotiation (for comparing object counts with the next test)' '
|
||||
setup_client_and_server &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 \
|
||||
push "$URI" refs/heads/main:refs/remotes/origin/main &&
|
||||
test_when_finished "rm -f event" &&
|
||||
grep_wrote 6 event # 2 commits, 2 trees, 2 blobs
|
||||
'
|
||||
|
||||
test_expect_success 'push with negotiation' '
|
||||
setup_client_and_server &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c protocol.version=2 -c push.negotiate=1 \
|
||||
push "$URI" refs/heads/main:refs/remotes/origin/main &&
|
||||
test_when_finished "rm -f event" &&
|
||||
grep_wrote 3 event # 1 commit, 1 tree, 1 blob
|
||||
'
|
||||
|
||||
test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' '
|
||||
setup_client_and_server &&
|
||||
|
||||
# Use protocol v0 to make negotiation fail (because protocol v0 does
|
||||
# not support the "wait-for-done" capability, which is required for
|
||||
# push negotiation)
|
||||
GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" git -C client -c push.negotiate=1 \
|
||||
push "$URI" refs/heads/main:refs/remotes/origin/main 2>err &&
|
||||
test_when_finished "rm -f event" &&
|
||||
grep_wrote 6 event && # 2 commits, 2 trees, 2 blobs
|
||||
|
||||
cat >warning-expect <<-EOF &&
|
||||
warning: --negotiate-only requires protocol v2
|
||||
warning: push negotiation failed; proceeding anyway with push
|
||||
EOF
|
||||
grep warning: err >warning-actual &&
|
||||
test_cmp warning-expect warning-actual
|
||||
'
|
||||
|
||||
test_done
|
Loading…
Reference in New Issue
Block a user