Skip to content

Commit 4abc310

Browse files
gitsterdscho
authored andcommitted
Merge branch 'nd/do-not-move-worktree-manually'
"git worktree" had a broken code that attempted to auto-fix possible inconsistency that results from end-users moving a worktree to different places without telling Git (the original repository needs to maintain backpointers to its worktrees, but "mv" run by end-users who are not familiar with that fact will obviously not adjust them), which actually made things worse when triggered. * nd/do-not-move-worktree-manually: worktree: stop supporting moving worktrees manually worktree.c: fix indentation Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 78567b9 + 618244e commit 4abc310

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
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
@@ -451,17 +451,6 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
451451
return ret;
452452
}
453453

454-
static void update_linked_gitdir(const char *gitfile, const char *gitdir)
455-
{
456-
struct strbuf path = STRBUF_INIT;
457-
struct stat st;
458-
459-
strbuf_addf(&path, "%s/gitdir", gitdir);
460-
if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
461-
write_file(path.buf, "%s", gitfile);
462-
strbuf_release(&path);
463-
}
464-
465454
/*
466455
* Try to read the location of the git directory from the .git file,
467456
* return path to git directory if found.
@@ -531,7 +520,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
531520
error_code = READ_GITFILE_ERR_NOT_A_REPO;
532521
goto cleanup_return;
533522
}
534-
update_linked_gitdir(path, dir);
535523
path = real_path(dir);
536524

537525
cleanup_return:

worktree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ struct worktree **get_worktrees(void)
176176
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
177177
continue;
178178

179-
if ((linked = get_linked_worktree(d->d_name))) {
180-
ALLOC_GROW(list, counter + 1, alloc);
181-
list[counter++] = linked;
182-
}
179+
if ((linked = get_linked_worktree(d->d_name))) {
180+
ALLOC_GROW(list, counter + 1, alloc);
181+
list[counter++] = linked;
182+
}
183183
}
184184
closedir(dir);
185185
}

0 commit comments

Comments
 (0)