Skip to content

Commit

Permalink
Merge branch 'nd/do-not-move-worktree-manually'
Browse files Browse the repository at this point in the history
"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 <johannes.schindelin@gmx.de>
  • Loading branch information
gitster authored and dscho committed Feb 12, 2016
2 parents 78567b9 + 618244e commit 4abc310
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
15 changes: 10 additions & 5 deletions Documentation/git-worktree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ The working tree's administrative files in the repository (see
`git worktree prune` in the main or any linked working tree to
clean up any stale administrative files.

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

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

If you move a linked working tree, you need to update the 'gitdir' file
in the entry's directory. For example, if a linked working tree is moved
to `/newpath/test-next` and its `.git` file points to
`/path/main/.git/worktrees/test-next`, then update
`/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next`
instead.

To prevent a $GIT_DIR/worktrees entry from being pruned (which
can be useful in some situations, such as when the
entry's working tree is stored on a portable device), add a file named
Expand Down
12 changes: 0 additions & 12 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,6 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok)
return ret;
}

static void update_linked_gitdir(const char *gitfile, const char *gitdir)
{
struct strbuf path = STRBUF_INIT;
struct stat st;

strbuf_addf(&path, "%s/gitdir", gitdir);
if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
write_file(path.buf, "%s", gitfile);
strbuf_release(&path);
}

/*
* Try to read the location of the git directory from the .git file,
* return path to git directory if found.
Expand Down Expand Up @@ -531,7 +520,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code)
error_code = READ_GITFILE_ERR_NOT_A_REPO;
goto cleanup_return;
}
update_linked_gitdir(path, dir);
path = real_path(dir);

cleanup_return:
Expand Down
8 changes: 4 additions & 4 deletions worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ struct worktree **get_worktrees(void)
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;

if ((linked = get_linked_worktree(d->d_name))) {
ALLOC_GROW(list, counter + 1, alloc);
list[counter++] = linked;
}
if ((linked = get_linked_worktree(d->d_name))) {
ALLOC_GROW(list, counter + 1, alloc);
list[counter++] = linked;
}
}
closedir(dir);
}
Expand Down

0 comments on commit 4abc310

Please sign in to comment.