2009-04-23 23:06:38 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2009 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test updating submodules
|
|
|
|
|
|
|
|
This test verifies that "git submodule update" detaches the HEAD of the
|
2009-06-02 22:59:12 +00:00
|
|
|
submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
|
2009-04-23 23:06:38 +00:00
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:39 +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
|
|
|
|
|
2009-04-23 23:06:38 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
|
|
|
|
compare_head()
|
|
|
|
{
|
2020-11-18 23:44:39 +00:00
|
|
|
sha_main=$(git rev-list --max-count=1 main)
|
2016-01-08 11:06:20 +00:00
|
|
|
sha_head=$(git rev-list --max-count=1 HEAD)
|
2009-04-23 23:06:38 +00:00
|
|
|
|
2020-11-18 23:44:39 +00:00
|
|
|
test "$sha_main" = "$sha_head"
|
2009-04-23 23:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test_expect_success 'setup a submodule tree' '
|
2022-07-29 19:21:40 +00:00
|
|
|
git config --global protocol.file.allow always &&
|
2009-04-23 23:06:38 +00:00
|
|
|
echo file > file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
2010-09-01 21:28:27 +00:00
|
|
|
git commit -m upstream &&
|
2009-04-23 23:06:38 +00:00
|
|
|
git clone . super &&
|
|
|
|
git clone super submodule &&
|
2010-03-05 08:20:38 +00:00
|
|
|
git clone super rebasing &&
|
|
|
|
git clone super merging &&
|
2011-08-11 17:51:46 +00:00
|
|
|
git clone super none &&
|
2009-04-23 23:06:38 +00:00
|
|
|
(cd super &&
|
|
|
|
git submodule add ../submodule submodule &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "submodule" &&
|
|
|
|
git submodule init submodule
|
|
|
|
) &&
|
|
|
|
(cd submodule &&
|
|
|
|
echo "line2" > file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m "Commit 2"
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
git pull --rebase origin
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git commit -m "submodule update"
|
2010-03-05 08:20:38 +00:00
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
git submodule add ../rebasing rebasing &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "rebasing"
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
git submodule add ../merging merging &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "rebasing"
|
2013-09-15 17:38:21 +00:00
|
|
|
) &&
|
2011-08-11 17:51:46 +00:00
|
|
|
(cd super &&
|
|
|
|
git submodule add ../none none &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "none"
|
2016-03-30 01:27:42 +00:00
|
|
|
) &&
|
|
|
|
git clone . recursivesuper &&
|
2018-06-16 20:33:19 +00:00
|
|
|
( cd recursivesuper &&
|
2016-03-30 01:27:42 +00:00
|
|
|
git submodule add ../super super
|
2011-08-11 17:51:46 +00:00
|
|
|
)
|
2009-04-23 23:06:38 +00:00
|
|
|
'
|
|
|
|
|
2020-06-24 14:46:30 +00:00
|
|
|
test_expect_success 'update --remote falls back to using HEAD' '
|
|
|
|
test_create_repo main-branch-submodule &&
|
|
|
|
test_commit -C main-branch-submodule initial &&
|
|
|
|
|
|
|
|
test_create_repo main-branch &&
|
|
|
|
git -C main-branch submodule add ../main-branch-submodule &&
|
|
|
|
git -C main-branch commit -m add-submodule &&
|
|
|
|
|
|
|
|
git -C main-branch-submodule switch -c hello &&
|
|
|
|
test_commit -C main-branch-submodule world &&
|
|
|
|
|
|
|
|
git clone --recursive main-branch main-branch-clone &&
|
|
|
|
git -C main-branch-clone submodule update --remote main-branch-submodule &&
|
|
|
|
test_path_exists main-branch-clone/main-branch-submodule/world.t
|
|
|
|
'
|
|
|
|
|
2009-04-23 23:06:38 +00:00
|
|
|
test_expect_success 'submodule update detaching the HEAD ' '
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
cd submodule &&
|
2013-06-16 14:18:18 +00:00
|
|
|
! compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update from subdirectory' '
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
mkdir super/sub &&
|
|
|
|
(cd super/sub &&
|
|
|
|
(cd ../submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update ../submodule &&
|
|
|
|
cd ../submodule &&
|
2009-04-23 23:06:38 +00:00
|
|
|
! compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-03-30 01:27:42 +00:00
|
|
|
supersha1=$(git -C super rev-parse HEAD)
|
|
|
|
mergingsha1=$(git -C super/merging rev-parse HEAD)
|
|
|
|
nonesha1=$(git -C super/none rev-parse HEAD)
|
|
|
|
rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
|
|
|
|
submodulesha1=$(git -C super/submodule rev-parse HEAD)
|
|
|
|
pwd=$(pwd)
|
|
|
|
|
|
|
|
cat <<EOF >expect
|
|
|
|
Submodule path '../super': checked out '$supersha1'
|
|
|
|
Submodule path '../super/merging': checked out '$mergingsha1'
|
|
|
|
Submodule path '../super/none': checked out '$nonesha1'
|
|
|
|
Submodule path '../super/rebasing': checked out '$rebasingsha1'
|
|
|
|
Submodule path '../super/submodule': checked out '$submodulesha1'
|
|
|
|
EOF
|
|
|
|
|
2016-05-02 22:24:04 +00:00
|
|
|
cat <<EOF >expect2
|
2018-07-23 13:39:42 +00:00
|
|
|
Cloning into '$pwd/recursivesuper/super/merging'...
|
|
|
|
Cloning into '$pwd/recursivesuper/super/none'...
|
|
|
|
Cloning into '$pwd/recursivesuper/super/rebasing'...
|
|
|
|
Cloning into '$pwd/recursivesuper/super/submodule'...
|
2016-05-02 22:24:04 +00:00
|
|
|
Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
|
|
|
|
Submodule 'none' ($pwd/none) registered for path '../super/none'
|
|
|
|
Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
|
|
|
|
Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
|
|
|
|
done.
|
|
|
|
done.
|
|
|
|
done.
|
|
|
|
done.
|
|
|
|
EOF
|
|
|
|
|
2016-03-30 01:27:42 +00:00
|
|
|
test_expect_success 'submodule update --init --recursive from subdirectory' '
|
|
|
|
git -C recursivesuper/super reset --hard HEAD^ &&
|
|
|
|
(cd recursivesuper &&
|
|
|
|
mkdir tmp &&
|
|
|
|
cd tmp &&
|
2016-05-02 22:24:04 +00:00
|
|
|
git submodule update --init --recursive ../super >../../actual 2>../../actual2
|
2016-03-30 01:27:42 +00:00
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect actual &&
|
2018-07-23 13:39:42 +00:00
|
|
|
sort actual2 >actual2.sorted &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect2 actual2.sorted
|
2016-03-30 01:27:42 +00:00
|
|
|
'
|
|
|
|
|
2017-01-07 00:19:53 +00:00
|
|
|
cat <<EOF >expect2
|
|
|
|
Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'submodule update --init from and of subdirectory' '
|
|
|
|
git init withsubs &&
|
|
|
|
(cd withsubs &&
|
|
|
|
mkdir foo &&
|
|
|
|
git submodule add "$(pwd)/../rebasing" foo/sub &&
|
|
|
|
(cd foo &&
|
|
|
|
git submodule deinit -f sub &&
|
|
|
|
git submodule update --init sub 2>../../actual2
|
|
|
|
)
|
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect2 actual2
|
2017-01-07 00:19:53 +00:00
|
|
|
'
|
|
|
|
|
2011-03-06 22:13:36 +00:00
|
|
|
test_expect_success 'submodule update does not fetch already present commits' '
|
|
|
|
(cd submodule &&
|
|
|
|
echo line3 >> file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "upstream line3"
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
head=$(git rev-parse --verify HEAD) &&
|
2019-09-05 22:10:05 +00:00
|
|
|
echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected &&
|
2011-03-06 22:13:36 +00:00
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
git submodule update > ../actual 2> ../actual.err
|
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expected actual &&
|
2018-08-08 16:31:06 +00:00
|
|
|
test_must_be_empty actual.err
|
2011-03-06 22:13:36 +00:00
|
|
|
'
|
|
|
|
|
2011-04-01 09:42:03 +00:00
|
|
|
test_expect_success 'submodule update should fail due to local changes' '
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1 &&
|
|
|
|
echo "local change" > file
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
2022-03-05 00:13:49 +00:00
|
|
|
test_must_fail git submodule update submodule 2>../actual.raw
|
|
|
|
) &&
|
|
|
|
sed "s/^> //" >expect <<-\EOF &&
|
|
|
|
> error: Your local changes to the following files would be overwritten by checkout:
|
|
|
|
> file
|
|
|
|
> Please commit your changes or stash them before you switch branches.
|
|
|
|
> Aborting
|
|
|
|
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
|
|
|
|
EOF
|
|
|
|
sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
|
2011-04-01 09:42:03 +00:00
|
|
|
'
|
|
|
|
test_expect_success 'submodule update should throw away changes with --force ' '
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update --force submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
! compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-07-25 17:41:54 +00:00
|
|
|
test_expect_success 'submodule update --force forcibly checks out submodules' '
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
rm -f file
|
|
|
|
) &&
|
|
|
|
git submodule update --force submodule &&
|
|
|
|
(cd submodule &&
|
|
|
|
test "$(git status -s file)" = ""
|
|
|
|
)
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
submodule update: add --remote for submodule's upstream changes
The current `update` command incorporates the superproject's gitlinked
SHA-1 ($sha1) into the submodule HEAD ($subsha1). Depending on the
options you use, it may checkout $sha1, rebase the $subsha1 onto
$sha1, or merge $sha1 into $subsha1. This helps you keep up with
changes in the upstream superproject.
However, it's also useful to stay up to date with changes in the
upstream subproject. Previous workflows for incorporating such
changes include the ungainly:
$ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'
With this patch, all of the useful functionality for incorporating
superproject changes can be reused to incorporate upstream subproject
updates. When you specify --remote, the target $sha1 is replaced with
a $sha1 of the submodule's origin/master tracking branch. If you want
to merge a different tracking branch, you can configure the
`submodule.<name>.branch` option in `.gitmodules`. You can override
the `.gitmodules` configuration setting for a particular superproject
by configuring the option in that superproject's default configuration
(using the usual configuration hierarchy, e.g. `.git/config`,
`~/.gitconfig`, etc.).
Previous use of submodule.<name>.branch
=======================================
Because we're adding a new configuration option, it's a good idea to
check if anyone else is already using the option. The foreach-pull
example above was described by Ævar in
commit f030c96d8643fa0a1a9b2bd9c2f36a77721fb61f
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date: Fri May 21 16:10:10 2010 +0000
git-submodule foreach: Add $toplevel variable
Gerrit uses the same interpretation for the setting, but because
Gerrit has direct access to the subproject repositories, it updates
the superproject repositories automatically when a subproject changes.
Gerrit also accepts the special value '.', which it expands into the
superproject's branch name.
Although the --remote functionality is using `submodule.<name>.branch`
slightly differently, the effect is the same. The foreach-pull
example uses the option to record the name of the local branch to
checkout before pulls. The tracking branch to be pulled is recorded
in `.git/modules/<name>/config`, which was initialized by the module
clone during `submodule add` or `submodule init`. Because the branch
name stored in `submodule.<name>.branch` was likely the same as the
branch name used during the initial `submodule add`, the same branch
will be pulled in each workflow.
Implementation details
======================
In order to ensure a current tracking branch state, `update --remote`
fetches the submodule's remote repository before calculating the
SHA-1. However, I didn't change the logic guarding the existing fetch:
if test -z "$nofetch"
then
# Run fetch only if $sha1 isn't present or it
# is not reachable from a ref.
(clear_local_git_env; cd "$path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
fi
There will not be a double-fetch, because the new $sha1 determined
after the `--remote` triggered fetch should always exist in the
repository. If it doesn't, it's because some racy process removed it
from the submodule's repository and we *should* be re-fetching.
Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 16:03:32 +00:00
|
|
|
test_expect_success 'submodule update --remote should fetch upstream changes' '
|
|
|
|
(cd submodule &&
|
|
|
|
echo line4 >> file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "upstream line4"
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
git submodule update --remote --force submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-08-03 20:44:04 +00:00
|
|
|
test_expect_success 'submodule update --remote should fetch upstream changes with .' '
|
|
|
|
(
|
|
|
|
cd super &&
|
|
|
|
git config -f .gitmodules submodule."submodule".branch "." &&
|
|
|
|
git add .gitmodules &&
|
|
|
|
git commit -m "submodules: update from the respective superproject branch"
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd submodule &&
|
|
|
|
echo line4a >> file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "upstream line4a" &&
|
|
|
|
git checkout -b test-branch &&
|
|
|
|
test_commit on-test-branch
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd super &&
|
|
|
|
git submodule update --remote --force submodule &&
|
2018-06-16 20:33:19 +00:00
|
|
|
git -C submodule log -1 --oneline >actual &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git -C ../submodule log -1 --oneline main >expect &&
|
2016-08-03 20:44:04 +00:00
|
|
|
test_cmp expect actual &&
|
|
|
|
git checkout -b test-branch &&
|
|
|
|
git submodule update --remote --force submodule &&
|
2018-06-16 20:33:19 +00:00
|
|
|
git -C submodule log -1 --oneline >actual &&
|
|
|
|
git -C ../submodule log -1 --oneline test-branch >expect &&
|
2016-08-03 20:44:04 +00:00
|
|
|
test_cmp expect actual &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2016-08-03 20:44:04 +00:00
|
|
|
git branch -d test-branch &&
|
|
|
|
git reset --hard HEAD^
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
submodule update: add --remote for submodule's upstream changes
The current `update` command incorporates the superproject's gitlinked
SHA-1 ($sha1) into the submodule HEAD ($subsha1). Depending on the
options you use, it may checkout $sha1, rebase the $subsha1 onto
$sha1, or merge $sha1 into $subsha1. This helps you keep up with
changes in the upstream superproject.
However, it's also useful to stay up to date with changes in the
upstream subproject. Previous workflows for incorporating such
changes include the ungainly:
$ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'
With this patch, all of the useful functionality for incorporating
superproject changes can be reused to incorporate upstream subproject
updates. When you specify --remote, the target $sha1 is replaced with
a $sha1 of the submodule's origin/master tracking branch. If you want
to merge a different tracking branch, you can configure the
`submodule.<name>.branch` option in `.gitmodules`. You can override
the `.gitmodules` configuration setting for a particular superproject
by configuring the option in that superproject's default configuration
(using the usual configuration hierarchy, e.g. `.git/config`,
`~/.gitconfig`, etc.).
Previous use of submodule.<name>.branch
=======================================
Because we're adding a new configuration option, it's a good idea to
check if anyone else is already using the option. The foreach-pull
example above was described by Ævar in
commit f030c96d8643fa0a1a9b2bd9c2f36a77721fb61f
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date: Fri May 21 16:10:10 2010 +0000
git-submodule foreach: Add $toplevel variable
Gerrit uses the same interpretation for the setting, but because
Gerrit has direct access to the subproject repositories, it updates
the superproject repositories automatically when a subproject changes.
Gerrit also accepts the special value '.', which it expands into the
superproject's branch name.
Although the --remote functionality is using `submodule.<name>.branch`
slightly differently, the effect is the same. The foreach-pull
example uses the option to record the name of the local branch to
checkout before pulls. The tracking branch to be pulled is recorded
in `.git/modules/<name>/config`, which was initialized by the module
clone during `submodule add` or `submodule init`. Because the branch
name stored in `submodule.<name>.branch` was likely the same as the
branch name used during the initial `submodule add`, the same branch
will be pulled in each workflow.
Implementation details
======================
In order to ensure a current tracking branch state, `update --remote`
fetches the submodule's remote repository before calculating the
SHA-1. However, I didn't change the logic guarding the existing fetch:
if test -z "$nofetch"
then
# Run fetch only if $sha1 isn't present or it
# is not reachable from a ref.
(clear_local_git_env; cd "$path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
fi
There will not be a double-fetch, because the new $sha1 determined
after the `--remote` triggered fetch should always exist in the
repository. If it doesn't, it's because some racy process removed it
from the submodule's repository and we *should* be re-fetching.
Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 16:03:32 +00:00
|
|
|
test_expect_success 'local config should override .gitmodules branch' '
|
|
|
|
(cd submodule &&
|
2016-08-03 20:44:04 +00:00
|
|
|
git checkout test-branch &&
|
submodule update: add --remote for submodule's upstream changes
The current `update` command incorporates the superproject's gitlinked
SHA-1 ($sha1) into the submodule HEAD ($subsha1). Depending on the
options you use, it may checkout $sha1, rebase the $subsha1 onto
$sha1, or merge $sha1 into $subsha1. This helps you keep up with
changes in the upstream superproject.
However, it's also useful to stay up to date with changes in the
upstream subproject. Previous workflows for incorporating such
changes include the ungainly:
$ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'
With this patch, all of the useful functionality for incorporating
superproject changes can be reused to incorporate upstream subproject
updates. When you specify --remote, the target $sha1 is replaced with
a $sha1 of the submodule's origin/master tracking branch. If you want
to merge a different tracking branch, you can configure the
`submodule.<name>.branch` option in `.gitmodules`. You can override
the `.gitmodules` configuration setting for a particular superproject
by configuring the option in that superproject's default configuration
(using the usual configuration hierarchy, e.g. `.git/config`,
`~/.gitconfig`, etc.).
Previous use of submodule.<name>.branch
=======================================
Because we're adding a new configuration option, it's a good idea to
check if anyone else is already using the option. The foreach-pull
example above was described by Ævar in
commit f030c96d8643fa0a1a9b2bd9c2f36a77721fb61f
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date: Fri May 21 16:10:10 2010 +0000
git-submodule foreach: Add $toplevel variable
Gerrit uses the same interpretation for the setting, but because
Gerrit has direct access to the subproject repositories, it updates
the superproject repositories automatically when a subproject changes.
Gerrit also accepts the special value '.', which it expands into the
superproject's branch name.
Although the --remote functionality is using `submodule.<name>.branch`
slightly differently, the effect is the same. The foreach-pull
example uses the option to record the name of the local branch to
checkout before pulls. The tracking branch to be pulled is recorded
in `.git/modules/<name>/config`, which was initialized by the module
clone during `submodule add` or `submodule init`. Because the branch
name stored in `submodule.<name>.branch` was likely the same as the
branch name used during the initial `submodule add`, the same branch
will be pulled in each workflow.
Implementation details
======================
In order to ensure a current tracking branch state, `update --remote`
fetches the submodule's remote repository before calculating the
SHA-1. However, I didn't change the logic guarding the existing fetch:
if test -z "$nofetch"
then
# Run fetch only if $sha1 isn't present or it
# is not reachable from a ref.
(clear_local_git_env; cd "$path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
fi
There will not be a double-fetch, because the new $sha1 determined
after the `--remote` triggered fetch should always exist in the
repository. If it doesn't, it's because some racy process removed it
from the submodule's repository and we *should* be re-fetching.
Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 16:03:32 +00:00
|
|
|
echo line5 >> file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "upstream line5" &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main
|
submodule update: add --remote for submodule's upstream changes
The current `update` command incorporates the superproject's gitlinked
SHA-1 ($sha1) into the submodule HEAD ($subsha1). Depending on the
options you use, it may checkout $sha1, rebase the $subsha1 onto
$sha1, or merge $sha1 into $subsha1. This helps you keep up with
changes in the upstream superproject.
However, it's also useful to stay up to date with changes in the
upstream subproject. Previous workflows for incorporating such
changes include the ungainly:
$ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'
With this patch, all of the useful functionality for incorporating
superproject changes can be reused to incorporate upstream subproject
updates. When you specify --remote, the target $sha1 is replaced with
a $sha1 of the submodule's origin/master tracking branch. If you want
to merge a different tracking branch, you can configure the
`submodule.<name>.branch` option in `.gitmodules`. You can override
the `.gitmodules` configuration setting for a particular superproject
by configuring the option in that superproject's default configuration
(using the usual configuration hierarchy, e.g. `.git/config`,
`~/.gitconfig`, etc.).
Previous use of submodule.<name>.branch
=======================================
Because we're adding a new configuration option, it's a good idea to
check if anyone else is already using the option. The foreach-pull
example above was described by Ævar in
commit f030c96d8643fa0a1a9b2bd9c2f36a77721fb61f
Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date: Fri May 21 16:10:10 2010 +0000
git-submodule foreach: Add $toplevel variable
Gerrit uses the same interpretation for the setting, but because
Gerrit has direct access to the subproject repositories, it updates
the superproject repositories automatically when a subproject changes.
Gerrit also accepts the special value '.', which it expands into the
superproject's branch name.
Although the --remote functionality is using `submodule.<name>.branch`
slightly differently, the effect is the same. The foreach-pull
example uses the option to record the name of the local branch to
checkout before pulls. The tracking branch to be pulled is recorded
in `.git/modules/<name>/config`, which was initialized by the module
clone during `submodule add` or `submodule init`. Because the branch
name stored in `submodule.<name>.branch` was likely the same as the
branch name used during the initial `submodule add`, the same branch
will be pulled in each workflow.
Implementation details
======================
In order to ensure a current tracking branch state, `update --remote`
fetches the submodule's remote repository before calculating the
SHA-1. However, I didn't change the logic guarding the existing fetch:
if test -z "$nofetch"
then
# Run fetch only if $sha1 isn't present or it
# is not reachable from a ref.
(clear_local_git_env; cd "$path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
test -z "$rev") || git-fetch)) ||
die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
fi
There will not be a double-fetch, because the new $sha1 determined
after the `--remote` triggered fetch should always exist in the
repository. If it doesn't, it's because some racy process removed it
from the submodule's repository and we *should* be re-fetching.
Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 16:03:32 +00:00
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.branch test-branch &&
|
|
|
|
git submodule update --remote --force submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:39 +00:00
|
|
|
test_expect_success 'submodule update --rebase staying on main' '
|
2009-04-23 23:06:38 +00:00
|
|
|
(cd super/submodule &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main
|
2009-04-23 23:06:38 +00:00
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update --rebase submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2020-11-18 23:44:39 +00:00
|
|
|
test_expect_success 'submodule update --merge staying on main' '
|
2009-06-02 22:59:12 +00:00
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update --merge submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
test_expect_success 'submodule update - rebase in .git/config' '
|
2009-04-23 23:06:38 +00:00
|
|
|
(cd super &&
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
git config submodule.submodule.update rebase
|
2009-04-23 23:06:38 +00:00
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
|
2009-04-23 23:06:38 +00:00
|
|
|
(cd super &&
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
git config submodule.submodule.update checkout
|
2009-04-23 23:06:38 +00:00
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update --rebase submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-06-02 22:59:12 +00:00
|
|
|
test_expect_success 'submodule update - merge in .git/config' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update merge
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update - checkout in .git/config but --merge given' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update checkout
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD~1
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update --merge submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
test_expect_success 'submodule update - checkout in .git/config' '
|
2009-04-23 23:06:38 +00:00
|
|
|
(cd super &&
|
Rename submodule.<name>.rebase to submodule.<name>.update
The addition of "submodule.<name>.rebase" demonstrates the usefulness of
alternatives to the default behaviour of "git submodule update". However,
by naming the config variable "submodule.<name>.rebase", and making it a
boolean choice, we are artificially constraining future git versions that
may want to add _more_ alternatives than just "rebase".
Therefore, while "submodule.<name>.rebase" is not yet in a stable git
release, future-proof it, by changing it from
submodule.<name>.rebase = true/false
to
submodule.<name>.update = rebase/checkout
where "checkout" specifies the default behaviour of "git submodule update"
(checking out the new commit to a detached HEAD), and "rebase" specifies
the --rebase behaviour (where the current local branch in the submodule is
rebase onto the new commit). Thus .update == checkout is equivalent to
.rebase == false, and .update == rebase is equivalent to .rebase == true.
Finally, leaving .update unset is equivalent to leaving .rebase unset.
In future git versions, other alternatives to "git submodule update"
behaviour can be included by adding them to the list of allowable values
for the submodule.<name>.update variable.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-03 06:27:06 +00:00
|
|
|
git config submodule.submodule.update checkout
|
2009-04-23 23:06:38 +00:00
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD^
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
! compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2013-07-03 09:02:02 +00:00
|
|
|
test_expect_success 'submodule update - command in .git/config' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update "!git checkout"
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard HEAD^
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
cd submodule &&
|
|
|
|
! compare_head
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
submodule: reject submodule.update = !command in .gitmodules
Since ac1fbbda2013 (submodule: do not copy unknown update mode from
.gitmodules, 2013-12-02), Git has been careful to avoid copying
[submodule "foo"]
update = !run an arbitrary scary command
from .gitmodules to a repository's local config, copying in the
setting 'update = none' instead. The gitmodules(5) manpage documents
the intention:
The !command form is intentionally ignored here for security
reasons
Unfortunately, starting with v2.20.0-rc0 (which integrated ee69b2a9
(submodule--helper: introduce new update-module-mode helper,
2018-08-13, first released in v2.20.0-rc0)), there are scenarios where
we *don't* ignore it: if the config store contains no
submodule.foo.update setting, the submodule-config API falls back to
reading .gitmodules and the repository-supplied !command gets run
after all.
This was part of a general change over time in submodule support to
read more directly from .gitmodules, since unlike .git/config it
allows a project to change values between branches and over time
(while still allowing .git/config to override things). But it was
never intended to apply to this kind of dangerous configuration.
The behavior change was not advertised in ee69b2a9's commit message
and was missed in review.
Let's take the opportunity to make the protection more robust, even in
Git versions that are technically not affected: instead of quietly
converting 'update = !command' to 'update = none', noisily treat it as
an error. Allowing the setting but treating it as meaning something
else was just confusing; users are better served by seeing the error
sooner. Forbidding the construct makes the semantics simpler and
means we can check for it in fsck (in a separate patch).
As a result, the submodule-config API cannot read this value from
.gitmodules under any circumstance, and we can declare with confidence
For security reasons, the '!command' form is not accepted
here.
Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2019-12-05 09:28:28 +00:00
|
|
|
test_expect_success 'submodule update - command in .gitmodules is rejected' '
|
2017-09-26 19:54:13 +00:00
|
|
|
test_when_finished "git -C super reset --hard HEAD^" &&
|
|
|
|
git -C super config -f .gitmodules submodule.submodule.update "!false" &&
|
|
|
|
git -C super commit -a -m "add command to .gitmodules file" &&
|
|
|
|
git -C super/submodule reset --hard $submodulesha1^ &&
|
submodule: reject submodule.update = !command in .gitmodules
Since ac1fbbda2013 (submodule: do not copy unknown update mode from
.gitmodules, 2013-12-02), Git has been careful to avoid copying
[submodule "foo"]
update = !run an arbitrary scary command
from .gitmodules to a repository's local config, copying in the
setting 'update = none' instead. The gitmodules(5) manpage documents
the intention:
The !command form is intentionally ignored here for security
reasons
Unfortunately, starting with v2.20.0-rc0 (which integrated ee69b2a9
(submodule--helper: introduce new update-module-mode helper,
2018-08-13, first released in v2.20.0-rc0)), there are scenarios where
we *don't* ignore it: if the config store contains no
submodule.foo.update setting, the submodule-config API falls back to
reading .gitmodules and the repository-supplied !command gets run
after all.
This was part of a general change over time in submodule support to
read more directly from .gitmodules, since unlike .git/config it
allows a project to change values between branches and over time
(while still allowing .git/config to override things). But it was
never intended to apply to this kind of dangerous configuration.
The behavior change was not advertised in ee69b2a9's commit message
and was missed in review.
Let's take the opportunity to make the protection more robust, even in
Git versions that are technically not affected: instead of quietly
converting 'update = !command' to 'update = none', noisily treat it as
an error. Allowing the setting but treating it as meaning something
else was just confusing; users are better served by seeing the error
sooner. Forbidding the construct makes the semantics simpler and
means we can check for it in fsck (in a separate patch).
As a result, the submodule-config API cannot read this value from
.gitmodules under any circumstance, and we can declare with confidence
For security reasons, the '!command' form is not accepted
here.
Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2019-12-05 09:28:28 +00:00
|
|
|
test_must_fail git -C super submodule update submodule
|
2017-09-26 19:54:13 +00:00
|
|
|
'
|
|
|
|
|
2019-12-05 09:30:43 +00:00
|
|
|
test_expect_success 'fsck detects command in .gitmodules' '
|
|
|
|
git init command-in-gitmodules &&
|
|
|
|
(
|
|
|
|
cd command-in-gitmodules &&
|
|
|
|
git submodule add ../submodule submodule &&
|
|
|
|
test_commit adding-submodule &&
|
|
|
|
|
|
|
|
git config -f .gitmodules submodule.submodule.update "!false" &&
|
|
|
|
git add .gitmodules &&
|
|
|
|
test_commit configuring-update &&
|
|
|
|
test_must_fail git fsck
|
|
|
|
)
|
2017-09-26 19:54:13 +00:00
|
|
|
'
|
|
|
|
|
2016-03-30 01:27:44 +00:00
|
|
|
cat << EOF >expect
|
2021-07-10 07:47:59 +00:00
|
|
|
fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule'
|
2016-03-30 01:27:44 +00:00
|
|
|
EOF
|
|
|
|
|
2013-07-03 09:02:02 +00:00
|
|
|
test_expect_success 'submodule update - command in .git/config catches failure' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update "!false"
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
2016-03-30 01:27:44 +00:00
|
|
|
git reset --hard $submodulesha1^
|
2013-07-03 09:02:02 +00:00
|
|
|
) &&
|
|
|
|
(cd super &&
|
2016-03-30 01:27:44 +00:00
|
|
|
test_must_fail git submodule update submodule 2>../actual
|
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp actual expect
|
2016-03-30 01:27:44 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
cat << EOF >expect
|
2021-07-10 07:47:59 +00:00
|
|
|
fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule'
|
2016-03-30 01:27:44 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update "!false"
|
|
|
|
) &&
|
|
|
|
(cd super/submodule &&
|
|
|
|
git reset --hard $submodulesha1^
|
|
|
|
) &&
|
|
|
|
(cd super &&
|
|
|
|
mkdir tmp && cd tmp &&
|
|
|
|
test_must_fail git submodule update ../submodule 2>../../actual
|
2016-03-30 01:27:45 +00:00
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp actual expect
|
2016-03-30 01:27:45 +00:00
|
|
|
'
|
|
|
|
|
2017-01-25 23:48:51 +00:00
|
|
|
test_expect_success 'submodule update - command run for initial population of submodule' '
|
2017-03-22 22:12:07 +00:00
|
|
|
cat >expect <<-EOF &&
|
2021-07-10 07:47:59 +00:00
|
|
|
fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
|
2017-03-22 22:12:07 +00:00
|
|
|
EOF
|
2017-01-25 23:48:51 +00:00
|
|
|
rm -rf super/submodule &&
|
2017-03-22 22:12:07 +00:00
|
|
|
test_must_fail git -C super submodule update 2>actual &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp expect actual &&
|
2017-01-25 23:48:51 +00:00
|
|
|
git -C super submodule update --checkout
|
|
|
|
'
|
|
|
|
|
2016-03-30 01:27:45 +00:00
|
|
|
cat << EOF >expect
|
2021-07-10 07:47:59 +00:00
|
|
|
fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
|
|
|
|
fatal: Failed to recurse into submodule path '../super'
|
2016-03-30 01:27:45 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
|
|
|
|
(cd recursivesuper &&
|
|
|
|
git submodule update --remote super &&
|
|
|
|
git add super &&
|
|
|
|
git commit -m "update to latest to have more than one commit in submodules"
|
|
|
|
) &&
|
|
|
|
git -C recursivesuper/super config submodule.submodule.update "!false" &&
|
|
|
|
git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
|
|
|
|
(cd recursivesuper &&
|
|
|
|
mkdir -p tmp && cd tmp &&
|
|
|
|
test_must_fail git submodule update --recursive ../super 2>../../actual
|
2016-03-30 01:27:44 +00:00
|
|
|
) &&
|
2021-02-11 01:53:53 +00:00
|
|
|
test_cmp actual expect
|
2013-07-03 09:02:02 +00:00
|
|
|
'
|
|
|
|
|
2013-12-02 21:31:55 +00:00
|
|
|
test_expect_success 'submodule init does not copy command into .git/config' '
|
submodule: reject submodule.update = !command in .gitmodules
Since ac1fbbda2013 (submodule: do not copy unknown update mode from
.gitmodules, 2013-12-02), Git has been careful to avoid copying
[submodule "foo"]
update = !run an arbitrary scary command
from .gitmodules to a repository's local config, copying in the
setting 'update = none' instead. The gitmodules(5) manpage documents
the intention:
The !command form is intentionally ignored here for security
reasons
Unfortunately, starting with v2.20.0-rc0 (which integrated ee69b2a9
(submodule--helper: introduce new update-module-mode helper,
2018-08-13, first released in v2.20.0-rc0)), there are scenarios where
we *don't* ignore it: if the config store contains no
submodule.foo.update setting, the submodule-config API falls back to
reading .gitmodules and the repository-supplied !command gets run
after all.
This was part of a general change over time in submodule support to
read more directly from .gitmodules, since unlike .git/config it
allows a project to change values between branches and over time
(while still allowing .git/config to override things). But it was
never intended to apply to this kind of dangerous configuration.
The behavior change was not advertised in ee69b2a9's commit message
and was missed in review.
Let's take the opportunity to make the protection more robust, even in
Git versions that are technically not affected: instead of quietly
converting 'update = !command' to 'update = none', noisily treat it as
an error. Allowing the setting but treating it as meaning something
else was just confusing; users are better served by seeing the error
sooner. Forbidding the construct makes the semantics simpler and
means we can check for it in fsck (in a separate patch).
As a result, the submodule-config API cannot read this value from
.gitmodules under any circumstance, and we can declare with confidence
For security reasons, the '!command' form is not accepted
here.
Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2019-12-05 09:28:28 +00:00
|
|
|
test_when_finished "git -C super update-index --force-remove submodule1" &&
|
|
|
|
test_when_finished git config -f super/.gitmodules \
|
|
|
|
--remove-section submodule.submodule1 &&
|
2013-12-02 21:31:55 +00:00
|
|
|
(cd super &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git ls-files -s submodule >out &&
|
|
|
|
H=$(cut -d" " -f2 out) &&
|
2013-12-02 21:31:55 +00:00
|
|
|
mkdir submodule1 &&
|
|
|
|
git update-index --add --cacheinfo 160000 $H submodule1 &&
|
|
|
|
git config -f .gitmodules submodule.submodule1.path submodule1 &&
|
|
|
|
git config -f .gitmodules submodule.submodule1.url ../submodule &&
|
|
|
|
git config -f .gitmodules submodule.submodule1.update !false &&
|
submodule: reject submodule.update = !command in .gitmodules
Since ac1fbbda2013 (submodule: do not copy unknown update mode from
.gitmodules, 2013-12-02), Git has been careful to avoid copying
[submodule "foo"]
update = !run an arbitrary scary command
from .gitmodules to a repository's local config, copying in the
setting 'update = none' instead. The gitmodules(5) manpage documents
the intention:
The !command form is intentionally ignored here for security
reasons
Unfortunately, starting with v2.20.0-rc0 (which integrated ee69b2a9
(submodule--helper: introduce new update-module-mode helper,
2018-08-13, first released in v2.20.0-rc0)), there are scenarios where
we *don't* ignore it: if the config store contains no
submodule.foo.update setting, the submodule-config API falls back to
reading .gitmodules and the repository-supplied !command gets run
after all.
This was part of a general change over time in submodule support to
read more directly from .gitmodules, since unlike .git/config it
allows a project to change values between branches and over time
(while still allowing .git/config to override things). But it was
never intended to apply to this kind of dangerous configuration.
The behavior change was not advertised in ee69b2a9's commit message
and was missed in review.
Let's take the opportunity to make the protection more robust, even in
Git versions that are technically not affected: instead of quietly
converting 'update = !command' to 'update = none', noisily treat it as
an error. Allowing the setting but treating it as meaning something
else was just confusing; users are better served by seeing the error
sooner. Forbidding the construct makes the semantics simpler and
means we can check for it in fsck (in a separate patch).
As a result, the submodule-config API cannot read this value from
.gitmodules under any circumstance, and we can declare with confidence
For security reasons, the '!command' form is not accepted
here.
Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2019-12-05 09:28:28 +00:00
|
|
|
test_must_fail git submodule init submodule1 &&
|
|
|
|
test_expect_code 1 git config submodule.submodule1.update >actual &&
|
|
|
|
test_must_be_empty actual
|
2013-12-02 21:31:55 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-04-23 23:06:38 +00:00
|
|
|
test_expect_success 'submodule init picks up rebase' '
|
|
|
|
(cd super &&
|
2010-03-05 08:20:38 +00:00
|
|
|
git config -f .gitmodules submodule.rebasing.update rebase &&
|
2009-04-23 23:06:38 +00:00
|
|
|
git submodule init rebasing &&
|
2010-03-05 08:20:38 +00:00
|
|
|
test "rebase" = "$(git config submodule.rebasing.update)"
|
2009-04-23 23:06:38 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2009-06-02 22:59:12 +00:00
|
|
|
test_expect_success 'submodule init picks up merge' '
|
|
|
|
(cd super &&
|
2010-03-05 08:20:38 +00:00
|
|
|
git config -f .gitmodules submodule.merging.update merge &&
|
2009-06-02 22:59:12 +00:00
|
|
|
git submodule init merging &&
|
2010-03-05 08:20:38 +00:00
|
|
|
test "merge" = "$(git config submodule.merging.update)"
|
2009-06-02 22:59:12 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-02-17 16:18:46 +00:00
|
|
|
test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
|
2017-01-25 23:48:51 +00:00
|
|
|
test_config -C super submodule.submodule.update checkout &&
|
2011-02-17 16:18:46 +00:00
|
|
|
(cd super &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >expect &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update --merge submodule &&
|
|
|
|
git status -s submodule >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
|
2017-01-25 23:48:51 +00:00
|
|
|
test_config -C super submodule.submodule.update checkout &&
|
2011-02-17 16:18:46 +00:00
|
|
|
(cd super &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >expect &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update --rebase submodule &&
|
|
|
|
git status -s submodule >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update ignores update=merge config for new submodules' '
|
|
|
|
(cd super &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >expect &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git config submodule.submodule.update merge &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >actual &&
|
|
|
|
git config --unset submodule.submodule.update &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update ignores update=rebase config for new submodules' '
|
|
|
|
(cd super &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >expect &&
|
|
|
|
rm -rf submodule &&
|
|
|
|
git config submodule.submodule.update rebase &&
|
|
|
|
git submodule update submodule &&
|
|
|
|
git status -s submodule >actual &&
|
|
|
|
git config --unset submodule.submodule.update &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2011-08-11 17:51:46 +00:00
|
|
|
test_expect_success 'submodule init picks up update=none' '
|
|
|
|
(cd super &&
|
|
|
|
git config -f .gitmodules submodule.none.update none &&
|
|
|
|
git submodule init none &&
|
|
|
|
test "none" = "$(git config submodule.none.update)"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update - update=none in .git/config' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update none &&
|
|
|
|
(cd submodule &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-08-11 17:51:46 +00:00
|
|
|
compare_head
|
|
|
|
) &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git diff --name-only >out &&
|
|
|
|
grep ^submodule$ out &&
|
2011-08-11 17:51:46 +00:00
|
|
|
git submodule update &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git diff --name-only >out &&
|
|
|
|
grep ^submodule$ out &&
|
2011-08-11 17:51:46 +00:00
|
|
|
(cd submodule &&
|
|
|
|
compare_head
|
|
|
|
) &&
|
|
|
|
git config --unset submodule.submodule.update &&
|
|
|
|
git submodule update submodule
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
|
|
|
|
(cd super &&
|
|
|
|
git config submodule.submodule.update none &&
|
|
|
|
(cd submodule &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-08-11 17:51:46 +00:00
|
|
|
compare_head
|
|
|
|
) &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git diff --name-only >out &&
|
|
|
|
grep ^submodule$ out &&
|
2011-08-11 17:51:46 +00:00
|
|
|
git submodule update --checkout &&
|
2018-08-08 16:31:04 +00:00
|
|
|
git diff --name-only >out &&
|
|
|
|
! grep ^submodule$ out &&
|
2011-08-11 17:51:46 +00:00
|
|
|
(cd submodule &&
|
2018-08-08 16:31:07 +00:00
|
|
|
! compare_head
|
2011-08-11 17:51:46 +00:00
|
|
|
) &&
|
|
|
|
git config --unset submodule.submodule.update
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update --init skips submodule with update=none' '
|
|
|
|
(cd super &&
|
|
|
|
git add .gitmodules &&
|
|
|
|
git commit -m ".gitmodules"
|
|
|
|
) &&
|
|
|
|
git clone super cloned &&
|
|
|
|
(cd cloned &&
|
|
|
|
git submodule update --init &&
|
2018-08-08 16:31:06 +00:00
|
|
|
test_path_exists submodule/.git &&
|
|
|
|
test_path_is_missing none/.git
|
2011-08-11 17:51:46 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2022-04-25 12:45:41 +00:00
|
|
|
test_expect_success 'submodule update with pathspec warns against uninitialized ones' '
|
|
|
|
test_when_finished "rm -fr selective" &&
|
|
|
|
git clone super selective &&
|
|
|
|
(
|
|
|
|
cd selective &&
|
|
|
|
git submodule init submodule &&
|
|
|
|
|
|
|
|
git submodule update submodule 2>err &&
|
|
|
|
! grep "Submodule path .* not initialized" err &&
|
|
|
|
|
|
|
|
git submodule update rebasing 2>err &&
|
|
|
|
grep "Submodule path .rebasing. not initialized" err &&
|
|
|
|
|
|
|
|
test_path_exists submodule/.git &&
|
|
|
|
test_path_is_missing rebasing/.git
|
|
|
|
)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update without pathspec updates only initialized ones' '
|
|
|
|
test_when_finished "rm -fr selective" &&
|
|
|
|
git clone super selective &&
|
|
|
|
(
|
|
|
|
cd selective &&
|
|
|
|
git submodule init submodule &&
|
|
|
|
git submodule update 2>err &&
|
|
|
|
test_path_exists submodule/.git &&
|
|
|
|
test_path_is_missing rebasing/.git &&
|
|
|
|
! grep "Submodule path .* not initialized" err
|
|
|
|
)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2011-06-13 17:15:26 +00:00
|
|
|
test_expect_success 'submodule update continues after checkout error' '
|
|
|
|
(cd super &&
|
|
|
|
git reset --hard HEAD &&
|
|
|
|
git submodule add ../submodule submodule2 &&
|
|
|
|
git submodule init &&
|
|
|
|
git commit -am "new_submodule" &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../expect
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
(cd submodule &&
|
|
|
|
test_commit "update_submodule" file
|
|
|
|
) &&
|
|
|
|
(cd submodule2 &&
|
|
|
|
test_commit "update_submodule2" file
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git add submodule2 &&
|
|
|
|
git commit -m "two_new_submodule_commits" &&
|
|
|
|
(cd submodule &&
|
|
|
|
echo "" > file
|
|
|
|
) &&
|
|
|
|
git checkout HEAD^ &&
|
|
|
|
test_must_fail git submodule update &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../actual
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
test_expect_success 'submodule update continues after recursive checkout error' '
|
|
|
|
(cd super &&
|
|
|
|
git reset --hard HEAD &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-06-13 17:15:26 +00:00
|
|
|
git submodule update &&
|
|
|
|
(cd submodule &&
|
|
|
|
git submodule add ../submodule subsubmodule &&
|
|
|
|
git submodule init &&
|
|
|
|
git commit -m "new_subsubmodule"
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git commit -m "update_submodule" &&
|
|
|
|
(cd submodule &&
|
|
|
|
(cd subsubmodule &&
|
|
|
|
test_commit "update_subsubmodule" file
|
|
|
|
) &&
|
|
|
|
git add subsubmodule &&
|
|
|
|
test_commit "update_submodule_again" file &&
|
|
|
|
(cd subsubmodule &&
|
|
|
|
test_commit "update_subsubmodule_again" file
|
|
|
|
) &&
|
|
|
|
test_commit "update_submodule_again_again" file
|
|
|
|
) &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../expect &&
|
2011-06-13 17:15:26 +00:00
|
|
|
test_commit "update_submodule2_again" file
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git add submodule2 &&
|
|
|
|
git commit -m "new_commits" &&
|
|
|
|
git checkout HEAD^ &&
|
|
|
|
(cd submodule &&
|
|
|
|
git checkout HEAD^ &&
|
|
|
|
(cd subsubmodule &&
|
|
|
|
echo "" > file
|
|
|
|
)
|
|
|
|
) &&
|
2022-08-31 23:18:02 +00:00
|
|
|
test_expect_code 1 git submodule update --recursive &&
|
2011-06-13 17:15:26 +00:00
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../actual
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update exit immediately in case of merge conflict' '
|
|
|
|
(cd super &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-06-13 17:15:26 +00:00
|
|
|
git reset --hard HEAD &&
|
|
|
|
(cd submodule &&
|
|
|
|
(cd subsubmodule &&
|
|
|
|
git reset --hard HEAD
|
|
|
|
)
|
|
|
|
) &&
|
|
|
|
git submodule update --recursive &&
|
|
|
|
(cd submodule &&
|
|
|
|
test_commit "update_submodule_2" file
|
|
|
|
) &&
|
|
|
|
(cd submodule2 &&
|
|
|
|
test_commit "update_submodule2_2" file
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git add submodule2 &&
|
|
|
|
git commit -m "two_new_submodule_commits" &&
|
|
|
|
(cd submodule &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-06-13 17:15:26 +00:00
|
|
|
test_commit "conflict" file &&
|
|
|
|
echo "conflict" > file
|
|
|
|
) &&
|
|
|
|
git checkout HEAD^ &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../expect
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
git config submodule.submodule.update merge &&
|
|
|
|
test_must_fail git submodule update &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../actual
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
2011-08-15 21:17:47 +00:00
|
|
|
|
2011-06-13 17:15:26 +00:00
|
|
|
test_expect_success 'submodule update exit immediately after recursive rebase error' '
|
|
|
|
(cd super &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-06-13 17:15:26 +00:00
|
|
|
git reset --hard HEAD &&
|
|
|
|
(cd submodule &&
|
|
|
|
git reset --hard HEAD &&
|
|
|
|
git submodule update --recursive
|
|
|
|
) &&
|
|
|
|
(cd submodule &&
|
|
|
|
test_commit "update_submodule_3" file
|
|
|
|
) &&
|
|
|
|
(cd submodule2 &&
|
|
|
|
test_commit "update_submodule2_3" file
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
git add submodule2 &&
|
|
|
|
git commit -m "two_new_submodule_commits" &&
|
|
|
|
(cd submodule &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git checkout main &&
|
2011-06-13 17:15:26 +00:00
|
|
|
test_commit "conflict2" file &&
|
|
|
|
echo "conflict" > file
|
|
|
|
) &&
|
|
|
|
git checkout HEAD^ &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../expect
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
git config submodule.submodule.update rebase &&
|
|
|
|
test_must_fail git submodule update &&
|
|
|
|
(cd submodule2 &&
|
2012-07-30 17:51:52 +00:00
|
|
|
git rev-parse --verify HEAD >../actual
|
2011-06-13 17:15:26 +00:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
2011-08-15 21:17:47 +00:00
|
|
|
|
|
|
|
test_expect_success 'add different submodules to the same path' '
|
|
|
|
(cd super &&
|
|
|
|
git submodule add ../submodule s1 &&
|
|
|
|
test_must_fail git submodule add ../merging s1
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule add places git-dir in superprojects git-dir' '
|
|
|
|
(cd super &&
|
|
|
|
mkdir deeper &&
|
|
|
|
git submodule add ../submodule deeper/submodule &&
|
|
|
|
(cd deeper/submodule &&
|
|
|
|
git log > ../../expected
|
|
|
|
) &&
|
|
|
|
(cd .git/modules/deeper/submodule &&
|
|
|
|
git log > ../../../../actual
|
|
|
|
) &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected actual
|
2011-08-15 21:17:47 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update places git-dir in superprojects git-dir' '
|
|
|
|
(cd super &&
|
|
|
|
git commit -m "added submodule"
|
|
|
|
) &&
|
|
|
|
git clone super super2 &&
|
|
|
|
(cd super2 &&
|
|
|
|
git submodule init deeper/submodule &&
|
|
|
|
git submodule update &&
|
|
|
|
(cd deeper/submodule &&
|
|
|
|
git log > ../../expected
|
|
|
|
) &&
|
|
|
|
(cd .git/modules/deeper/submodule &&
|
|
|
|
git log > ../../../../actual
|
|
|
|
) &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected actual
|
2011-08-15 21:17:47 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
|
|
|
|
(cd super2 &&
|
|
|
|
(cd deeper/submodule &&
|
|
|
|
git submodule add ../submodule subsubmodule &&
|
|
|
|
(cd subsubmodule &&
|
|
|
|
git log > ../../../expected
|
|
|
|
) &&
|
|
|
|
git commit -m "added subsubmodule" &&
|
2013-01-05 00:19:19 +00:00
|
|
|
git push origin :
|
2011-08-15 21:17:47 +00:00
|
|
|
) &&
|
|
|
|
(cd .git/modules/deeper/submodule/modules/subsubmodule &&
|
|
|
|
git log > ../../../../../actual
|
|
|
|
) &&
|
|
|
|
git add deeper/submodule &&
|
|
|
|
git commit -m "update submodule" &&
|
2013-01-05 00:19:19 +00:00
|
|
|
git push origin : &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected actual
|
2011-08-15 21:17:47 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
|
|
|
|
mkdir super_update_r &&
|
|
|
|
(cd super_update_r &&
|
|
|
|
git init --bare
|
|
|
|
) &&
|
|
|
|
mkdir subsuper_update_r &&
|
|
|
|
(cd subsuper_update_r &&
|
|
|
|
git init --bare
|
|
|
|
) &&
|
|
|
|
mkdir subsubsuper_update_r &&
|
|
|
|
(cd subsubsuper_update_r &&
|
|
|
|
git init --bare
|
|
|
|
) &&
|
|
|
|
git clone subsubsuper_update_r subsubsuper_update_r2 &&
|
|
|
|
(cd subsubsuper_update_r2 &&
|
|
|
|
test_commit "update_subsubsuper" file &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git push origin main
|
2011-08-15 21:17:47 +00:00
|
|
|
) &&
|
|
|
|
git clone subsuper_update_r subsuper_update_r2 &&
|
|
|
|
(cd subsuper_update_r2 &&
|
|
|
|
test_commit "update_subsuper" file &&
|
|
|
|
git submodule add ../subsubsuper_update_r subsubmodule &&
|
|
|
|
git commit -am "subsubmodule" &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git push origin main
|
2011-08-15 21:17:47 +00:00
|
|
|
) &&
|
|
|
|
git clone super_update_r super_update_r2 &&
|
|
|
|
(cd super_update_r2 &&
|
|
|
|
test_commit "update_super" file &&
|
|
|
|
git submodule add ../subsuper_update_r submodule &&
|
|
|
|
git commit -am "submodule" &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git push origin main
|
2011-08-15 21:17:47 +00:00
|
|
|
) &&
|
|
|
|
rm -rf super_update_r2 &&
|
|
|
|
git clone super_update_r super_update_r2 &&
|
|
|
|
(cd super_update_r2 &&
|
2013-03-02 19:44:59 +00:00
|
|
|
git submodule update --init --recursive >actual &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep "Submodule path .submodule/subsubmodule.: checked out" actual &&
|
2011-08-15 21:17:47 +00:00
|
|
|
(cd submodule/subsubmodule &&
|
|
|
|
git log > ../../expected
|
|
|
|
) &&
|
2018-07-02 00:24:03 +00:00
|
|
|
(cd .git/modules/submodule/modules/subsubmodule &&
|
2011-08-15 21:17:47 +00:00
|
|
|
git log > ../../../../../actual
|
2018-07-02 00:24:03 +00:00
|
|
|
) &&
|
2018-10-05 21:54:04 +00:00
|
|
|
test_cmp expected actual
|
2011-08-15 21:17:47 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-01-24 21:49:56 +00:00
|
|
|
test_expect_success 'submodule add properly re-creates deeper level submodules' '
|
|
|
|
(cd super &&
|
2020-11-18 23:44:39 +00:00
|
|
|
git reset --hard main &&
|
2012-01-24 21:49:56 +00:00
|
|
|
rm -rf deeper/ &&
|
2012-09-30 21:01:29 +00:00
|
|
|
git submodule add --force ../submodule deeper/submodule
|
2012-01-24 21:49:56 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-03-04 21:15:36 +00:00
|
|
|
test_expect_success 'submodule update properly revives a moved submodule' '
|
|
|
|
(cd super &&
|
2013-03-13 11:42:52 +00:00
|
|
|
H=$(git rev-parse --short HEAD) &&
|
2012-03-04 21:15:36 +00:00
|
|
|
git commit -am "pre move" &&
|
2013-03-13 11:42:52 +00:00
|
|
|
H2=$(git rev-parse --short HEAD) &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git status >out &&
|
|
|
|
sed "s/$H/XXX/" out >expect &&
|
2018-07-02 00:24:03 +00:00
|
|
|
H=$(cd submodule2 && git rev-parse HEAD) &&
|
2012-03-04 21:15:36 +00:00
|
|
|
git rm --cached submodule2 &&
|
|
|
|
rm -rf submodule2 &&
|
|
|
|
mkdir -p "moved/sub module" &&
|
|
|
|
git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
|
2018-06-16 20:33:19 +00:00
|
|
|
git config -f .gitmodules submodule.submodule2.path "moved/sub module" &&
|
2012-03-04 21:15:36 +00:00
|
|
|
git commit -am "post move" &&
|
|
|
|
git submodule update &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git status > out &&
|
|
|
|
sed "s/$H2/XXX/" out >actual &&
|
2012-03-04 21:15:36 +00:00
|
|
|
test_cmp expect actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2012-07-12 17:45:32 +00:00
|
|
|
test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
|
|
|
|
mkdir -p linked/dir &&
|
|
|
|
ln -s linked/dir linkto &&
|
2013-07-02 21:42:56 +00:00
|
|
|
(cd linkto &&
|
|
|
|
git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
|
|
|
|
(cd super &&
|
|
|
|
git submodule update --init --recursive
|
|
|
|
)
|
2012-07-12 17:45:32 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2013-07-02 21:42:56 +00:00
|
|
|
test_expect_success 'submodule update clone shallow submodule' '
|
2016-07-29 00:44:03 +00:00
|
|
|
test_when_finished "rm -rf super3" &&
|
2018-08-08 16:31:05 +00:00
|
|
|
first=$(git -C cloned rev-parse HEAD:submodule) &&
|
2016-07-29 00:44:03 +00:00
|
|
|
second=$(git -C submodule rev-parse HEAD) &&
|
2016-08-10 17:56:07 +00:00
|
|
|
commit_count=$(git -C submodule rev-list --count $first^..$second) &&
|
2013-07-02 21:42:56 +00:00
|
|
|
git clone cloned super3 &&
|
2015-03-20 10:07:15 +00:00
|
|
|
pwd=$(pwd) &&
|
2016-07-29 00:44:03 +00:00
|
|
|
(
|
|
|
|
cd super3 &&
|
|
|
|
sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
|
|
|
|
mv -f .gitmodules.tmp .gitmodules &&
|
|
|
|
git submodule update --init --depth=$commit_count &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git -C submodule log --oneline >out &&
|
|
|
|
test_line_count = 1 out
|
2016-07-29 00:44:03 +00:00
|
|
|
)
|
2013-11-11 20:55:52 +00:00
|
|
|
'
|
|
|
|
|
2016-07-29 00:44:04 +00:00
|
|
|
test_expect_success 'submodule update clone shallow submodule outside of depth' '
|
|
|
|
test_when_finished "rm -rf super3" &&
|
|
|
|
git clone cloned super3 &&
|
|
|
|
pwd=$(pwd) &&
|
|
|
|
(
|
|
|
|
cd super3 &&
|
|
|
|
sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
|
|
|
|
mv -f .gitmodules.tmp .gitmodules &&
|
2019-02-25 21:54:08 +00:00
|
|
|
# Some protocol versions (e.g. 2) support fetching
|
|
|
|
# unadvertised objects, so restrict this test to v0.
|
2019-12-24 01:01:10 +00:00
|
|
|
test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \
|
2019-02-25 21:54:08 +00:00
|
|
|
git submodule update --init --depth=1 2>actual &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep "Direct fetching of that commit failed." actual &&
|
2016-07-29 00:44:04 +00:00
|
|
|
git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
|
|
|
|
git submodule update --init --depth=1 >actual &&
|
2018-08-08 16:31:05 +00:00
|
|
|
git -C submodule log --oneline >out &&
|
|
|
|
test_line_count = 1 out
|
2016-07-29 00:44:04 +00:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2013-11-11 20:55:52 +00:00
|
|
|
test_expect_success 'submodule update --recursive drops module name before recursing' '
|
|
|
|
(cd super2 &&
|
|
|
|
(cd deeper/submodule/subsubmodule &&
|
|
|
|
git checkout HEAD^
|
|
|
|
) &&
|
|
|
|
git submodule update --recursive deeper/submodule >actual &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
|
2013-07-02 21:42:56 +00:00
|
|
|
)
|
|
|
|
'
|
2016-03-01 02:07:19 +00:00
|
|
|
|
|
|
|
test_expect_success 'submodule update can be run in parallel' '
|
|
|
|
(cd super2 &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
|
|
|
|
grep "7 tasks" trace.out &&
|
|
|
|
git config submodule.fetchJobs 8 &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git submodule update &&
|
|
|
|
grep "8 tasks" trace.out &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
|
|
|
|
grep "9 tasks" trace.out
|
|
|
|
)
|
|
|
|
'
|
2016-03-01 02:07:20 +00:00
|
|
|
|
|
|
|
test_expect_success 'git clone passes the parallel jobs config on to submodules' '
|
|
|
|
test_when_finished "rm -rf super4" &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
|
|
|
|
grep "7 tasks" trace.out &&
|
|
|
|
rm -rf super4 &&
|
|
|
|
git config --global submodule.fetchJobs 8 &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
|
|
|
|
grep "8 tasks" trace.out &&
|
|
|
|
rm -rf super4 &&
|
|
|
|
GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
|
|
|
|
grep "9 tasks" trace.out &&
|
|
|
|
rm -rf super4
|
|
|
|
'
|
|
|
|
|
2020-09-30 19:50:53 +00:00
|
|
|
test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '
|
|
|
|
(cd super &&
|
|
|
|
test_commit -C rebasing message &&
|
|
|
|
git submodule update --rebase --quiet >out 2>err &&
|
|
|
|
test_must_be_empty out &&
|
|
|
|
test_must_be_empty err &&
|
2022-06-28 10:05:28 +00:00
|
|
|
git submodule update --rebase >out 2>err &&
|
2020-09-30 19:50:53 +00:00
|
|
|
test_file_not_empty out &&
|
|
|
|
test_must_be_empty err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2021-04-30 09:59:06 +00:00
|
|
|
test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' '
|
|
|
|
test_when_finished "rm -rf super4 super5 super6" &&
|
|
|
|
git clone . super4 &&
|
|
|
|
(cd super4 &&
|
|
|
|
git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 &&
|
|
|
|
git commit -am "setup submodule3"
|
|
|
|
) &&
|
|
|
|
(cd submodule &&
|
|
|
|
test_commit line6 file
|
|
|
|
) &&
|
|
|
|
git clone super4 super5 &&
|
|
|
|
(cd super5 &&
|
|
|
|
git submodule update --quiet --init --depth=1 submodule3 >out 2>err &&
|
|
|
|
test_must_be_empty out &&
|
|
|
|
test_must_be_empty err
|
|
|
|
) &&
|
|
|
|
git clone super4 super6 &&
|
|
|
|
(cd super6 &&
|
|
|
|
git submodule update --init --depth=1 submodule3 >out 2>err &&
|
|
|
|
test_file_not_empty out &&
|
|
|
|
test_file_not_empty err
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2022-03-05 00:14:00 +00:00
|
|
|
test_expect_success 'submodule update --filter requires --init' '
|
|
|
|
test_expect_code 129 git -C super submodule update --filter blob:none
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update --filter sets partial clone settings' '
|
|
|
|
test_when_finished "rm -rf super-filter" &&
|
|
|
|
git clone cloned super-filter &&
|
|
|
|
git -C super-filter submodule update --init --filter blob:none &&
|
|
|
|
test_cmp_config -C super-filter/submodule true remote.origin.promisor &&
|
|
|
|
test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
|
|
|
|
'
|
|
|
|
|
2022-07-01 02:11:51 +00:00
|
|
|
# NEEDSWORK: Clean up the tests so that we can reuse the test setup.
|
|
|
|
# Don't reuse the existing repos because the earlier tests have
|
|
|
|
# intentionally disruptive configurations.
|
|
|
|
test_expect_success 'setup clean recursive superproject' '
|
|
|
|
git init bottom &&
|
|
|
|
test_commit -C bottom "bottom" &&
|
|
|
|
git init middle &&
|
|
|
|
git -C middle submodule add ../bottom bottom &&
|
|
|
|
git -C middle commit -m "middle" &&
|
|
|
|
git init top &&
|
|
|
|
git -C top submodule add ../middle middle &&
|
|
|
|
git -C top commit -m "top" &&
|
|
|
|
git clone --recurse-submodules top top-clean
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update should skip unmerged submodules' '
|
|
|
|
test_when_finished "rm -fr top-cloned" &&
|
|
|
|
cp -r top-clean top-cloned &&
|
|
|
|
|
|
|
|
# Create an upstream commit in each repo, starting with bottom
|
|
|
|
test_commit -C bottom upstream_commit &&
|
|
|
|
# Create middle commit
|
|
|
|
git -C middle/bottom fetch &&
|
|
|
|
git -C middle/bottom checkout -f FETCH_HEAD &&
|
|
|
|
git -C middle add bottom &&
|
|
|
|
git -C middle commit -m "upstream_commit" &&
|
|
|
|
# Create top commit
|
|
|
|
git -C top/middle fetch &&
|
|
|
|
git -C top/middle checkout -f FETCH_HEAD &&
|
|
|
|
git -C top add middle &&
|
|
|
|
git -C top commit -m "upstream_commit" &&
|
|
|
|
|
|
|
|
# Create a downstream conflict
|
|
|
|
test_commit -C top-cloned/middle/bottom downstream_commit &&
|
|
|
|
git -C top-cloned/middle add bottom &&
|
|
|
|
git -C top-cloned/middle commit -m "downstream_commit" &&
|
|
|
|
git -C top-cloned/middle fetch --recurse-submodules origin &&
|
|
|
|
test_must_fail git -C top-cloned/middle merge origin/main &&
|
|
|
|
|
|
|
|
# Make the update of "middle" a no-op, otherwise we error out
|
|
|
|
# because of its unmerged state
|
|
|
|
test_config -C top-cloned submodule.middle.update !true &&
|
|
|
|
git -C top-cloned submodule update --recursive 2>actual.err &&
|
|
|
|
cat >expect.err <<-\EOF &&
|
2022-07-01 02:11:52 +00:00
|
|
|
Skipping unmerged submodule middle/bottom
|
2022-07-01 02:11:51 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expect.err actual.err
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule update --recursive skip submodules with strategy=none' '
|
|
|
|
test_when_finished "rm -fr top-cloned" &&
|
|
|
|
cp -r top-clean top-cloned &&
|
|
|
|
|
|
|
|
test_commit -C top-cloned/middle/bottom downstream_commit &&
|
|
|
|
git -C top-cloned/middle config submodule.bottom.update none &&
|
|
|
|
git -C top-cloned submodule update --recursive 2>actual.err &&
|
|
|
|
cat >expect.err <<-\EOF &&
|
2022-07-01 02:11:52 +00:00
|
|
|
Skipping submodule '\''middle/bottom'\''
|
2022-07-01 02:11:51 +00:00
|
|
|
EOF
|
|
|
|
test_cmp expect.err actual.err
|
|
|
|
'
|
|
|
|
|
2023-06-14 16:48:57 +00:00
|
|
|
add_submodule_commit_and_validate () {
|
|
|
|
HASH=$(git rev-parse HEAD) &&
|
|
|
|
git update-index --add --cacheinfo 160000,$HASH,sub &&
|
|
|
|
git commit -m "create submodule" &&
|
|
|
|
echo "160000 commit $HASH sub" >expect &&
|
|
|
|
git ls-tree HEAD -- sub >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'commit with staged submodule change' '
|
|
|
|
add_submodule_commit_and_validate
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' '
|
|
|
|
test_config diff.ignoreSubmodules dirty &&
|
|
|
|
add_submodule_commit_and_validate
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit with staged submodule change with ignoreSubmodules all' '
|
|
|
|
test_config diff.ignoreSubmodules all &&
|
|
|
|
add_submodule_commit_and_validate
|
|
|
|
'
|
|
|
|
|
2009-04-23 23:06:38 +00:00
|
|
|
test_done
|