Show 59 quoted lines
> On Sat, Dec 20, 2025 at 12:15:23PM +0200, Adrian Ratiu wrote:
>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
>> index f8cae345a5..5a6436f18f 100644
>> --- a/builtin/submodule--helper.c
>> +++ b/builtin/submodule--helper.c
>> @@ -1266,6 +1266,63 @@ static int module_gitdir(int argc, const char **argv, const char *prefix UNUSED,
>> return 0;
>> }
>>
>> +static int module_migrate(int argc UNUSED, const char **argv UNUSED,
>> + const char *prefix UNUSED, struct repository *repo)
>> +{
>> + struct strbuf module_dir = STRBUF_INIT;
>> + DIR *dir;
>> + struct dirent *de;
>> +
>> + repo_git_path_append(repo, &module_dir, "modules/");
>> +
>> + dir = opendir(module_dir.buf);
>> + if (!dir)
>> + die(_("could not open '%s'"), module_dir.buf);
>> +
>> + while ((de = readdir(dir))) {
>> + struct strbuf gitdir_path = STRBUF_INIT;
>> + char *key;
>> + const char *value;
>> +
>> + if (is_dot_or_dotdot(de->d_name))
>> + continue;
>> +
>> + strbuf_addf(&gitdir_path, "%s/%s", module_dir.buf, de->d_name);
>> + if (!is_git_directory(gitdir_path.buf)) {
>> + strbuf_release(&gitdir_path);
>> + continue;
>> + }
>> + strbuf_release(&gitdir_path);
>> +
>> + key = xstrfmt("submodule.%s.gitdir", de->d_name);
>> + if (!repo_config_get_string_tmp(repo, key, &value)) {
>> + /* Already has a gitdir config, nothing to do. */
>> + free(key);
>> + continue;
>> + }
>> + free(key);
>> +
>> + create_default_gitdir_config(de->d_name);
>> + }
>> +
>> + closedir(dir);
>> + strbuf_release(&module_dir);
>> +
>> + if (repo_config_set_gently(repo, "core.repositoryformatversion", "1"))
>> + die(_("could not set core.repositoryformatversion to 1. "
>> + "Please enable it for migration to work, for example: "
>> + "git config core.repositoryformatversion 1"));
>
> We should probably be careful here to not override the repository format
> version in case it's already greater than 0. We don't have version 2
> yet, but if we ever do this would otherwise need to be changed.