From: Johannes Schindelin <johannes.schindelin@xxxxxx> To allow for overriding the default branch name, we have introduced a config setting. With this patch, the `git submodule` command learns about this, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- builtin/submodule--helper.c | 10 ++++++++-- t/t7406-submodule-update.sh | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 46c03d2a126..48d73e8d9cb 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1980,8 +1980,14 @@ static const char *remote_submodule_branch(const char *path) branch = sub->branch; free(key); - if (!branch) - return "master"; + if (!branch) { + static char *fall_back; + + if (!fall_back) + fall_back = git_main_branch_name(MAIN_BRANCH_FOR_INIT); + + return fall_back; + } if (!strcmp(branch, ".")) { const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 4fb447a143e..641113afef4 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -70,6 +70,13 @@ test_expect_success 'setup a submodule tree' ' ) ' +test_expect_success 'update --remote uses configured default main branch' ' + git clone super main-branch && + test_must_fail git -C main-branch -c init.defaultBranch=hello \ + submodule update --init --remote submodule 2>err && + test_i18ngrep origin/hello err +' + test_expect_success 'submodule update detaching the HEAD ' ' (cd super/submodule && git reset --hard HEAD~1 -- gitgitgadget