From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796245619; b=S3cQBFKtStbQ1Dd+FTEtdKOPj5w/S+9zpE3IAZETGo0j2D+2VGwcmzAO0kcEJ2Dms79X 3d2FSQjL0JbD5XX2C/hXb5IuwTPchMaajez0PJxUejpzgX4KziWNmgWAxUeAinRi2/kTO qtgW6aAQiKOpWVBeUYrfAKJHUKVd1DY3NXqDtgzV5rRBw3FSYwgtXOYH+jiUIhO85sCIZ wI4wLkJ7iFVnsKnhlXzz2XL3vYPUBJ9hyT8DJLlzRl+C3A0y1sWIIg47tG5OyPedsRrTQ dNVrh5qoxVYkIm3R7kA0u9WTP8InKsWfUnhIKQf9o/cFiW42x/SVfkge0ljcoOyNmug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796245619; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=iWJ0Rc5QoBU3/Q/Ik0EuwkNRkNI6q7mEzaGahPri0F4=; b=zFtLl0bxrYmylWwOz9hKoa1YSKGczvLTEuaUCAoQfMWL2UP8k0zDtouPMbMAOs7VOx2x TKRxA7LZ8K0e/OjoJUWZQqukDBdLSpWwmAPHCisQzDJ2ciIkmHTW+DqJIKO70AjT3td0M NY7d3KZ+8NWRdrRMh6V6jCSo8S5LApF/ARPdqcV0ym17GCbeANtpbJj6pbSHjeZ5SX9RY AAaR+SSbE0sntcfdYtbF6bsHbYFdcAhDWftaTLtmL3XxxEOfxlfJLpopMwbQtsNyt5oWq CCY7mVKogqWfrTxnbsDhefoc3LlhInPeH8i5oBbr2gxd/33+uYc/iYXNdwXX3C4tZFA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Nd3bVy6T; arc=none smtp.remote-ip=74.125.82.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A86CC606A336 for ; Wed, 2 Dec 2026 21:06:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A86CC606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Nd3bVy6T Received: by mail-dl1-f43.google.com with SMTP id a92af1059eb24-1b589050416so7171204c88.0 for ; Wed, 02 Dec 2026 13:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796245618; x=1796850418; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=iWJ0Rc5QoBU3/Q/Ik0EuwkNRkNI6q7mEzaGahPri0F4=; b=Nd3bVy6TpJzUWcpLfHZdzjnqwF7S9jboJAvw7r+uhSDFUR3U1YKKghrYLh+vul/bsf kRuCAR0JLM8hcA0Ft2VSUJ+TkZ69EbZsL8FYOylWzXQnJHofnm421v2h1waHsKiaviYh cVYvrL/CjtncqCBR+6iLcxk6GlB3R3DFFUobYFroUYsiJSwRhMIvxmpmV12txxERBwl6 NayV2ckup2AmqwZ5fYFV6IvRIPKqX4NORUqNsCTFSGKZOM7l8wlFkSqXNaopiAshd8KB XSOc2EpvQ8JMKp93Fh4LENOtoNb51h7M/NyR4DWH1QwtkJRyxxNAlk19IFJK6UAcFTE3 QYCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796245618; x=1796850418; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=iWJ0Rc5QoBU3/Q/Ik0EuwkNRkNI6q7mEzaGahPri0F4=; b=cCFtGXeGFbXCsQ2nfyovORvFkxVjzC9q86nkxWUjiUhWP56dIcdDOIFBBBdapR+uWU 9FicMBH1usTOXMbKmmcqOR7IXfZQuBKY5c2i4CWDMH/yowk1lSjvyaJBCSo4MG4M84LH XbtkCpNSl9oB2Tkn2kgAMjKbf5aUjWDf4ed+AY/2unzmZ8nw3muv4Hn41uaBYMgJjNJR ckAIuj4B8VTncdFon/pOZOwwiqxEKkt2mgO4zuUL+jeebu4C3XNCQsJn5fag5CWlqMRQ oo3+H6bHKORhRtMCOWKQVBQX/fV9mg91etNFN2tro/Mc2nCdSmUMrqRl+PBPOo+G0cXn It7A== X-Gm-Message-State: APuU4Z9JTSI4WDRLvVAUJhmcYef9LlC4HdJKbZQcB+flYBXG1w0FQKWM V5SqBrTlUYakUoOq7J4cPm5MI6O7cpVeCjHNu7enzbkUcNeBO3iwgC4Net1xTjZ7 X-Gm-Gg: AZFdTZcNap2fjDZEjIF8TdvFQSwrkwvX6gBgwF7H1A3zFmZMRsQVOn/RXnxM5IxSUUx SJG85E/h+Riz8XdJ+Y20jp5f7CzFu3DxDArHPH0MCOv7qL6UTaj4IfAxg4Nfd11t6GLO9yFH+qN AoTmpF0Fv8j//vEnG79cDdSe6t1G1AND9s6lw5w0ncdsOaA6WXQPKV/MJr7o+ly0DjjKjATBEdL ksSnwco7EL/kJl9oiIB9fpx8U1uTyd3A0CeAarEMx2nUf6kiAyQFmKHFfNmz9H5hE1V2ClEvh1o SCFE8FkxQA02AGvbbhLvJrmBVNdGDeDNokTZY18ihaXwPWjS29DbLzU67SICXbChvepXG8qZnH9 N2M+SUDzv0j6lZvyuqHMXCpx9BwPs0LP5fL6r1HidsR4JnK+fbhprZr3wqLkNakdLLgFs4wseKb OWV6lkdzVV9rXVgUJcakogqvBtWktfQsPP1Klv+kaEmoWUC5NStsYVfctt19zM2+CavQnpdbaIL MV1V++yRegPWLv0sL9fCgeDWkHqWiGBE7QpZ8LsK3rkYqyc6g/7sHSZwQ3QrEOkRY1kbh0uSlON 3JxUZy0tUwerfETT/F4PV3zRPMt7rDc= X-Received: by 2002:a05:7022:1585:b0:147:8a40:cdf3 with SMTP id a92af1059eb24-1b5568f00a6mr38939585c88.24.1796245617474; Wed, 02 Dec 2026 13:06:57 -0800 (PST) Received: from [127.0.0.1] ([20.171.22.246]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556840494sm95282570c88.12.2026.12.02.13.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 13:06:56 -0800 (PST) Message-Id: In-Reply-To: References: From: "Yoichi NAKAYAMA via GitGitGadget" Date: Wed, 02 Dec 2026 21:06:51 +0000 Subject: [PATCH v4 3/4] submodule: store settings in worktree config when enabled Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Yoichi NAKAYAMA , Yoichi NAKAYAMA , Yoichi NAKAYAMA From: Yoichi NAKAYAMA Submodule URLs can differ between branches. For example, one branch may use the upstream repository while another uses a fork for the same submodule. When these branches are checked out in separate worktrees, storing `submodule..url` in the shared repository config prevents each worktree from using its own URL. Store submodule settings such as `submodule..active` and `submodule..url` in the worktree config when `extensions.worktreeConfig` is enabled. Settings shared between worktrees can remain in the repository config. When such a setting exists there, 'git submodule deinit' sets `submodule..active` to false in the worktree config to unregister the submodule. Unlike other settings, `submodule..gitdir` must not be shared between worktrees. Different commits in the superproject may record different commits for the same submodule. If the gitdir is shared, the submodule worktrees end up sharing the same `HEAD` and index, causing Git commands to behave incorrectly. Therefore, store this setting in the worktree config and exclude it from the config copied by 'git worktree add'. Signed-off-by: Yoichi NAKAYAMA --- Documentation/config/extensions.adoc | 9 ++ Documentation/config/submodule.adoc | 13 +- Documentation/gitsubmodules.adoc | 26 +++- builtin/submodule--helper.c | 43 +++--- builtin/worktree.c | 23 +++ t/t2405-worktree-submodule.sh | 157 +++++++++++++++++++++ t/t7425-submodule-gitdir-path-extension.sh | 49 +++++++ 7 files changed, 296 insertions(+), 24 deletions(-) diff --git a/Documentation/config/extensions.adoc b/Documentation/config/extensions.adoc index 4f3a66a454..5dc6475cfe 100644 --- a/Documentation/config/extensions.adoc +++ b/Documentation/config/extensions.adoc @@ -169,5 +169,14 @@ these config values on a per-worktree basis, and uses the worktree independently. See linkgit:git-sparse-checkout[1] for more details. + +Submodule configuration is also affected by this extension. +The `submodule..gitdir` variable must be worktree-specific, as +each worktree must use a separate gitdir for the same submodule. +Other submodule configuration variables may be shared between worktrees, +but Git commands that update submodule configuration store these +variables in the worktree-specific `config.worktree` file when this +extension is enabled, so that each worktree can have its own submodule +configuration. ++ For historical reasons, this extension is respected regardless of the `core.repositoryFormatVersion` setting. diff --git a/Documentation/config/submodule.adoc b/Documentation/config/submodule.adoc index 4c424017b4..6931888b71 100644 --- a/Documentation/config/submodule.adoc +++ b/Documentation/config/submodule.adoc @@ -6,6 +6,9 @@ submodule..url:: set, the presence of this variable is used as a fallback to indicate whether the submodule is of interest to git commands. See linkgit:git-submodule[1] and linkgit:gitmodules[5] for details. + When `extensions.worktreeConfig` is enabled, 'git submodule init' and + 'git submodule sync' store this setting in each worktree's config. + See linkgit:git-config[1] for details. submodule..update:: The method by which a submodule is updated by 'git submodule update', @@ -16,6 +19,9 @@ submodule..update:: and `pull.rebase` are more specific. It is populated by `git submodule init` from the linkgit:gitmodules[5] file. See description of 'update' command in linkgit:git-submodule[1]. + When `extensions.worktreeConfig` is enabled, 'git submodule init' stores + this setting in each worktree's config. See linkgit:git-config[1] for + details. submodule..branch:: The remote branch name for a submodule, used by `git submodule @@ -52,13 +58,18 @@ submodule..active:: commands. This config option takes precedence over the submodule.active config option. See linkgit:gitsubmodules[7] for details. + When `extensions.worktreeConfig` is enabled, 'git submodule init' stores + this setting in each worktree's config. See linkgit:git-config[1] for + details. submodule..gitdir:: This sets the gitdir path for submodule . This configuration is respected when `extensions.submodulePathConfig` is enabled, otherwise it has no effect. When enabled, this config becomes the single source of truth for submodule gitdir paths and Git will error if it is missing. - See linkgit:git-config[1] for details. + When `extensions.worktreeConfig` is enabled, 'git submodule init' stores + this setting in each worktree's config. See linkgit:git-config[1] for + details. submodule.active:: A repeated field which contains a pathspec used to match against a diff --git a/Documentation/gitsubmodules.adoc b/Documentation/gitsubmodules.adoc index 8e8165637b..a18d565bc6 100644 --- a/Documentation/gitsubmodules.adoc +++ b/Documentation/gitsubmodules.adoc @@ -102,8 +102,9 @@ check if the submodule has any changes not published to any remote. The remotes are configured in the submodule as usual in the `$GIT_DIR/config` file. - * The configuration file `$GIT_DIR/config` in the superproject. - Git only recurses into active submodules + * The configuration files `$GIT_DIR/config` and, when the + `extensions.worktreeConfig` extension is enabled, `$GIT_DIR/config.worktree` + in the superproject. Git only recurses into active submodules (see <> section below). + If the submodule is not yet initialized, then the configuration @@ -123,6 +124,21 @@ If the submodule has never been initialized, this is the only place where submodule configuration is found. It serves as the last fallback to specify where to obtain the submodule from. +MULTIPLE WORKTREES +------------------ + +When using multiple worktrees, it is recommended to enable the +`extensions.worktreeConfig` extension. Without this extension, +submodule configuration is shared between worktrees, which can +cause unexpected interactions. For example, if different branches +use different URLs for a submodule, a URL configured in one +worktree may be used by another worktree, preventing it from +fetching the required commits. + +Enabling this extension allows Git commands to store submodule +configuration in each worktree's `config.worktree` file, keeping +the configuration independent between worktrees. + [[FORMS]] FORMS ----- @@ -150,8 +166,10 @@ The directory which is supposed to be the working directory is empty instead. + A submodule can be deinitialized by running `git submodule deinit`. Besides emptying the working directory, this command only modifies -the superproject's `$GIT_DIR/config` file, so the superproject's history -is not affected. This can be undone using `git submodule init`. +the superproject's configuration file (`$GIT_DIR/config` or +`$GIT_DIR/config.worktree`, depending on whether the +`extensions.worktreeConfig` extension is enabled), so the superproject's +history is not affected. This can be undone using `git submodule init`. * Deleted submodule: A submodule can be deleted by running `git rm && git commit`. This can be undone diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9faa532854..34783c71d1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -497,7 +497,7 @@ static int validate_and_set_submodule_gitdir(struct strbuf *gitdir_path, return 0; } - if (repo_config_set_gently(the_repository, key, gitdir_path->buf)) { + if (repo_config_set_worktree_gently(the_repository, key, gitdir_path->buf)) { free(key); return -1; } @@ -610,15 +610,10 @@ static void init_submodule(const char *path, const char *prefix, die(_("No url found for submodule path '%s' in .gitmodules"), displaypath); - /* - * NEEDSWORK: In a multi-working-tree world, this needs to be - * set in the per-worktree config. - * - * Set active flag for the submodule being initialized - */ + /* Set active flag for the submodule being initialized */ if (!is_submodule_active(the_repository, path)) { strbuf_addf(&sb, "submodule.%s.active", sub->name); - repo_config_set_gently(the_repository, sb.buf, "true"); + repo_config_set_worktree_gently(the_repository, sb.buf, "true"); strbuf_reset(&sb); } @@ -644,7 +639,7 @@ static void init_submodule(const char *path, const char *prefix, free(oldurl); } - if (repo_config_set_gently(the_repository, sb.buf, url)) + if (repo_config_set_worktree_gently(the_repository, sb.buf, url)) die(_("Failed to register url for submodule path '%s'"), displaypath); if (!(flags & OPT_QUIET)) @@ -666,7 +661,7 @@ static void init_submodule(const char *path, const char *prefix, upd = submodule_update_type_to_string(sub->update_strategy.type); } - if (repo_config_set_gently(the_repository, sb.buf, upd)) + if (repo_config_set_worktree_gently(the_repository, sb.buf, upd)) die(_("Failed to register update mode for submodule path '%s'"), displaypath); } @@ -1492,7 +1487,7 @@ static void sync_submodule(const char *path, const char *prefix, strbuf_reset(&sb); strbuf_addf(&sb, "submodule.%s.url", sub->name); - if (repo_config_set_gently(the_repository, sb.buf, super_config_url)) + if (repo_config_set_worktree_gently(the_repository, sb.buf, super_config_url)) die(_("failed to register url for submodule path '%s'"), displaypath); @@ -1671,17 +1666,31 @@ static void deinit_submodule(const char *path, const char *prefix, /* remove the .git/config entries (unless the user already did it) */ if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) { + char *file = the_repository->repository_format_worktree_config ? + repo_git_path(the_repository, "config.worktree") : + repo_git_path(the_repository, "config"); char *sub_key = xstrfmt("submodule.%s", sub->name); /* * remove the whole section so we have a clean state when * the user later decides to init this submodule again */ - repo_config_rename_section_in_file(the_repository, NULL, sub_key, NULL); + repo_config_rename_section_in_file(the_repository, file, sub_key, NULL); if (!(flags & OPT_QUIET)) printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"), sub->name, sub->url, displaypath); + free(file); free(sub_key); + + if (the_repository->repository_format_worktree_config) { + char *key = xstrfmt("submodule.%s.active", sub->name); + + repo_config_clear(the_repository); + if (is_submodule_active(the_repository, path)) + repo_config_set_worktree_gently(the_repository, + key, "false"); + free(key); + } } cleanup: @@ -3581,7 +3590,7 @@ static void configure_added_submodule(struct add_data *add_data) int matched = 0; key = xstrfmt("submodule.%s.url", add_data->sm_name); - repo_config_set_gently(the_repository, key, add_data->realrepo); + repo_config_set_worktree_gently(the_repository, key, add_data->realrepo); free(key); add_submod.git_cmd = 1; @@ -3611,10 +3620,6 @@ static void configure_added_submodule(struct add_data *add_data) if (run_command(&add_gitmodules)) die(_("Failed to register submodule '%s'"), add_data->sm_path); - /* - * NEEDSWORK: In a multi-working-tree world this needs to be - * set in the per-worktree config. - */ /* * NEEDSWORK: In the longer run, we need to get rid of this * pattern of querying "submodule.active" before calling @@ -3628,7 +3633,7 @@ static void configure_added_submodule(struct add_data *add_data) * current configured pathspec, set the submodule's active flag */ key = xstrfmt("submodule.%s.active", add_data->sm_name); - repo_config_set_gently(the_repository, key, "true"); + repo_config_set_worktree_gently(the_repository, key, "true"); free(key); } else { for (size_t i = 0; i < values->nr; i++) { @@ -3640,7 +3645,7 @@ static void configure_added_submodule(struct add_data *add_data) } if (!matched) { /* no pattern matched -> force-enable */ key = xstrfmt("submodule.%s.active", add_data->sm_name); - repo_config_set_gently(the_repository, key, "true"); + repo_config_set_worktree_gently(the_repository, key, "true"); free(key); } } diff --git a/builtin/worktree.c b/builtin/worktree.c index 77ecd0f71f..71cea4813a 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -363,6 +363,9 @@ static void copy_filtered_worktree_config(const char *worktree_git_dir) if (file_exists(from_file)) { struct config_set cs = { { 0 } }; int bare; + struct string_list keys = STRING_LIST_INIT_DUP; + struct string_list_item *item; + int i; if (safe_create_leading_directories(the_repository, to_file) || copy_file(the_repository, to_file, from_file, 0666)) { @@ -386,6 +389,26 @@ static void copy_filtered_worktree_config(const char *worktree_git_dir) error(_("failed to unset '%s' in '%s'"), "core.worktree", to_file); + /* unset "submodule.*.gitdir" */ + for (i = 0; i < cs.list.nr; i++) { + const char *var = cs.list.items[i].e->key; + const char *subsection, *key; + size_t subsection_len; + + if (!parse_config_key(var, "submodule", + &subsection, &subsection_len, &key) && + subsection && !strcmp(key, "gitdir")) + string_list_insert(&keys, var); + } + for_each_string_list_item(item, &keys) { + if (repo_config_set_multivar_in_file_gently( + the_repository, to_file, item->string, + NULL, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE)) + error(_("failed to unset '%s' in '%s'"), + item->string, to_file); + } + string_list_clear(&keys, 0); + git_configset_clear(&cs); } diff --git a/t/t2405-worktree-submodule.sh b/t/t2405-worktree-submodule.sh index f5c94d490b..9bd8fda77c 100755 --- a/t/t2405-worktree-submodule.sh +++ b/t/t2405-worktree-submodule.sh @@ -91,4 +91,161 @@ test_expect_success 'unsetting core.worktree does not prevent running commands d git -C main/.git/worktrees/checkout-recurse/modules/sub log ' +test_expect_success 'submodule config in worktree config' ' + test_when_finished "rm -rf wt-config" && + git clone "$base_path/origin/main" wt-config && + ( + cd wt-config && + git config extensions.worktreeConfig true && + git worktree add wt && + cat .git/config >.git/expect-config && + + git submodule update --init && + test_cmp .git/expect-config .git/config && + echo "true" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub.url >actual && + test_cmp expect actual && + + git submodule deinit sub && + test_cmp .git/expect-config .git/config && + test_must_be_empty .git/config.worktree && + + git submodule add ../sub sub2 && + test_cmp .git/expect-config .git/config && + echo "true" >expect && + git config --worktree submodule.sub2.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub2.url >actual && + test_cmp expect actual && + + git config --file=.gitmodules submodule.sub2.url new_url && + git submodule sync && + test_cmp .git/expect-config .git/config && + echo "new_url" >expect && + git config --worktree submodule.sub2.url >actual && + test_cmp expect actual && + + cd wt && + + git submodule update --init && + test_cmp ../.git/expect-config ../.git/config && + echo "true" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub.url >actual && + test_cmp expect actual && + + git submodule deinit sub && + test_cmp ../.git/expect-config ../.git/config && + test_must_be_empty ../.git/worktrees/wt/config.worktree && + + git submodule add ../sub sub2 && + test_cmp ../.git/expect-config ../.git/config && + echo "true" >expect && + git config --worktree submodule.sub2.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub2.url >actual && + test_cmp expect actual && + + git config --file=.gitmodules submodule.sub2.url new_url && + git submodule sync && + test_cmp ../.git/expect-config ../.git/config && + echo "new_url" >expect && + git config --worktree submodule.sub2.url >actual && + test_cmp expect actual + ) +' + +test_expect_success 'deinit overwrites active config' ' + test_when_finished "rm -rf repo-wt-config" && + git clone "$base_path/origin/main" repo-wt-config && + ( + cd repo-wt-config && + git submodule update --init && + git config extensions.worktreeConfig true && + git worktree add wt && + cat .git/config >.git/expect-config && + + git submodule deinit sub && + test_cmp .git/expect-config .git/config && + echo "false" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + + cd wt && + + git submodule deinit sub && + test_cmp ../.git/expect-config ../.git/config && + echo "false" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual + ) +' + +test_expect_success 'deinit overwrites active config (name != path)' ' + test_when_finished "rm -rf repo-wt-config" && + git clone "$base_path/origin/main" repo-wt-config && + ( + cd repo-wt-config && + git submodule update --init && + git mv sub sub_ && + git commit -m "move submodule" && + git config extensions.worktreeConfig true && + git worktree add wt && + cat .git/config >.git/expect-config && + + git submodule deinit sub_ && + test_cmp .git/expect-config .git/config && + echo "false" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + + cd wt && + + git submodule deinit sub_ && + test_cmp ../.git/expect-config ../.git/config && + echo "false" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual + ) +' + +test_expect_success 'do not copy gitdir in config.worktree' ' + test_when_finished "rm -rf copy-wt-config" && + git clone "$base_path/origin/main" copy-wt-config && + ( + cd copy-wt-config && + git config core.repositoryformatversion 1 && + git config extensions.submodulePathConfig true && + git config extensions.worktreeConfig true && + + git submodule update --init && + echo "true" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub.url >actual && + test_cmp expect actual && + echo ".git/modules/sub" >expect && + git config --worktree submodule.sub.gitdir >actual && + test_cmp expect actual && + + git worktree add wt && + cd wt && + echo "true" >expect && + git config --worktree submodule.sub.active >actual && + test_cmp expect actual && + echo "$base_path/origin/sub" >expect && + git config --worktree submodule.sub.url >actual && + test_cmp expect actual && + test_must_fail git config --worktree submodule.sub.gitdir + ) +' + test_done diff --git a/t/t7425-submodule-gitdir-path-extension.sh b/t/t7425-submodule-gitdir-path-extension.sh index 65a61edb09..590febcafd 100755 --- a/t/t7425-submodule-gitdir-path-extension.sh +++ b/t/t7425-submodule-gitdir-path-extension.sh @@ -88,6 +88,55 @@ test_expect_success 'gitdir config path is relative for both absolute and relati ) ' +test_expect_success 'gitdir for the main worktree is stored in worktree config' ' + test_when_finished "rm -rf relative-cfg-path-test-main" && + git init -b main relative-cfg-path-test-main && + ( + cd relative-cfg-path-test-main && + git config core.repositoryformatversion 1 && + git config extensions.submodulePathConfig true && + git config extensions.worktreeConfig true && + + # Test with absolute URL + git submodule add "$TRASH_DIRECTORY/new-sub" sub-abs && + git config --worktree submodule.sub-abs.gitdir >actual && + echo ".git/modules/sub-abs" >expect && + test_cmp expect actual && + + # Test with relative URL + git submodule add ../new-sub sub-rel && + git config --worktree submodule.sub-rel.gitdir >actual && + echo ".git/modules/sub-rel" >expect && + test_cmp expect actual + ) +' + +test_expect_success 'gitdir for a linked worktree is stored in worktree config' ' + test_when_finished "rm -rf relative-cfg-path-test-wt" && + git init -b main relative-cfg-path-test-wt && + ( + cd relative-cfg-path-test-wt && + git config core.repositoryformatversion 1 && + git config extensions.submodulePathConfig true && + git config extensions.worktreeConfig true && + + git worktree add wt && + cd wt && + + # Test with absolute URL + git submodule add "$TRASH_DIRECTORY/new-sub" sub-abs && + git config --worktree submodule.sub-abs.gitdir >actual && + echo "../.git/worktrees/wt/modules/sub-abs" >expect && + test_cmp expect actual && + + # Test with relative URL + git submodule add ../../new-sub sub-rel && + git config --worktree submodule.sub-rel.gitdir >actual && + echo "../.git/worktrees/wt/modules/sub-rel" >expect && + test_cmp expect actual + ) +' + test_expect_success 'clone from repo with both legacy and new-style submodules' ' git clone --recurse-submodules main cloned-non-extension && ( -- gitgitgadget