diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-03-04 10:52:58 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-04 10:52:59 -0800 |
| commit | 1d0a2acb78f157d39937a088548e561b27722e8d (patch) | |
| tree | 4251f1f0f2a4ce4a6ee6f71e75d17d0bdbe4f948 /builtin/worktree.c | |
| parent | 50d063e335afd5828fbb9de2f2b2fb44fd884d2b (diff) | |
| parent | 53592d68e86814fcc4a8df6cc38340597e56fe5a (diff) | |
| download | git-1d0a2acb78f157d39937a088548e561b27722e8d.tar.xz | |
Merge branch 'kn/ref-location'
Allow the directory in which reference backends store their data to
be specified.
* kn/ref-location:
refs: add GIT_REFERENCE_BACKEND to specify reference backend
refs: allow reference location in refstorage config
refs: receive and use the reference storage payload
refs: move out stub modification to generic layer
refs: extract out `refs_create_refdir_stubs()`
setup: don't modify repo in `create_reference_database()`
Diffstat (limited to 'builtin/worktree.c')
| -rw-r--r-- | builtin/worktree.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index 3d6547c23b..38d6fd9027 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -425,6 +425,39 @@ static int make_worktree_orphan(const char * ref, const struct add_opts *opts, return run_command(&cp); } +/* + * References for worktrees are generally stored in '$GIT_DIR/worktrees/<wt_id>'. + * But when using alternate reference directories, we want to store the worktree + * references in '$ALTERNATE_REFERENCE_DIR/worktrees/<wt_id>'. + * + * Create the necessary folder structure to facilitate the same. But to ensure + * that the former path is still considered a Git directory, add stubs. + */ +static void setup_alternate_ref_dir(struct worktree *wt, const char *wt_git_path) +{ + struct strbuf sb = STRBUF_INIT; + char *path; + + path = wt->repo->ref_storage_payload; + if (!path) + return; + + if (!is_absolute_path(path)) + strbuf_addf(&sb, "%s/", wt->repo->commondir); + + strbuf_addf(&sb, "%s/worktrees", path); + safe_create_dir(wt->repo, sb.buf, 1); + strbuf_addf(&sb, "/%s", wt->id); + safe_create_dir(wt->repo, sb.buf, 1); + strbuf_reset(&sb); + + strbuf_addf(&sb, "this worktree stores references in %s/worktrees/%s", + path, wt->id); + refs_create_refdir_stubs(wt->repo, wt_git_path, sb.buf); + + strbuf_release(&sb); +} + static int add_worktree(const char *path, const char *refname, const struct add_opts *opts) { @@ -518,6 +551,7 @@ static int add_worktree(const char *path, const char *refname, ret = error(_("could not find created worktree '%s'"), name); goto done; } + setup_alternate_ref_dir(wt, sb_repo.buf); wt_refs = get_worktree_ref_store(wt); ret = ref_store_create_on_disk(wt_refs, REF_STORE_CREATE_ON_DISK_IS_WORKTREE, &sb); |
