[PATCH 06/10] submodule add: respect submodule.active

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When submodule.active is configured, in addition to adding
submodule."<name>".url to the config, add the path of the added
submodule if it isn't already covered by the current config values.

Signed-off-by: Brandon Williams <bmwill@xxxxxxxxxx>
---
 git-submodule.sh               | 11 +++++++++++
 t/t7413-submodule-is-active.sh | 22 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/git-submodule.sh b/git-submodule.sh
index e5b9a8920..4633a4336 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -271,6 +271,17 @@ or you are unsure what this means choose another name with the '--name' option."
 	fi &&
 	git add --force .gitmodules ||
 	die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
+
+	if git config --get submodule.active >/dev/null
+	then
+		# If the submodule being adding isn't already covered by the
+		# current configured pathspec, add the submodule's path to
+		# 'submodule.active'
+		if ! git submodule--helper is-active "$sm_path"
+		then
+			git config --add submodule.active "$sm_path"
+		fi
+	fi
 }
 
 #
diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh
index 683487020..8a519163b 100755
--- a/t/t7413-submodule-is-active.sh
+++ b/t/t7413-submodule-is-active.sh
@@ -60,4 +60,26 @@ test_expect_success 'is-active works with exclusions in submodule.active config'
 	git -C super config --unset-all submodule.active
 '
 
+test_expect_success 'is-active and submodule add' '
+	test_when_finished "rm -rf super2" &&
+	git init super2 &&
+	test_commit -C super2 initial &&
+	git -C super2 config --add submodule.active "sub*" &&
+
+	cat >expect <<-\EOF &&
+	sub*
+	EOF
+	git -C super2 submodule add ../sub sub1 &&
+	git -C super2 config --get-all submodule.active >actual &&
+	test_cmp actual expect &&
+
+	cat >expect <<-\EOF &&
+	sub*
+	mod
+	EOF
+	git -C super2 submodule add ../sub mod &&
+	git -C super2 config --get-all submodule.active >actual &&
+	test_cmp actual expect
+'
+
 test_done
-- 
2.11.0.483.g087da7b7c-goog




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]