Skip to content

Commit 6cfbdcb

Browse files
pcloudsgitster
authored andcommitted
git_path(): keep "info/sparse-checkout" per work-tree
Currently git_path("info/sparse-checkout") resolves to $GIT_COMMON_DIR/info/sparse-checkout in multiple worktree mode. It makes more sense for the sparse checkout patterns to be per worktree, so you can have multiple checkouts with different parts of the tree. With this, "git checkout --to <new>" on a sparse checkout will create <new> as a full checkout. Which is expected, it's how a new checkout is made. The user can reshape the worktree afterwards. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77a6d84 commit 6cfbdcb

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

path.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len)
103103
char *base = buf->buf + git_dir_len;
104104
const char **p;
105105

106-
if (is_dir_file(base, "logs", "HEAD"))
106+
if (is_dir_file(base, "logs", "HEAD") ||
107+
is_dir_file(base, "info", "sparse-checkout"))
107108
return; /* keep this in $GIT_DIR */
108109
for (p = common_list; *p; p++) {
109110
const char *path = *p;

t/t0060-path-utils.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ test_git_path GIT_COMMON_DIR=bar objects bar/objects
270270
test_git_path GIT_COMMON_DIR=bar objects/bar bar/objects/bar
271271
test_git_path GIT_COMMON_DIR=bar info/exclude bar/info/exclude
272272
test_git_path GIT_COMMON_DIR=bar info/grafts bar/info/grafts
273+
test_git_path GIT_COMMON_DIR=bar info/sparse-checkout .git/info/sparse-checkout
273274
test_git_path GIT_COMMON_DIR=bar remotes/bar bar/remotes/bar
274275
test_git_path GIT_COMMON_DIR=bar branches/bar bar/branches/bar
275276
test_git_path GIT_COMMON_DIR=bar logs/refs/heads/master bar/logs/refs/heads/master

0 commit comments

Comments
 (0)