From 41a813b25075284ff071cff462d04ce642e427d6 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 12 Feb 2026 16:01:58 -0500 Subject: [PATCH] gvfs-helper: create shared object cache if missing Users should be allowed to delete their shared cache and have it recreated on 'git fetch'. This change makes that happen by creating any leading directories and then creating the directory itself with mkdir(). Add a test that exercises --local-cache-path for the first time and checks this scenario. Signed-off-by: Derrick Stolee --- gvfs-helper.c | 14 +++++++++++--- t/t9210-scalar.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/gvfs-helper.c b/gvfs-helper.c index d3903108ad946b..dc8b24f10cef49 100644 --- a/gvfs-helper.c +++ b/gvfs-helper.c @@ -1352,13 +1352,16 @@ static int option_parse_shared_cache_directory(const struct option *opt, */ strbuf_addbuf(&gvfs_shared_cache_pathname, &buf_arg); + /* Attempt to create the directory, in case it doesn't exist. */ + safe_create_leading_directories(the_repository, + gvfs_shared_cache_pathname.buf); + mkdir(gvfs_shared_cache_pathname.buf, 0777); + odb_add_to_alternates_memory(the_repository->objects, buf_arg.buf); strbuf_release(&buf_arg); return 0; - } - - else { + } else { /* * The requested shared-cache is different from the one * we inherited. Replace the inherited value with this @@ -1371,6 +1374,11 @@ static int option_parse_shared_cache_directory(const struct option *opt, strbuf_setlen(&gvfs_shared_cache_pathname, 0); strbuf_addbuf(&gvfs_shared_cache_pathname, &buf_arg); + /* Attempt to create the directory, in case it doesn't exist. */ + safe_create_leading_directories(the_repository, + gvfs_shared_cache_pathname.buf); + mkdir(gvfs_shared_cache_pathname.buf, 0777); + odb_add_to_alternates_memory(the_repository->objects, buf_arg.buf); /* diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index 588a09355b9286..17274e5599ec70 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -455,6 +455,37 @@ test_expect_success '`scalar clone` with GVFS-enabled server' ' ) ' +test_expect_success '`scalar clone` with GVFS-enabled server; local cache path' ' + : the fake cache server requires fake authentication && + git config --global core.askPass true && + + LOCAL_CACHE_BASE="$(pwd)/local" && + + # We must set credential.interactive=true to bypass a setting + # in "scalar clone" that disables interactive credentials during + # an unattended command. + scalar \ + -c credential.interactive=true \ + clone --gvfs-protocol \ + --local-cache-path="$LOCAL_CACHE_BASE" \ + --single-branch -- http://$ORIGIN_HOST_PORT/ with-local && + + : verify that the shared cache has been configured && + cache_key="url_$(printf "%s" http://$ORIGIN_HOST_PORT/ | + tr A-Z a-z | + test-tool sha1)" && + LOCAL_CACHE_DIR="$LOCAL_CACHE_BASE/$cache_key" && + echo "$LOCAL_CACHE_DIR" >expect && + git -C with-local/src config gvfs.sharedCache >actual && + test_cmp expect actual && + + : check the local cache is recreated on fetch && + rm -rf $LOCAL_CACHE_BASE && + git -C with-local fetch && + test_path_is_dir "$LOCAL_CACHE_DIR" && + test_path_is_dir "$LOCAL_CACHE_DIR/pack" +' + . "$TEST_DIRECTORY"/lib-gvfs-helper.sh test_expect_success 'scalar clone: all verbs with different servers' '