2009-08-14 03:41:14 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2017-05-23 03:01:14 +08:00
|
|
|
test_description='test push with submodules'
|
2009-08-14 03:41:14 +08:00
|
|
|
|
2020-11-19 07:44:33 +08: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-19 07:44:19 +08:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2021-10-09 05:08:19 +08:00
|
|
|
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
|
|
|
|
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
|
|
|
|
|
2009-08-14 03:41:14 +08:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
mkdir pub.git &&
|
2010-10-31 09:46:54 +08:00
|
|
|
GIT_DIR=pub.git git init --bare &&
|
2009-08-14 03:41:14 +08:00
|
|
|
GIT_DIR=pub.git git config receive.fsckobjects true &&
|
|
|
|
mkdir work &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git init &&
|
2014-01-08 18:47:56 +08:00
|
|
|
git config push.default matching &&
|
2009-08-14 03:41:14 +08:00
|
|
|
mkdir -p gar/bage &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
|
|
|
git init &&
|
2013-01-05 08:17:10 +08:00
|
|
|
git config push.default matching &&
|
2009-08-14 03:41:14 +08:00
|
|
|
>junk &&
|
|
|
|
git add junk &&
|
|
|
|
git commit -m "Initial junk"
|
|
|
|
) &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Initial superproject"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-05-23 03:01:14 +08:00
|
|
|
test_expect_success 'push works with recorded gitlink' '
|
2009-08-14 03:41:14 +08:00
|
|
|
(
|
|
|
|
cd work &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push ../pub.git main
|
2009-08-14 03:41:14 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-08-20 06:08:47 +08:00
|
|
|
test_expect_success 'push if submodule has no remote' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>junk2 &&
|
|
|
|
git add junk2 &&
|
|
|
|
git commit -m "Second junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Second commit for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=check ../pub.git main
|
2011-08-20 06:08:47 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push fails if submodule commit not on remote' '
|
|
|
|
(
|
|
|
|
cd work/gar &&
|
|
|
|
git clone --bare bage ../../submodule.git &&
|
|
|
|
cd bage &&
|
|
|
|
git remote add origin ../../../submodule.git &&
|
|
|
|
git fetch &&
|
|
|
|
>junk3 &&
|
|
|
|
git add junk3 &&
|
|
|
|
git commit -m "Third junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Third commit for gar/bage" &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# the push should fail with --recurse-submodules=check
|
|
|
|
# on the command line...
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git push --recurse-submodules=check ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
|
|
|
|
# ...or if specified in the configuration..
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git -c push.recurseSubmodules=check push ../pub.git main
|
2011-08-20 06:08:47 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds after commit was pushed to remote' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push origin main
|
2011-08-20 06:08:47 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=check ../pub.git main
|
2011-08-20 06:08:47 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-11-17 19:05:56 +08:00
|
|
|
test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-on-demand-on-command-line &&
|
|
|
|
git add recurse-on-demand-on-command-line &&
|
|
|
|
git commit -m "Recurse on-demand on command line junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse on-demand on command line for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the submodule commit got there too
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet origin/main main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-on-demand-from-config &&
|
|
|
|
git add recurse-on-demand-from-config &&
|
|
|
|
git commit -m "Recurse on-demand from config junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse on-demand from config for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=on-demand push ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the submodule commit got there too
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet origin/main main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-06-01 08:30:49 +08:00
|
|
|
test_expect_success 'push succeeds if submodule commit not on remote but using auto-on-demand via submodule.recurse config' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-on-demand-from-submodule-recurse-config &&
|
|
|
|
git add recurse-on-demand-from-submodule-recurse-config &&
|
|
|
|
git commit -m "Recurse submodule.recurse from config junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse submodule.recurse from config for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c submodule.recurse push ../pub.git main &&
|
2017-06-01 08:30:49 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2017-06-01 08:30:49 +08:00
|
|
|
# Check that the submodule commit got there too
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet origin/main main
|
2017-06-01 08:30:49 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2015-12-03 21:10:34 +08:00
|
|
|
test_expect_success 'push recurse-submodules on command line overrides config' '
|
2015-11-17 19:05:56 +08:00
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-check-on-command-line-overriding-config &&
|
|
|
|
git add recurse-check-on-command-line-overriding-config &&
|
2015-12-03 21:10:34 +08:00
|
|
|
git commit -m "Recurse on command-line overriding config junk"
|
2015-11-17 19:05:56 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse on command-line overriding config for gar/bage" &&
|
2015-12-03 21:10:34 +08:00
|
|
|
|
|
|
|
# Ensure that we can override on-demand in the config
|
|
|
|
# to just check submodules
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git -c push.recurseSubmodules=on-demand push --recurse-submodules=check ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit did not get there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main^ &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the submodule commit did not get there
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:34 +08:00
|
|
|
|
|
|
|
# Ensure that we can override check in the config to
|
|
|
|
# disable submodule recursion entirely
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
|
|
|
git -c push.recurseSubmodules=on-demand push --recurse-submodules=no ../pub.git main &&
|
2015-12-03 21:10:34 +08:00
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:34 +08:00
|
|
|
|
|
|
|
# Ensure that we can override check in the config to
|
|
|
|
# disable submodule recursion entirely (alternative form)
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=on-demand push --no-recurse-submodules ../pub.git main &&
|
2015-12-03 21:10:34 +08:00
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:34 +08:00
|
|
|
|
|
|
|
# Ensure that we can override check in the config to
|
|
|
|
# push the submodule too
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git main &&
|
2015-12-03 21:10:34 +08:00
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
|
|
|
(cd gar/bage && git diff --quiet origin/main main)
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
2015-12-03 21:10:35 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push recurse-submodules last one wins on command line' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-check-on-command-line-overriding-earlier-command-line &&
|
|
|
|
git add recurse-check-on-command-line-overriding-earlier-command-line &&
|
|
|
|
git commit -m "Recurse on command-line overridiing earlier command-line junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse on command-line overriding earlier command-line for gar/bage" &&
|
|
|
|
|
|
|
|
# should result in "check"
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git push --recurse-submodules=on-demand --recurse-submodules=check ../pub.git main &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the supermodule commit did not get there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main^ &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the submodule commit did not get there
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:35 +08:00
|
|
|
|
|
|
|
# should result in "no"
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand --recurse-submodules=no ../pub.git main &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the supermodule commit did get there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the submodule commit did not get there
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:35 +08:00
|
|
|
|
|
|
|
# should result in "no"
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand --no-recurse-submodules ../pub.git main &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the submodule commit did not get there
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main^) &&
|
2015-12-03 21:10:35 +08:00
|
|
|
|
|
|
|
# But the options in the other order should push the submodule
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=check --recurse-submodules=on-demand ../pub.git main &&
|
2015-12-03 21:10:35 +08:00
|
|
|
# Check that the submodule commit did get there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
(cd gar/bage && git diff --quiet origin/main main)
|
2015-12-03 21:10:35 +08:00
|
|
|
)
|
2015-11-17 19:05:56 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-on-demand-on-command-line-overriding-config &&
|
|
|
|
git add recurse-on-demand-on-command-line-overriding-config &&
|
|
|
|
git commit -m "Recurse on-demand on command-line overriding config junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse on-demand on command-line overriding config for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the submodule commit got there
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet origin/main main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-disable-on-command-line-overriding-config &&
|
|
|
|
git add recurse-disable-on-command-line-overriding-config &&
|
|
|
|
git commit -m "Recurse disable on command-line overriding config junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse disable on command-line overriding config for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=check push --recurse-submodules=no ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# But that the submodule commit did not
|
2020-11-19 07:44:33 +08:00
|
|
|
( cd gar/bage && git diff --quiet origin/main main^ ) &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Now push it to avoid confusing future tests
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-disable-on-command-line-alt-overriding-config &&
|
|
|
|
git add recurse-disable-on-command-line-alt-overriding-config &&
|
|
|
|
git commit -m "Recurse disable on command-line alternative overriding config junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse disable on command-line alternative overriding config for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -c push.recurseSubmodules=check push --no-recurse-submodules ../pub.git main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Check that the supermodule commit got there
|
|
|
|
git fetch ../pub.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git diff --quiet FETCH_HEAD main &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# But that the submodule commit did not
|
2020-11-19 07:44:33 +08:00
|
|
|
( cd gar/bage && git diff --quiet origin/main main^ ) &&
|
2015-11-17 19:05:56 +08:00
|
|
|
# Now push it to avoid confusing future tests
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-09-13 01:30:27 +08:00
|
|
|
test_expect_success 'submodule entry pointing at a tag is error' '
|
|
|
|
git -C work/gar/bage tag -a test1 -m "tag" &&
|
|
|
|
tag=$(git -C work/gar/bage rev-parse test1^{tag}) &&
|
|
|
|
git -C work update-index --cacheinfo 160000 "$tag" gar/bage &&
|
|
|
|
git -C work commit -m "bad commit" &&
|
|
|
|
test_when_finished "git -C work reset --hard HEAD^" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git -C work push --recurse-submodules=on-demand ../pub.git main 2>err &&
|
2023-10-31 13:23:30 +08:00
|
|
|
test_grep "is a tag, not a commit" err
|
2017-09-13 01:30:27 +08:00
|
|
|
'
|
|
|
|
|
2015-11-17 19:05:56 +08:00
|
|
|
test_expect_success 'push fails if recurse submodules option passed as yes' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>recurse-push-fails-if-recurse-submodules-passed-as-yes &&
|
|
|
|
git add recurse-push-fails-if-recurse-submodules-passed-as-yes &&
|
|
|
|
git commit -m "Recurse push fails if recurse submodules option passed as yes"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Recurse push fails if recurse submodules option passed as yes for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git push --recurse-submodules=yes ../pub.git main &&
|
|
|
|
test_must_fail git -c push.recurseSubmodules=yes push ../pub.git main &&
|
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2015-11-17 19:05:56 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-08-20 06:08:47 +08:00
|
|
|
test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
|
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
|
|
|
>junk4 &&
|
|
|
|
git add junk4 &&
|
|
|
|
git commit -m "Fourth junk"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
git branch branch2 &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Fourth commit for gar/bage" &&
|
|
|
|
git checkout branch2 &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
|
|
|
git checkout HEAD~1
|
|
|
|
) &&
|
|
|
|
>junk1 &&
|
|
|
|
git add junk1 &&
|
|
|
|
git commit -m "First junk" &&
|
|
|
|
test_must_fail git push --recurse-submodules=check ../pub.git
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
|
2015-03-20 18:07:15 +08:00
|
|
|
git init --bare a &&
|
2011-08-20 06:08:47 +08:00
|
|
|
git clone a a1 &&
|
|
|
|
(
|
|
|
|
cd a1 &&
|
2018-07-02 08:24:01 +08:00
|
|
|
git init b &&
|
2011-08-20 06:08:47 +08:00
|
|
|
(
|
|
|
|
cd b &&
|
|
|
|
>junk &&
|
|
|
|
git add junk &&
|
|
|
|
git commit -m "initial"
|
|
|
|
) &&
|
|
|
|
git add b &&
|
|
|
|
git commit -m "added submodule" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=check origin main
|
2011-08-20 06:08:47 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-03-29 15:21:24 +08:00
|
|
|
test_expect_success 'push unpushed submodules when not needed' '
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
2012-03-29 15:21:24 +08:00
|
|
|
>junk5 &&
|
|
|
|
git add junk5 &&
|
|
|
|
git commit -m "Fifth junk" &&
|
|
|
|
git push &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse origin/main >../../../expected
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
2012-03-29 15:21:24 +08:00
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Fifth commit for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd submodule.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../actual
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push unpushed submodules when not needed 2' '
|
|
|
|
(
|
|
|
|
cd submodule.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../expected
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
|
|
|
>junk6 &&
|
|
|
|
git add junk6 &&
|
|
|
|
git commit -m "Sixth junk"
|
|
|
|
) &&
|
|
|
|
>junk2 &&
|
|
|
|
git add junk2 &&
|
|
|
|
git commit -m "Second junk for work" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd submodule.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../actual
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push unpushed submodules recursively' '
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
2012-03-29 15:21:24 +08:00
|
|
|
> junk7 &&
|
|
|
|
git add junk7 &&
|
|
|
|
git commit -m "Seventh junk" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../../../expected
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
2012-03-29 15:21:24 +08:00
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Seventh commit for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --recurse-submodules=on-demand ../pub.git main
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd submodule.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../actual
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push unpushable submodule recursively fails' '
|
|
|
|
(
|
|
|
|
cd work &&
|
|
|
|
(
|
|
|
|
cd gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse origin/main >../../../expected &&
|
|
|
|
git checkout main~0 &&
|
2012-03-29 15:21:24 +08:00
|
|
|
> junk8 &&
|
|
|
|
git add junk8 &&
|
|
|
|
git commit -m "Eighth junk"
|
|
|
|
) &&
|
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Eighth commit for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git push --recurse-submodules=on-demand ../pub.git main
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd submodule.git &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git rev-parse main >../actual
|
2012-03-29 15:21:24 +08:00
|
|
|
) &&
|
2020-11-19 07:44:33 +08:00
|
|
|
test_when_finished git -C work reset --hard main^ &&
|
2012-03-29 15:21:24 +08:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-11-18 02:46:04 +08:00
|
|
|
test_expect_success 'push --dry-run does not recursively update submodules' '
|
2016-11-18 02:46:03 +08:00
|
|
|
(
|
|
|
|
cd work/gar/bage &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
|
|
|
git rev-parse main >../../../expected_submodule &&
|
2016-11-18 02:46:03 +08:00
|
|
|
> junk9 &&
|
|
|
|
git add junk9 &&
|
|
|
|
git commit -m "Ninth junk" &&
|
|
|
|
|
|
|
|
# Go up to 'work' directory
|
|
|
|
cd ../.. &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git checkout main &&
|
|
|
|
git rev-parse main >../expected_pub &&
|
2016-11-18 02:46:03 +08:00
|
|
|
git add gar/bage &&
|
|
|
|
git commit -m "Ninth commit for gar/bage" &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git push --dry-run --recurse-submodules=on-demand ../pub.git main
|
2016-11-18 02:46:03 +08:00
|
|
|
) &&
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C submodule.git rev-parse main >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse main >actual_pub &&
|
2016-11-18 02:46:03 +08:00
|
|
|
test_cmp expected_pub actual_pub &&
|
|
|
|
test_cmp expected_submodule actual_submodule
|
|
|
|
'
|
|
|
|
|
2016-12-20 02:25:33 +08:00
|
|
|
test_expect_success 'push --dry-run does not recursively update submodules' '
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C work push --dry-run --recurse-submodules=only ../pub.git main &&
|
2016-12-20 02:25:33 +08:00
|
|
|
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C submodule.git rev-parse main >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse main >actual_pub &&
|
2016-12-20 02:25:33 +08:00
|
|
|
test_cmp expected_pub actual_pub &&
|
|
|
|
test_cmp expected_submodule actual_submodule
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push only unpushed submodules recursively' '
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C work/gar/bage rev-parse main >expected_submodule &&
|
|
|
|
git -C pub.git rev-parse main >expected_pub &&
|
2016-12-20 02:25:33 +08:00
|
|
|
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C work push --recurse-submodules=only ../pub.git main &&
|
2016-12-20 02:25:33 +08:00
|
|
|
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C submodule.git rev-parse main >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse main >actual_pub &&
|
2016-12-20 02:25:33 +08:00
|
|
|
test_cmp expected_submodule actual_submodule &&
|
|
|
|
test_cmp expected_pub actual_pub
|
|
|
|
'
|
|
|
|
|
Doc: document push.recurseSubmodules=only
Git learned pushing submodules without pushing the superproject by
the user specifying --recurse-submodules=only through 6c656c3fe4
("submodules: add RECURSE_SUBMODULES_ONLY value", 2016-12-20) and
225e8bf778 ("push: add option to push only submodules", 2016-12-20).
For users who use this feature regularly, it is desirable to have an
equivalent configuration.
It turns out that such a configuration (push.recurseSubmodules=only) is
already supported, even though it is neither documented nor mentioned
in the commit messages, due to the way the --recurse-submodules=only
feature was implemented (a function used to parse --recurse-submodules
was updated to support "only", but that same function is used to parse
push.recurseSubmodules too). What is left is to document it and test it,
which is what this commit does.
There is a possible point of confusion when recursing into a submodule
that itself has the push.recurseSubmodules=only configuration, because
if a repository has only its submodules pushed and not itself, its
superproject can never be pushed. Therefore, treat such configurations
as being "on-demand", and print a warning message.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-15 05:37:12 +08:00
|
|
|
setup_subsub () {
|
|
|
|
git init upstream &&
|
|
|
|
git init upstream/sub &&
|
|
|
|
git init upstream/sub/deepsub &&
|
|
|
|
test_commit -C upstream/sub/deepsub innermost &&
|
|
|
|
git -C upstream/sub submodule add ./deepsub deepsub &&
|
|
|
|
git -C upstream/sub commit -m middle &&
|
|
|
|
git -C upstream submodule add ./sub sub &&
|
|
|
|
git -C upstream commit -m outermost &&
|
|
|
|
|
|
|
|
git -c protocol.file.allow=always clone --recurse-submodules upstream downstream &&
|
|
|
|
git -C downstream/sub/deepsub checkout -b downstream-branch &&
|
|
|
|
git -C downstream/sub checkout -b downstream-branch &&
|
|
|
|
git -C downstream checkout -b downstream-branch
|
|
|
|
}
|
|
|
|
|
|
|
|
new_downstream_commits () {
|
|
|
|
test_commit -C downstream/sub/deepsub new-innermost &&
|
|
|
|
git -C downstream/sub add deepsub &&
|
|
|
|
git -C downstream/sub commit -m new-middle &&
|
|
|
|
git -C downstream add sub &&
|
|
|
|
git -C downstream commit -m new-outermost
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'push with push.recurseSubmodules=only on superproject' '
|
|
|
|
test_when_finished rm -rf upstream downstream &&
|
|
|
|
setup_subsub &&
|
|
|
|
new_downstream_commits &&
|
|
|
|
git -C downstream config push.recurseSubmodules only &&
|
|
|
|
git -C downstream push origin downstream-branch &&
|
|
|
|
|
|
|
|
test_must_fail git -C upstream rev-parse refs/heads/downstream-branch &&
|
|
|
|
git -C upstream/sub rev-parse refs/heads/downstream-branch &&
|
|
|
|
test_must_fail git -C upstream/sub/deepsub rev-parse refs/heads/downstream-branch
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push with push.recurseSubmodules=only on superproject and top-level submodule' '
|
|
|
|
test_when_finished rm -rf upstream downstream &&
|
|
|
|
setup_subsub &&
|
|
|
|
new_downstream_commits &&
|
|
|
|
git -C downstream config push.recurseSubmodules only &&
|
|
|
|
git -C downstream/sub config push.recurseSubmodules only &&
|
|
|
|
git -C downstream push origin downstream-branch 2> err &&
|
|
|
|
|
|
|
|
test_must_fail git -C upstream rev-parse refs/heads/downstream-branch &&
|
|
|
|
git -C upstream/sub rev-parse refs/heads/downstream-branch &&
|
|
|
|
git -C upstream/sub/deepsub rev-parse refs/heads/downstream-branch &&
|
|
|
|
grep "recursing into submodule with push.recurseSubmodules=only; using on-demand instead" err
|
|
|
|
'
|
|
|
|
|
2017-04-06 01:47:19 +08:00
|
|
|
test_expect_success 'push propagating the remotes name to a submodule' '
|
|
|
|
git -C work remote add origin ../pub.git &&
|
|
|
|
git -C work remote add pub ../pub.git &&
|
|
|
|
|
|
|
|
> work/gar/bage/junk10 &&
|
|
|
|
git -C work/gar/bage add junk10 &&
|
|
|
|
git -C work/gar/bage commit -m "Tenth junk" &&
|
|
|
|
git -C work add gar/bage &&
|
|
|
|
git -C work commit -m "Tenth junk added to gar/bage" &&
|
|
|
|
|
|
|
|
# Fails when submodule does not have a matching remote
|
2020-11-19 07:44:33 +08:00
|
|
|
test_must_fail git -C work push --recurse-submodules=on-demand pub main &&
|
2017-04-06 01:47:19 +08:00
|
|
|
# Succeeds when submodules has matching remote and refspec
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C work push --recurse-submodules=on-demand origin main &&
|
2017-04-06 01:47:19 +08:00
|
|
|
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C submodule.git rev-parse main >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse main >actual_pub &&
|
|
|
|
git -C work/gar/bage rev-parse main >expected_submodule &&
|
|
|
|
git -C work rev-parse main >expected_pub &&
|
2017-04-06 01:47:19 +08:00
|
|
|
test_cmp expected_submodule actual_submodule &&
|
|
|
|
test_cmp expected_pub actual_pub
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push propagating refspec to a submodule' '
|
|
|
|
> work/gar/bage/junk11 &&
|
|
|
|
git -C work/gar/bage add junk11 &&
|
|
|
|
git -C work/gar/bage commit -m "Eleventh junk" &&
|
|
|
|
|
|
|
|
git -C work checkout branch2 &&
|
|
|
|
git -C work add gar/bage &&
|
|
|
|
git -C work commit -m "updating gar/bage in branch2" &&
|
|
|
|
|
|
|
|
# Fails when submodule does not have a matching branch
|
|
|
|
test_must_fail git -C work push --recurse-submodules=on-demand origin branch2 &&
|
|
|
|
# Fails when refspec includes an object id
|
|
|
|
test_must_fail git -C work push --recurse-submodules=on-demand origin \
|
|
|
|
"$(git -C work rev-parse branch2):refs/heads/branch2" &&
|
2017-07-21 01:40:37 +08:00
|
|
|
# Fails when refspec includes HEAD and parent and submodule do not
|
|
|
|
# have the same named branch checked out
|
2017-04-06 01:47:19 +08:00
|
|
|
test_must_fail git -C work push --recurse-submodules=on-demand origin \
|
|
|
|
HEAD:refs/heads/branch2 &&
|
|
|
|
|
2020-11-19 07:44:33 +08:00
|
|
|
git -C work/gar/bage branch branch2 main &&
|
2017-04-06 01:47:19 +08:00
|
|
|
git -C work push --recurse-submodules=on-demand origin branch2 &&
|
|
|
|
|
|
|
|
git -C submodule.git rev-parse branch2 >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse branch2 >actual_pub &&
|
|
|
|
git -C work/gar/bage rev-parse branch2 >expected_submodule &&
|
|
|
|
git -C work rev-parse branch2 >expected_pub &&
|
|
|
|
test_cmp expected_submodule actual_submodule &&
|
|
|
|
test_cmp expected_pub actual_pub
|
|
|
|
'
|
|
|
|
|
2017-07-21 01:40:37 +08:00
|
|
|
test_expect_success 'push propagating HEAD refspec to a submodule' '
|
|
|
|
git -C work/gar/bage checkout branch2 &&
|
|
|
|
> work/gar/bage/junk12 &&
|
|
|
|
git -C work/gar/bage add junk12 &&
|
|
|
|
git -C work/gar/bage commit -m "Twelfth junk" &&
|
|
|
|
|
|
|
|
git -C work checkout branch2 &&
|
|
|
|
git -C work add gar/bage &&
|
|
|
|
git -C work commit -m "updating gar/bage in branch2" &&
|
|
|
|
|
|
|
|
# Passes since the superproject and submodules HEAD are both on branch2
|
|
|
|
git -C work push --recurse-submodules=on-demand origin \
|
|
|
|
HEAD:refs/heads/branch2 &&
|
|
|
|
|
|
|
|
git -C submodule.git rev-parse branch2 >actual_submodule &&
|
|
|
|
git -C pub.git rev-parse branch2 >actual_pub &&
|
|
|
|
git -C work/gar/bage rev-parse branch2 >expected_submodule &&
|
|
|
|
git -C work rev-parse branch2 >expected_pub &&
|
|
|
|
test_cmp expected_submodule actual_submodule &&
|
|
|
|
test_cmp expected_pub actual_pub
|
|
|
|
'
|
|
|
|
|
2009-08-14 03:41:14 +08:00
|
|
|
test_done
|