Skip to content

Commit 1b614c0

Browse files
bmwillgitster
authored andcommitted
submodule add: respect submodule.active and submodule.<name>.active
In addition to adding submodule.<name>.url to the config, set submodule.<name>.active to true unless submodule.active is configured and the submodule's path matches the configured pathspec. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f8d711 commit 1b614c0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

git-submodule.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ or you are unsure what this means choose another name with the '--name' option."
278278
fi &&
279279
git add --force .gitmodules ||
280280
die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
281+
282+
# NEEDSWORK: In a multi-working-tree world, this needs to be
283+
# set in the per-worktree config.
284+
if git config --get submodule.active >/dev/null
285+
then
286+
# If the submodule being adding isn't already covered by the
287+
# current configured pathspec, set the submodule's active flag
288+
if ! git submodule--helper is-active "$sm_path"
289+
then
290+
git config submodule."$sm_name".active "true"
291+
fi
292+
else
293+
git config submodule."$sm_name".active "true"
294+
fi
281295
}
282296

283297
#

t/t7413-submodule-is-active.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ test_expect_success 'setup' '
1515
test_commit -C super initial &&
1616
git -C super submodule add ../sub sub1 &&
1717
git -C super submodule add ../sub sub2 &&
18+
19+
# Remove submodule.<name>.active entries in order to test in an
20+
# environment where only URLs are present in the conifg
21+
git -C super config --unset submodule.sub1.active &&
22+
git -C super config --unset submodule.sub2.active &&
23+
1824
git -C super commit -a -m "add 2 submodules at sub{1,2}"
1925
'
2026

@@ -83,4 +89,19 @@ test_expect_success 'is-active with submodule.active and submodule.<name>.active
8389
git -C super submodule--helper is-active sub2
8490
'
8591

92+
test_expect_success 'is-active, submodule.active and submodule add' '
93+
test_when_finished "rm -rf super2" &&
94+
git init super2 &&
95+
test_commit -C super2 initial &&
96+
git -C super2 config --add submodule.active "sub*" &&
97+
98+
# submodule add should only add submodule.<name>.active
99+
# to the config if not matched by the pathspec
100+
git -C super2 submodule add ../sub sub1 &&
101+
test_must_fail git -C super2 config --get submodule.sub1.active &&
102+
103+
git -C super2 submodule add ../sub mod &&
104+
git -C super2 config --get submodule.mod.active
105+
'
106+
86107
test_done

0 commit comments

Comments
 (0)