2015-01-08 03:23:24 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='pushing to a repository using the atomic push option'
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2015-01-08 03:23:24 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
mk_repo_pair () {
|
|
|
|
rm -rf workbench upstream &&
|
|
|
|
test_create_repo upstream &&
|
|
|
|
test_create_repo workbench &&
|
|
|
|
(
|
|
|
|
cd upstream &&
|
|
|
|
git config receive.denyCurrentBranch warn
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
git remote add up ../upstream
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Compare the ref ($1) in upstream with a ref value from workbench ($2)
|
|
|
|
# i.e. test_refs second HEAD@{2}
|
|
|
|
test_refs () {
|
|
|
|
test $# = 2 &&
|
|
|
|
git -C upstream rev-parse --verify "$1" >expect &&
|
|
|
|
git -C workbench rev-parse --verify "$2" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
}
|
|
|
|
|
2020-04-17 09:45:33 +00:00
|
|
|
fmt_status_report () {
|
|
|
|
sed -n \
|
|
|
|
-e "/^To / { s/ */ /g; p; }" \
|
|
|
|
-e "/^ ! / { s/ */ /g; p; }"
|
|
|
|
}
|
|
|
|
|
2015-01-08 03:23:24 +00:00
|
|
|
test_expect_success 'atomic push works for a single branch' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git push --atomic up main
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main main
|
2015-01-08 03:23:24 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push works for two branches' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git branch second &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
|
|
|
git checkout second &&
|
|
|
|
test_commit three &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git push --atomic up main second
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second second
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push works in combination with --mirror' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git checkout -b second &&
|
|
|
|
test_commit two &&
|
|
|
|
git push --atomic --mirror up
|
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second second
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push works in combination with --force' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git branch second main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit two_a &&
|
|
|
|
git checkout second &&
|
|
|
|
test_commit two_b &&
|
|
|
|
test_commit three_b &&
|
|
|
|
test_commit four &&
|
|
|
|
git push --mirror up &&
|
|
|
|
# The actual test is below
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit three_a &&
|
|
|
|
git checkout second &&
|
|
|
|
git reset --hard HEAD^ &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git push --force --atomic up main second
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second second
|
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
# set up two branches where main can be pushed but second can not
|
2015-01-08 03:23:24 +00:00
|
|
|
# (non-fast-forward). Since second can not be pushed the whole operation
|
2020-11-18 23:44:34 +00:00
|
|
|
# will fail and leave main untouched.
|
2015-01-08 03:23:24 +00:00
|
|
|
test_expect_success 'atomic push fails if one branch fails' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout -b second main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit two &&
|
|
|
|
test_commit three &&
|
|
|
|
test_commit four &&
|
|
|
|
git push --mirror up &&
|
|
|
|
git reset --hard HEAD~2 &&
|
|
|
|
test_commit five &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit six &&
|
|
|
|
test_must_fail git push --atomic --all up
|
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main HEAD@{7} &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second HEAD@{4}
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push fails if one tag fails remotely' '
|
|
|
|
# prepare the repo
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout -b second main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit two &&
|
|
|
|
git push --mirror up
|
|
|
|
) &&
|
|
|
|
# a third party modifies the server side:
|
|
|
|
(
|
|
|
|
cd upstream &&
|
|
|
|
git checkout second &&
|
|
|
|
git tag test_tag second
|
|
|
|
) &&
|
|
|
|
# see if we can now push both branches.
|
|
|
|
(
|
|
|
|
cd workbench &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit three &&
|
|
|
|
git checkout second &&
|
|
|
|
test_commit four &&
|
|
|
|
git tag test_tag &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_must_fail git push --tags --atomic up main second
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main HEAD@{3} &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second HEAD@{1}
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push obeys update hook preventing a branch to be pushed' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout -b second main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit two &&
|
|
|
|
git push --mirror up
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd upstream &&
|
|
|
|
HOOKDIR="$(git rev-parse --git-dir)/hooks" &&
|
|
|
|
HOOK="$HOOKDIR/update" &&
|
|
|
|
mkdir -p "$HOOKDIR" &&
|
|
|
|
write_script "$HOOK" <<-\EOF
|
2020-11-18 23:44:34 +00:00
|
|
|
# only allow update to main from now on
|
|
|
|
test "$1" = "refs/heads/main"
|
2015-01-08 03:23:24 +00:00
|
|
|
EOF
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git checkout main &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_commit three &&
|
|
|
|
git checkout second &&
|
|
|
|
test_commit four &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_must_fail git push --atomic up main second
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main HEAD@{3} &&
|
2015-01-08 03:23:24 +00:00
|
|
|
test_refs second HEAD@{1}
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'atomic push is not advertised if configured' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
2018-07-02 00:24:01 +00:00
|
|
|
cd upstream &&
|
2015-01-08 03:23:24 +00:00
|
|
|
git config receive.advertiseatomic 0
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_must_fail git push --atomic up main
|
2015-01-08 03:23:24 +00:00
|
|
|
) &&
|
2020-11-18 23:44:34 +00:00
|
|
|
test_refs main HEAD@{1}
|
2015-01-08 03:23:24 +00:00
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
# References in upstream : main(1) one(1) foo(1)
|
|
|
|
# References in workbench: main(2) foo(1) two(2) bar(2)
|
|
|
|
# Atomic push : main(2) two(2) bar(2)
|
2020-04-17 09:45:34 +00:00
|
|
|
test_expect_success 'atomic push reports (reject by update hook)' '
|
2020-04-17 09:45:33 +00:00
|
|
|
mk_repo_pair &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git branch foo &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git push up main one foo &&
|
2020-04-17 09:45:33 +00:00
|
|
|
git tag -d one
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
mkdir -p upstream/.git/hooks &&
|
|
|
|
cat >upstream/.git/hooks/update <<-EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
if test "\$1" = "refs/heads/bar"
|
|
|
|
then
|
|
|
|
echo >&2 "Pusing to branch bar is prohibited"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
EOF
|
|
|
|
chmod a+x upstream/.git/hooks/update
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit two &&
|
|
|
|
git branch bar
|
|
|
|
) &&
|
|
|
|
test_must_fail git -C workbench \
|
2020-11-18 23:44:34 +00:00
|
|
|
push --atomic up main two bar >out 2>&1 &&
|
2020-04-17 09:45:33 +00:00
|
|
|
fmt_status_report <out >actual &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
To ../upstream
|
2020-11-18 23:44:34 +00:00
|
|
|
! [remote rejected] main -> main (atomic push failure)
|
2020-04-17 09:45:33 +00:00
|
|
|
! [remote rejected] two -> two (atomic push failure)
|
|
|
|
! [remote rejected] bar -> bar (hook declined)
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
# References in upstream : main(1) one(1) foo(1)
|
|
|
|
# References in workbench: main(2) foo(1) two(2) bar(2)
|
2020-04-17 09:45:34 +00:00
|
|
|
test_expect_success 'atomic push reports (mirror, but reject by update hook)' '
|
2020-04-17 09:45:33 +00:00
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
git remote remove up &&
|
|
|
|
git remote add up ../upstream
|
|
|
|
) &&
|
|
|
|
test_must_fail git -C workbench \
|
|
|
|
push --atomic --mirror up >out 2>&1 &&
|
|
|
|
fmt_status_report <out >actual &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
To ../upstream
|
2020-11-18 23:44:34 +00:00
|
|
|
! [remote rejected] main -> main (atomic push failure)
|
2020-04-17 09:45:33 +00:00
|
|
|
! [remote rejected] one (atomic push failure)
|
|
|
|
! [remote rejected] bar -> bar (hook declined)
|
|
|
|
! [remote rejected] two -> two (atomic push failure)
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:34 +00:00
|
|
|
# References in upstream : main(2) one(1) foo(1)
|
|
|
|
# References in workbench: main(1) foo(1) two(2) bar(2)
|
2020-04-17 09:45:34 +00:00
|
|
|
test_expect_success 'atomic push reports (reject by non-ff)' '
|
2020-04-17 09:45:33 +00:00
|
|
|
rm upstream/.git/hooks/update &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
2020-11-18 23:44:34 +00:00
|
|
|
git push up main &&
|
2020-04-17 09:45:33 +00:00
|
|
|
git reset --hard HEAD^
|
|
|
|
) &&
|
|
|
|
test_must_fail git -C workbench \
|
2020-11-18 23:44:34 +00:00
|
|
|
push --atomic up main foo bar >out 2>&1 &&
|
2020-04-17 09:45:33 +00:00
|
|
|
fmt_status_report <out >actual &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
To ../upstream
|
2020-11-18 23:44:34 +00:00
|
|
|
! [rejected] main -> main (non-fast-forward)
|
2020-04-17 09:45:33 +00:00
|
|
|
! [rejected] bar -> bar (atomic push failed)
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2015-01-08 03:23:24 +00:00
|
|
|
test_done
|