summaryrefslogtreecommitdiff
path: root/sparse-index.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2022-02-07 21:33:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-02-08 17:49:20 (GMT)
commit7316dc5f6f2c8297d32e47d5859933ffacb6c00e (patch)
tree61b29b619bf08a15ca09798180935c3b9c8a2e1e /sparse-index.c
parentfe18733927c1d28ffcec3b52908989c591bc7b87 (diff)
downloadgit-7316dc5f6f2c8297d32e47d5859933ffacb6c00e.zip
git-7316dc5f6f2c8297d32e47d5859933ffacb6c00e.tar.gz
git-7316dc5f6f2c8297d32e47d5859933ffacb6c00e.tar.bz2
sparse-checkout: set worktree-config correctly
`git sparse-checkout set/init` enables worktree-specific configuration[*] by setting extensions.worktreeConfig=true, but neglects to perform the additional necessary bookkeeping of relocating `core.bare=true` and `core.worktree` from $GIT_COMMON_DIR/config to $GIT_COMMON_DIR/config.worktree, as documented in git-worktree.txt. As a result of this oversight, these settings, which are nonsensical for secondary worktrees, can cause Git commands to incorrectly consider a worktree bare (in the case of `core.bare`) or operate on the wrong worktree (in the case of `core.worktree`). Fix this problem by taking advantage of the recently-added init_worktree_config() which enables `extensions.worktreeConfig` and takes care of necessary bookkeeping. While at it, for backward-compatibility reasons, also stop upgrading the repository format to "1" since doing so is (unintentionally) not required to take advantage of `extensions.worktreeConfig`, as explained by 11664196ac ("Revert "check_repository_format_gently(): refuse extensions for old repositories"", 2020-07-15). [*] The main reason to use worktree-specific config for the sparse-checkout builtin was to avoid enabling sparse-checkout patterns in one and causing a loss of files in another. If a worktree does not have a sparse-checkout patterns file, then the sparse-checkout logic will not kick in on that worktree. Reported-by: Sean Allred <allred.sean@gmail.com> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sparse-index.c')
-rw-r--r--sparse-index.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/sparse-index.c b/sparse-index.c
index a1d505d..e936099 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -99,13 +99,9 @@ static int convert_to_sparse_rec(struct index_state *istate,
int set_sparse_index_config(struct repository *repo, int enable)
{
- int res;
- char *config_path = repo_git_path(repo, "config.worktree");
- res = git_config_set_in_file_gently(config_path,
- "index.sparse",
- enable ? "true" : NULL);
- free(config_path);
-
+ int res = repo_config_set_worktree_gently(repo,
+ "index.sparse",
+ enable ? "true" : "false");
prepare_repo_settings(repo);
repo->settings.sparse_index = enable;
return res;