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 <ao2@ao2.it> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Antonio Ospite committed
Oct 5, 2018 at 15:05 UTC
2502ffc0cf3c4db2a3cad13415a118b4becce0dd
2 files changed
+41
builtin/submodule--helper.c
+14
@@ -2003,6 +2003,19 @@ static int check_name(int argc, const char **argv, const char *prefix)
2003
return 0;
2004
}
2005
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
+
2019
#define SUPPORT_SUPER_PREFIX (1<<0)
2020
2021
struct cmd_struct {
@@ -2030,6 +2043,7 @@ static struct cmd_struct commands[] = {
2043
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
2044
{"is-active", is_active, 0},
2045
{"check-name", check_name, 0},
2046
+ {"config", module_config, 0},
2047
};
2048
2049
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
t/t7411-submodule-config.sh
+27
@@ -134,4 +134,31 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
134
)
135
'
136
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
+
164
test_done