summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-01-08 10:05:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2024-01-08 21:17:30 (GMT)
commit84f0ea956fbd3a3c9989a2d44da27881c0a5f546 (patch)
tree4ca86e286d189818bb77e1185bf7d39bbbc5b9bb
parent2eb1d0c45271faf149a13b61bb74af52abd7b3aa (diff)
downloadgit-84f0ea956fbd3a3c9989a2d44da27881c0a5f546.zip
git-84f0ea956fbd3a3c9989a2d44da27881c0a5f546.tar.gz
git-84f0ea956fbd3a3c9989a2d44da27881c0a5f546.tar.bz2
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/worktree.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 4ac1621..58937a2 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -495,6 +495,10 @@ static int add_worktree(const char *path, const char *refname,
strbuf_realpath(&realpath, get_git_common_dir(), 1);
write_file(sb_git.buf, "gitdir: %s/worktrees/%s",
realpath.buf, name);
+ strbuf_reset(&sb);
+ strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
+ write_file(sb.buf, "../..");
+
/*
* This is to keep resolve_ref() happy. We need a valid HEAD
* 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,
strbuf_reset(&sb);
strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
write_file(sb.buf, "%s", oid_to_hex(null_oid()));
- strbuf_reset(&sb);
- strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
- write_file(sb.buf, "../..");
/*
* If the current worktree has sparse-checkout enabled, then copy