]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/worktree: move setup of commondir file earlier
authorPatrick Steinhardt <ps@pks.im>
Mon, 8 Jan 2024 10:05:39 +0000 (11:05 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Jan 2024 21:17:30 +0000 (13:17 -0800)
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>
builtin/worktree.c

index 4ac16215416a004e9e0a5db321fa6d56c7f6c9ab..58937a2a680d1fb451c6d6a5c186cee65ca322a8 100644 (file)
@@ -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