Skip to content

Commit cc74a4a

Browse files
avarttaylorr
authored andcommitted
submodule--helper: move "config" to a test-tool
As with other moves to "test-tool" in f322e9f (Merge branch 'ab/submodule-helper-prep', 2022-09-13) the "config" sub-command was only used by our own tests. It was last used by "git submodule" itself in code that went away with a6226fd (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10). Let's move it over, and while doing so make it easier to reason about by splitting up the various uses for it into separate sub-commands, so that we don't need to count arguments to see what it does. This also has the advantage that we stop wasting future translator time on this command, currently the usage information for this internal-only tool has been translated into several languages. The use of the "_" function has also been removed from the "please make sure..." message. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent c03801e commit cc74a4a

File tree

4 files changed

+104
-66
lines changed

4 files changed

+104
-66
lines changed

builtin/submodule--helper.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,51 +2861,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
28612861
return ret;
28622862
}
28632863

2864-
static int module_config(int argc, const char **argv, const char *prefix)
2865-
{
2866-
enum {
2867-
CHECK_WRITEABLE = 1,
2868-
DO_UNSET = 2
2869-
} command = 0;
2870-
struct option module_config_options[] = {
2871-
OPT_CMDMODE(0, "check-writeable", &command,
2872-
N_("check if it is safe to write to the .gitmodules file"),
2873-
CHECK_WRITEABLE),
2874-
OPT_CMDMODE(0, "unset", &command,
2875-
N_("unset the config in the .gitmodules file"),
2876-
DO_UNSET),
2877-
OPT_END()
2878-
};
2879-
const char *const git_submodule_helper_usage[] = {
2880-
N_("git submodule--helper config <name> [<value>]"),
2881-
N_("git submodule--helper config --unset <name>"),
2882-
"git submodule--helper config --check-writeable",
2883-
NULL
2884-
};
2885-
2886-
argc = parse_options(argc, argv, prefix, module_config_options,
2887-
git_submodule_helper_usage, PARSE_OPT_KEEP_ARGV0);
2888-
2889-
if (argc == 1 && command == CHECK_WRITEABLE)
2890-
return is_writing_gitmodules_ok() ? 0 : -1;
2891-
2892-
/* Equivalent to ACTION_GET in builtin/config.c */
2893-
if (argc == 2 && command != DO_UNSET)
2894-
return print_config_from_gitmodules(the_repository, argv[1]);
2895-
2896-
/* Equivalent to ACTION_SET in builtin/config.c */
2897-
if (argc == 3 || (argc == 2 && command == DO_UNSET)) {
2898-
const char *value = (argc == 3) ? argv[2] : NULL;
2899-
2900-
if (!is_writing_gitmodules_ok())
2901-
die(_("please make sure that the .gitmodules file is in the working tree"));
2902-
2903-
return config_set_in_gitmodules_file_gently(argv[1], value);
2904-
}
2905-
2906-
usage_with_options(git_submodule_helper_usage, module_config_options);
2907-
}
2908-
29092864
static int module_set_url(int argc, const char **argv, const char *prefix)
29102865
{
29112866
int quiet = 0;
@@ -3424,7 +3379,6 @@ static struct cmd_struct commands[] = {
34243379
{"summary", module_summary, 0},
34253380
{"push-check", push_check, 0},
34263381
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
3427-
{"config", module_config, 0},
34283382
{"set-url", module_set_url, 0},
34293383
{"set-branch", module_set_branch, 0},
34303384
{"create-branch", module_create_branch, 0},

t/helper/test-submodule.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,94 @@ static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
111111
return 0;
112112
}
113113

114+
static int cmd__submodule_config_list(int argc, const char **argv)
115+
{
116+
struct option options[] = {
117+
OPT_END()
118+
};
119+
const char *const usage[] = {
120+
"test-tool submodule config-list <key>",
121+
NULL
122+
};
123+
argc = parse_options(argc, argv, "test-tools", options, usage,
124+
PARSE_OPT_KEEP_ARGV0);
125+
126+
setup_git_directory();
127+
128+
if (argc == 2)
129+
return print_config_from_gitmodules(the_repository, argv[1]);
130+
usage_with_options(usage, options);
131+
}
132+
133+
static int cmd__submodule_config_set(int argc, const char **argv)
134+
{
135+
struct option options[] = {
136+
OPT_END()
137+
};
138+
const char *const usage[] = {
139+
"test-tool submodule config-set <key> <value>",
140+
NULL
141+
};
142+
argc = parse_options(argc, argv, "test-tools", options, usage,
143+
PARSE_OPT_KEEP_ARGV0);
144+
145+
setup_git_directory();
146+
147+
/* Equivalent to ACTION_SET in builtin/config.c */
148+
if (argc == 3) {
149+
if (!is_writing_gitmodules_ok())
150+
die("please make sure that the .gitmodules file is in the working tree");
151+
152+
return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
153+
}
154+
usage_with_options(usage, options);
155+
}
156+
157+
static int cmd__submodule_config_unset(int argc, const char **argv)
158+
{
159+
struct option options[] = {
160+
OPT_END()
161+
};
162+
const char *const usage[] = {
163+
"test-tool submodule config-unset <key>",
164+
NULL
165+
};
166+
167+
setup_git_directory();
168+
169+
if (argc == 2) {
170+
if (!is_writing_gitmodules_ok())
171+
die("please make sure that the .gitmodules file is in the working tree");
172+
return config_set_in_gitmodules_file_gently(argv[1], NULL);
173+
}
174+
usage_with_options(usage, options);
175+
}
176+
177+
static int cmd__submodule_config_writeable(int argc, const char **argv)
178+
{
179+
struct option options[] = {
180+
OPT_END()
181+
};
182+
const char *const usage[] = {
183+
"test-tool submodule config-writeable",
184+
NULL
185+
};
186+
setup_git_directory();
187+
188+
if (argc == 1)
189+
return is_writing_gitmodules_ok() ? 0 : -1;
190+
191+
usage_with_options(usage, options);
192+
}
193+
114194
static struct test_cmd cmds[] = {
115195
{ "check-name", cmd__submodule_check_name },
116196
{ "is-active", cmd__submodule_is_active },
117197
{ "resolve-relative-url", cmd__submodule_resolve_relative_url},
198+
{ "config-list", cmd__submodule_config_list },
199+
{ "config-set", cmd__submodule_config_set },
200+
{ "config-unset", cmd__submodule_config_unset },
201+
{ "config-writeable", cmd__submodule_config_writeable },
118202
};
119203

120204
int cmd__submodule(int argc, const char **argv)

t/t7411-submodule-config.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,44 +137,44 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
137137
)
138138
'
139139

