Skip to content

Commit c89c494

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a4bb55 commit c89c494

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

builtin/submodule--helper.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,17 +2148,22 @@ static int check_name(int argc, const char **argv, const char *prefix)
21482148
static int module_config(int argc, const char **argv, const char *prefix)
21492149
{
21502150
enum {
2151-
CHECK_WRITEABLE = 1
2151+
CHECK_WRITEABLE = 1,
2152+
DO_UNSET = 2
21522153
} command = 0;
21532154

21542155
struct option module_config_options[] = {
21552156
OPT_CMDMODE(0, "check-writeable", &command,
21562157
N_("check if it is safe to write to the .gitmodules file"),
21572158
CHECK_WRITEABLE),
2159+
OPT_CMDMODE(0, "unset", &command,
2160+
N_("unset the config in the .gitmodules file"),
2161+
DO_UNSET),
21582162
OPT_END()
21592163
};
21602164
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>"),
21622167
N_("git submodule--helper config --check-writeable"),
21632168
NULL
21642169
};
@@ -2170,15 +2175,17 @@ static int module_config(int argc, const char **argv, const char *prefix)
21702175
return is_writing_gitmodules_ok() ? 0 : -1;
21712176

21722177
/* Equivalent to ACTION_GET in builtin/config.c */
2173-
if (argc == 2)
2178+
if (argc == 2 && command != DO_UNSET)
21742179
return print_config_from_gitmodules(the_repository, argv[1]);
21752180

21762181
/* 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+
21782185
if (!is_writing_gitmodules_ok())
21792186
die(_("please make sure that the .gitmodules file is in the working tree"));
21802187

2181-
return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
2188+
return config_set_in_gitmodules_file_gently(argv[1], value);
21822189
}
21832190

21842191
usage_with_options(git_submodule_helper_usage, module_config_options);

t/t7411-submodule-config.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ test_expect_success 'reading submodules config from the working tree with "submo
142142
)
143143
'
144144

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+
145154
test_expect_success 'writing submodules config with "submodule--helper config"' '
146155
(cd super &&
147156
echo "new_url" >expect &&

0 commit comments

Comments
 (0)