Skip to content

Commit 618244e

Browse files
pcloudsgitster
authored andcommitted
worktree: stop supporting moving worktrees manually
The current update_linked_gitdir() has a bug that can create "gitdir" file in non-multi-worktree setup. Worse, sometimes it can write relative path to "gitdir" file, which will not work (e.g. "git worktree list" will display the worktree's location incorrectly) Instead of fixing this, we step back a bit. The original design was probably not well thought out. For now, if the user manually moves a worktree, they have to fix up "gitdir" file manually or the worktree will get pruned. Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d4cddd6 commit 618244e

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Documentation/git-worktree.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ The working tree's administrative files in the repository (see
3232
`git worktree prune` in the main or any linked working tree to
3333
clean up any stale administrative files.
3434

35-
If you move a linked working tree to another file system, or
36-
within a file system that does not support hard links, you need to run
37-
at least one git command inside the linked working tree
38-
(e.g. `git status`) in order to update its administrative files in the
39-
repository so that they do not get automatically pruned.
35+
If you move a linked working tree, you need to manually update the
36+
administrative files so that they do not get pruned automatically. See
37+
section "DETAILS" for more information.
4038

4139
If a linked working tree is stored on a portable device or network share
4240
which is not always mounted, you can prevent its administrative files from
@@ -137,6 +135,13 @@ thumb is do not make any assumption about whether a path belongs to
137135
$GIT_DIR or $GIT_COMMON_DIR when you need to directly access something
138136
inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path.
139137

138+
If you move a linked working tree, you need to update the 'gitdir' file
139+
in the entry's directory. For example, if a linked working tree is moved
140+
to `/newpath/test-next` and its `.git` file points to
141+
`/path/main/.git/worktrees/test-next`, then update
142+
`/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next`
143+
instead.
144+
140145
To prevent a $GIT_DIR/worktrees entry from being pruned (which
141146
can be useful in some situations, such as when the
142147
entry's working tree is stored on a portable device), add a file named

setup.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,17 +401,6 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
401401
return ret;
402402
}
403403

404-
static void update_linked_gitdir(const char *gitfile, const char *gitdir)
405-
{
406-
struct strbuf path = STRBUF_INIT;
407-
struct stat st;
408-
409-
strbuf_addf(&path, "%s/gitdir", gitdir);
410-
if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
411-
write_file(path.buf, "%s", gitfile);
412-
strbuf_release(&path);
413-
}
414-
415404
/*
416405
* Try to read the location of the git directory from the .git file,
417406
* return path to git directory if found.
@@ -481,7 +470,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
481470
error_code = READ_GITFILE_ERR_NOT_A_REPO;
482471
goto cleanup_return;
483472
}
484-
update_linked_gitdir(path, dir);
485473
path = real_path(dir);
486474

487475
cleanup_return:

0 commit comments

Comments
 (0)