There are a couple of problems with this function:
- premature design
- create "gitdir" file outside multi-worktree context
- update the file's content with relative path, with breaks "worktree list"
The first three patches kill it, as a result. They are relatively safe.
The last three re-implement it in a new form, "worktree refresh",
inspired by "update-index --refresh". For now the user can use this
command to correct some internal data after moving a worktree. In
future, we might do automatic refresh like we do with the index.
The last three try out new design, so it will probably take more time
to graduate than the first three, which may end up in the next release
as worktree bug fix.
Eric Sunshine (1):
worktree.txt: how to fix up after moving a worktree
Nguyễn Thái Ngọc Duy (5):
worktree.c: fix indentation
worktree: stop supporting moving worktrees manually
abspath.c: add and use real_path_dup()
setup.c: record the location of .git file
worktree: new command to fix up worktree's info after moving
Documentation/git-worktree.txt | 21 ++++++++++++++++-----
abspath.c | 5 +++++
builtin/clone.c | 2 +-
builtin/init-db.c | 6 +++---
builtin/worktree.c | 18 ++++++++++++++++++
cache.h | 2 ++
setup.c | 26 +++++++++++---------------
t/t1501-worktree.sh | 9 +++++++++
worktree.c | 8 ++++----
9 files changed, 69 insertions(+), 28 deletions(-)
--
2.7.0.96.g5373197
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.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Documentation/git-worktree.txt | 6 ++----
setup.c | 12 ------------
2 files changed, 2 insertions(+), 16 deletions(-)
@@ -33,10 +33,8 @@ The working tree's administrative files in the repository (see 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.+within a file system that does not support hard links, you need to update+$GIT_DIR/worktrees/<id>/gitdir so that they do not get automatically pruned. 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
@@ -643,7 +643,7 @@ static const char *setup_discovered_git_dir(const char *gitdir,/* --work-tree is set without --git-dir; use discovered one */if(getenv(GIT_WORK_TREE_ENVIRONMENT)||git_work_tree_cfg){if(offset!=cwd->len&&!is_absolute_path(gitdir))-gitdir=xstrdup(real_path(gitdir));+gitdir=real_path_dup(gitdir);if(chdir(cwd->buf))die_errno("Could not come back to cwd");returnsetup_explicit_git_dir(gitdir,cwd,nongit_ok);
@@ -32,9 +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 update-$GIT_DIR/worktrees/<id>/gitdir 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
@@ -135,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
This is a low-level command that can be used to correct worktree
information after a worktree is moved. The idea is like 'index refresh'.
In future we may do "worktree refresh" automatically to keep it from
being pruned.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Documentation/git-worktree.txt | 8 +++++++-
builtin/worktree.c | 18 ++++++++++++++++++
t/t1501-worktree.sh | 9 +++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
@@ -65,6 +66,11 @@ each of the linked worktrees. The output details include if the worktree is bare, the revision currently checked out, and the branch currently checked out (or 'detached HEAD' if none).+refresh::++This command is required to update worktree's information after it's moved.+Executed from inside the moved worktree.+ OPTIONS -------
@@ -140,7 +146,7 @@ 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.+instead. Alternatively you can run "git worktree refresh". To prevent a $GIT_DIR/worktrees entry from being pruned (which can be useful in some situations, such as when the
From: Philip Oakley <hidden> Date: 2016-06-15 23:07:48
From: "Nguyễn Thái Ngọc Duy" <redacted>
quoted hunk
This is a low-level command that can be used to correct worktree
information after a worktree is moved. The idea is like 'index refresh'.
In future we may do "worktree refresh" automatically to keep it from
being pruned.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Documentation/git-worktree.txt | 8 +++++++-
builtin/worktree.c | 18 ++++++++++++++++++
t/t1501-worktree.sh | 9 +++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-worktree.txt
b/Documentation/git-worktree.txt
index 62c76c1..306aeec 100644
@@ -65,6 +66,11 @@ each of the linked worktrees. The output details
include if the worktree is
bare, the revision currently checked out, and the branch currently checked
out
(or 'detached HEAD' if none).
+refresh::
+
+This command is required to update worktree's information after it's
moved.
+Executed from inside the moved worktree.
+
OPTIONS
-------
@@ -140,7 +146,7 @@ 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.
+instead. Alternatively you can run "git worktree refresh".
Shouldn't this note also include the caveat about the run location?
...run "git worktree refresh" from inside the moved worktree.
quoted hunk
To prevent a $GIT_DIR/worktrees entry from being pruned (which
can be useful in some situations, such as when the
From: Eric Sunshine <hidden> Date: 2016-06-15 23:07:48
On Mon, Jan 18, 2016 at 6:21 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
quoted hunk
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.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
@@ -33,10 +33,8 @@ The working tree's administrative files in the repository (see 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.+within a file system that does not support hard links, you need to update+$GIT_DIR/worktrees/<id>/gitdir so that they do not get automatically pruned.
It seems kind of sad to change this text in this patch and then
immediately change it again in the next patch. You could instead
combine the two patches (and add a "Helped-by: Eric" if you want to
credit me).
From: Eric Sunshine <hidden> Date: 2016-06-15 23:07:48
On Mon, Jan 18, 2016 at 6:21 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
From: Eric Sunshine <redacted>
Let's use sunshine@sunshineco.com instead.
If you want to keep this patch separate from the previous patch, then
perhaps add a commit message here saying something like:
Following the example of af189b4 (Documentation/git-worktree:
split technical info from general description, 2015-07-06), keep the
high-level overview free of low-level details about updating
administrative files when moving a worktree, and instead mention
$GIT_DIR/worktrees/<id>/gitdir in the "DETAILS" section.
@@ -32,9 +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 update-$GIT_DIR/worktrees/<id>/gitdir 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
@@ -135,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--
On Tue, Jan 19, 2016 at 1:30 AM, Eric Sunshine [off-list ref] wrote:
On Mon, Jan 18, 2016 at 6:21 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
quoted
From: Eric Sunshine <redacted>
Let's use sunshine@sunshineco.com instead.
If you want to keep this patch separate from the previous patch, then
I don't want to make you feel sad. So I'll combine the two patches
into one. Noted the email address for helped-by though.
perhaps add a commit message here saying something like:
Following the example of af189b4 (Documentation/git-worktree:
split technical info from general description, 2015-07-06), keep the
high-level overview free of low-level details about updating
administrative files when moving a worktree, and instead mention
$GIT_DIR/worktrees/<id>/gitdir in the "DETAILS" section.
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 [off-list ref]
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
Documentation/git-worktree.txt | 15 ++++++++++-----
setup.c | 12 ------------
2 files changed, 10 insertions(+), 17 deletions(-)
@@ -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
@@ -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