builtin/submodule--helper: add gitdir command
This exposes the gitdir name computed by submodule_name_to_gitdir() internally, to make it easier for users and tests to interact with it. Next commit will add a gitdir configuration, so this helper can also be used to easily query that config or validate any gitdir path the user sets (submodule_name_to_git_dir now runs the validation logic, since our previous commit). Based-on-patch-by: Brandon Williams <bwilliams.eng@gmail.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Adrian Ratiu committed
Jan 12, 2026 at 20:46 UTC
34206caaf7c5059ac8480587e31cfc40473002b4
1 file changed
+17
builtin/submodule--helper.c
+17
@@ -1208,6 +1208,22 @@ static int module_summary(int argc, const char **argv, const char *prefix,
1208
return ret;
1209
}
1210
1211
+static int module_gitdir(int argc, const char **argv, const char *prefix UNUSED,
1212
+ struct repository *repo)
1213
+{
1214
+ struct strbuf gitdir = STRBUF_INIT;
1215
+
1216
+ if (argc != 2)
1217
+ usage(_("git submodule--helper gitdir <name>"));
1218
+
1219
+ submodule_name_to_gitdir(&gitdir, repo, argv[1]);
1220
+
1221
+ printf("%s\n", gitdir.buf);
1222
+
1223
+ strbuf_release(&gitdir);
1224
+ return 0;
1225
+}
1226
+
1227
struct sync_cb {
1228
const char *prefix;
1229
const char *super_prefix;
@@ -3587,6 +3603,7 @@ int cmd_submodule__helper(int argc,
3603
NULL
3604
};
3605
struct option options[] = {
3606
+ OPT_SUBCOMMAND("gitdir", &fn, module_gitdir),
3607
OPT_SUBCOMMAND("clone", &fn, module_clone),
3608
OPT_SUBCOMMAND("add", &fn, module_add),
3609
OPT_SUBCOMMAND("update", &fn, module_update),