140-
test_expect_success 'reading submodules config from the working tree with "submodule--helper config"' '
140+
test_expect_success 'reading submodules config from the working tree' '
141141
(cd super &&
142142
echo "../submodule" >expect &&
143-
git submodule--helper config submodule.submodule.url >actual &&
143+
test-tool submodule config-list submodule.submodule.url >actual &&
144144
test_cmp expect actual
145145
)
146146
'
147147

148-
test_expect_success 'unsetting submodules config from the working tree with "submodule--helper config --unset"' '
148+
test_expect_success 'unsetting submodules config from the working tree' '
149149
(cd super &&
150-
git submodule--helper config --unset submodule.submodule.url &&
151-
git submodule--helper config submodule.submodule.url >actual &&
150+
test-tool submodule config-unset submodule.submodule.url &&
151+
test-tool submodule config-list submodule.submodule.url >actual &&
152152
test_must_be_empty actual
153153
)
154154
'
155155

156156

157-
test_expect_success 'writing submodules config with "submodule--helper config"' '
157+
test_expect_success 'writing submodules config' '
158158
(cd super &&
159159
echo "new_url" >expect &&
160-
git submodule--helper config submodule.submodule.url "new_url" &&
161-
git submodule--helper config submodule.submodule.url >actual &&
160+
test-tool submodule config-set submodule.submodule.url "new_url" &&
161+
test-tool submodule config-list submodule.submodule.url >actual &&
162162
test_cmp expect actual
163163
)
164164
'
165165

