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 <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Mar 17, 2017 at 15:38 UTC
1b614c07d2428927358cc7317622913d1dbd59c9
2 files changed
+35
git-submodule.sh
+14
@@ -278,6 +278,20 @@ or you are unsure what this means choose another name with the '--name' option."
278
fi &&
279
git add --force .gitmodules ||
280
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
295
}
296
297
#
t/t7413-submodule-is-active.sh
+21
@@ -15,6 +15,12 @@ test_expect_success 'setup' '
15
test_commit -C super initial &&
16
git -C super submodule add ../sub sub1 &&
17
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
+
24
git -C super commit -a -m "add 2 submodules at sub{1,2}"
25
'
26
@@ -83,4 +89,19 @@ test_expect_success 'is-active with submodule.active and submodule.<name>.active
89
git -C super submodule--helper is-active sub2
90
'
91
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
+
107
test_done