Skip to content

Commit 84f0ea9

Browse files
pks-tgitster
authored andcommitted
builtin/worktree: move setup of commondir file earlier
Shuffle around how we create supporting worktree files so that we first ensure that the worktree has all link files ("gitdir", "commondir") before we try to initialize the ref database by writing "HEAD". This will be required by a subsequent commit where we start to initialize the ref database via `refs_init_db()`, which will require an initialized `struct worktree *`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2eb1d0c commit 84f0ea9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/worktree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ static int add_worktree(const char *path, const char *refname,
495495
strbuf_realpath(&realpath, get_git_common_dir(), 1);
496496
write_file(sb_git.buf, "gitdir: %s/worktrees/%s",
497497
realpath.buf, name);
498+
strbuf_reset(&sb);
499+
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
500+
write_file(sb.buf, "../..");
501+
498502
/*
499503
* This is to keep resolve_ref() happy. We need a valid HEAD
500504
* or is_git_directory() will reject the directory. Any value which
@@ -505,9 +509,6 @@ static int add_worktree(const char *path, const char *refname,
505509
strbuf_reset(&sb);
506510
strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
507511
write_file(sb.buf, "%s", oid_to_hex(null_oid()));
508-
strbuf_reset(&sb);
509-
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
510-
write_file(sb.buf, "../..");
511512

512513
/*
513514
* If the current worktree has sparse-checkout enabled, then copy

0 commit comments

Comments
 (0)