[PATCH 5/7] builtin/clone: don't apply "core.sharedRepository" to leading dirs
From: Patrick Steinhardt <hidden>
Date: 2026-09-24 09:19:48
Subsystem:
the rest · Maintainer:
Linus Torvalds
When creating a repository via git-clone(1) we create leading directories with `safe_create_leading_directories()`. We have adapted git-init(1) in a preceding commit to instead use the variant of this function that doesn't honor "core.sharedRepository". In that subcommand it didn't have an effect though as we explicitly unset the value of that configuration anyway, so we never honored that config. In git-clone(1) it's a bit of a different thing though: while the repository isn't initialized at the point in time where we call the function, we didn't explicitly unset the value. Consequently we _do_ honor the configuration here, but when it's configured in global- or system-level scope. This divergence doesn't seem to be intentional -- I cannot think of any good reason why git-init(1) and git-clone(1) should have divergent behaviour here. Adapt git-clone(1) to work the same as git-init(1) by also using the `no_share()` variants to create leading directories. Add tests for both commands. Signed-off-by: Patrick Steinhardt <redacted> --- builtin/clone.c | 4 ++-- t/t1301-shared-repo.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index b14264c33a..e72f8aa325 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c@@ -1133,7 +1133,7 @@ int cmd_clone(int argc, sigchain_push_common(remove_junk_on_signal); if (!option_bare) { - if (safe_create_leading_directories_const(the_repository, work_tree) < 0) + if (safe_create_leading_directories_no_share_const(work_tree) < 0) die_errno(_("could not create leading directories of '%s'"), work_tree); if (dest_exists)
@@ -1153,7 +1153,7 @@ int cmd_clone(int argc, junk_git_dir_flags |= REMOVE_DIR_KEEP_TOPLEVEL; junk_git_dir = git_dir; } - if (safe_create_leading_directories_const(the_repository, git_dir) < 0) + if (safe_create_leading_directories_no_share_const(git_dir) < 0) die(_("could not create leading directories of '%s'"), git_dir); if (0 <= option_verbosity) {
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index 0e0d07a1a1..3bc4bdb038 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh@@ -210,4 +210,46 @@ test_expect_success POSIXPERM 'template can set core.sharedrepository' ' test_cmp expect actual ' +test_expect_success POSIXPERM 'init does not apply core.sharedRepository to leading directories' ' + test_config_global core.sharedRepository 0666 && + umask 0077 && + test_when_finished "rm -rf dst" && + git init --bare dst/with/leading/dirs && + cat >expect <<-\EOF && + drwx------ + drwx------ + drwx------ + drwxrwxrwx + EOF + { + test_modebits dst && + test_modebits dst/with && + test_modebits dst/with/leading && + test_modebits dst/with/leading/dirs + } >actual && + test_cmp expect actual +' + +test_expect_success POSIXPERM 'clone does not apply core.sharedRepository to leading directories' ' + test_config_global core.sharedRepository 0666 && + umask 0077 && + test_when_finished "rm -rf source dst" && + git init source && + test_commit -C source initial && + git clone --bare source dst/with/leading/dirs && + cat >expect <<-\EOF && + drwx------ + drwx------ + drwx------ + drwxrwxrwx + EOF + { + test_modebits dst && + test_modebits dst/with && + test_modebits dst/with/leading && + test_modebits dst/with/leading/dirs + } >actual && + test_cmp expect actual +' + test_done
--
2.56.0.rc2.329.gd58861e689.dirty