Skip to content

Commit 2502ffc

Browse files
ao2gitster
authored andcommitted
submodule--helper: add a new 'config' subcommand
Add a new 'config' subcommand to 'submodule--helper', this extra level of indirection makes it possible to add some flexibility to how the submodules configuration is handled. Signed-off-by: Antonio Ospite <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 996df4d commit 2502ffc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

builtin/submodule--helper.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,19 @@ static int check_name(int argc, const char **argv, const char *prefix)
20032003
return 0;
20042004
}
20052005

2006+
static int module_config(int argc, const char **argv, const char *prefix)
2007+
{
2008+
/* Equivalent to ACTION_GET in builtin/config.c */
2009+
if (argc == 2)
2010+
return print_config_from_gitmodules(the_repository, argv[1]);
2011+
2012+
/* Equivalent to ACTION_SET in builtin/config.c */
2013+
if (argc == 3)
2014+
return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
2015+
2016+
die("submodule--helper config takes 1 or 2 arguments: name [value]");
2017+
}
2018+
20062019
#define SUPPORT_SUPER_PREFIX (1<<0)
20072020

20082021
struct cmd_struct {
@@ -2030,6 +2043,7 @@ static struct cmd_struct commands[] = {
20302043
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
20312044
{"is-active", is_active, 0},
20322045
{"check-name", check_name, 0},
2046+
{"config", module_config, 0},
20332047
};
20342048

20352049
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)

t/t7411-submodule-config.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,31 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
134134
)
135135
'
136136

137+
test_expect_success 'reading submodules config with "submodule--helper config"' '
138+
(cd super &&
139+
echo "../submodule" >expect &&
140+
git submodule--helper config submodule.submodule.url >actual &&
141+
test_cmp expect actual
142+
)
143+
'
144+
145+
test_expect_success 'writing submodules config with "submodule--helper config"' '
146+
(cd super &&
147+
echo "new_url" >expect &&
148+
git submodule--helper config submodule.submodule.url "new_url" &&
149+
git submodule--helper config submodule.submodule.url >actual &&
150+
test_cmp expect actual
151+
)
152+
'
153+
154+
test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
155+
test_when_finished "git -C super checkout .gitmodules" &&
156+
(cd super &&
157+
echo "newer_url" >expect &&
158+
git submodule--helper config submodule.submodule.url "newer_url" &&
159+
git submodule--helper config submodule.submodule.url >actual &&
160+
test_cmp expect actual
161+
)
162+
'
163+
137164
test_done

0 commit comments

Comments
 (0)