submodule--helper: teach config subcommand --unset

This teaches submodule--helper config the --unset option, which removes the specified configuration key from the .gitmodule file. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Feb 8, 2019 at 03:21 UTC c89c494240a516b082f397130ae44df2e757866b
2 files changed +21 -5
builtin/submodule--helper.c
+12 -5
@@ -2148,17 +2148,22 @@ static int check_name(int argc, const char **argv, const char *prefix)
2148 static int module_config(int argc, const char **argv, const char *prefix)
2149 {
2150 enum {
2151 - CHECK_WRITEABLE = 1
2151 + CHECK_WRITEABLE = 1,
2152 + DO_UNSET = 2
2153 } command = 0;
2154
2155 struct option module_config_options[] = {
2156 OPT_CMDMODE(0, "check-writeable", &command,
2157 N_("check if it is safe to write to the .gitmodules file"),
2158 CHECK_WRITEABLE),
2159 + OPT_CMDMODE(0, "unset", &command,
2160 + N_("unset the config in the .gitmodules file"),
2161 + DO_UNSET),
2162 OPT_END()
2163 };
2164 const char *const git_submodule_helper_usage[] = {
2161 - N_("git submodule--helper config name [value]"),
2165 + N_("git submodule--helper config <name> [<value>]"),
2166 + N_("git submodule--helper config --unset <name>"),
2167 N_("git submodule--helper config --check-writeable"),
2168 NULL
2169 };
@@ -2170,15 +2175,17 @@ static int module_config(int argc, const char **argv, const char *prefix)
2175 return is_writing_gitmodules_ok() ? 0 : -1;
2176
2177 /* Equivalent to ACTION_GET in builtin/config.c */
2173 - if (argc == 2)
2178 + if (argc == 2 && command != DO_UNSET)
2179 return print_config_from_gitmodules(the_repository, argv[1]);
2180
2181 /* Equivalent to ACTION_SET in builtin/config.c */
2177 - if (argc == 3) {
2182 + if (argc == 3 || (argc == 2 && command == DO_UNSET)) {
2183 + const char *value = (argc == 3) ? argv[2] : NULL;
2184 +
2185 if (!is_writing_gitmodules_ok())
2186 die(_("please make sure that the .gitmodules file is in the working tree"));
2187
2181 - return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
2188 + return config_set_in_gitmodules_file_gently(argv[1], value);
2189 }
2190
2191 usage_with_options(git_submodule_helper_usage, module_config_options);
t/t7411-submodule-config.sh
+9
@@ -142,6 +142,15 @@ test_expect_success 'reading submodules config from the working tree with "submo
142 )
143 '
144
145 +test_expect_success 'unsetting submodules config from the working tree with "submodule--helper config --unset"' '
146 + (cd super &&
147 + git submodule--helper config --unset submodule.submodule.url &&
148 + git submodule--helper config submodule.submodule.url >actual &&
149 + test_must_be_empty actual
150 + )
151 +'
152 +
153 +
154 test_expect_success 'writing submodules config with "submodule--helper config"' '
155 (cd super &&
156 echo "new_url" >expect &&