166-
test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
166+
test_expect_success 'overwriting unstaged submodules config' '
167167
test_when_finished "git -C super checkout .gitmodules" &&
168168
(cd super &&
169169
echo "newer_url" >expect &&
170-
git submodule--helper config submodule.submodule.url "newer_url" &&
171-
git submodule--helper config submodule.submodule.url >actual &&
170+
test-tool submodule config-set submodule.submodule.url "newer_url" &&
171+
test-tool submodule config-list submodule.submodule.url >actual &&
172172
test_cmp expect actual
173173
)
174174
'
175175

176176
test_expect_success 'writeable .gitmodules when it is in the working tree' '
177-
git -C super submodule--helper config --check-writeable
177+
test-tool -C super submodule config-writeable
178178
'
179179

180180
test_expect_success 'writeable .gitmodules when it is nowhere in the repository' '
@@ -183,15 +183,15 @@ test_expect_success 'writeable .gitmodules when it is nowhere in the repository'
183183
(cd super &&
184184
git rm .gitmodules &&
185185
git commit -m "remove .gitmodules from the current branch" &&
186-
git submodule--helper config --check-writeable
186+
test-tool submodule config-writeable
187187
)
188188
'
189189

190190
test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' '
191191
test_when_finished "git -C super checkout .gitmodules" &&
192192
(cd super &&
193193
rm -f .gitmodules &&
194-
test_must_fail git submodule--helper config --check-writeable
194+
test_must_fail test-tool submodule config-writeable
195195
)
196196
'
197197

@@ -200,19 +200,19 @@ test_expect_success 'non-writeable .gitmodules when it is in the current branch
200200
test_when_finished "git -C super reset --hard $ORIG" &&
201201
(cd super &&
202202
git rm .gitmodules &&
203-
test_must_fail git submodule--helper config --check-writeable
203+
test_must_fail test-tool submodule config-writeable
204204
)
205205
'
206206

207207
test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' '
208208
ORIG=$(git -C super rev-parse HEAD) &&
209209
test_when_finished "git -C super reset --hard $ORIG" &&
210210
(cd super &&
211-
git submodule--helper config submodule.submodule.url "staged_url" &&
211+
test-tool submodule config-set submodule.submodule.url "staged_url" &&
212212
git add .gitmodules &&
213213
rm -f .gitmodules &&
214214
echo "staged_url" >expect &&
215-
git submodule--helper config submodule.submodule.url >actual &&
215+
test-tool submodule config-list submodule.submodule.url >actual &&
216216
test_cmp expect actual
217217
)
218218
'
@@ -223,7 +223,7 @@ test_expect_success 'reading submodules config from the current branch when .git
223223
(cd super &&
224224
git rm .gitmodules &&
225225
echo "../submodule" >expect &&
226-
git submodule--helper config submodule.submodule.url >actual &&
226+
test-tool submodule config-list submodule.submodule.url >actual &&
227227
test_cmp expect actual
228228
)
229229
'

t/t7418-submodule-sparse-gitmodules.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ test_expect_success 'sparse checkout setup which hides .gitmodules' '
5050

5151
test_expect_success 'reading gitmodules config file when it is not checked out' '
5252
echo "../submodule" >expect &&
53-
git -C super submodule--helper config submodule.submodule.url >actual &&
53+
test-tool -C super submodule config-list submodule.submodule.url >actual &&
5454
test_cmp expect actual
5555
'
5656

5757
test_expect_success 'not writing gitmodules config file when it is not checked out' '
58-
test_must_fail git -C super submodule--helper config submodule.submodule.url newurl &&
58+
test_must_fail test-tool -C super submodule config-set submodule.submodule.url newurl &&
5959
test_path_is_missing super/.gitmodules
6060
'
6161

0 commit comments

Comments
 (0)