git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] worktree: repair copied repository and linked worktrees
@ 2024-09-23  7:54 Eric Sunshine
  2024-09-23  8:04 ` Eric Sunshine
  2024-09-23 21:22 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Sunshine @ 2024-09-23  7:54 UTC (permalink / raw)
  To: git; +Cc: Russell Stuart, Eric Sunshine

From: Eric Sunshine <sunshine@sunshineco.com>

For each linked worktree, Git maintains two pointers: (1)
<repo>/worktrees/<id>/gitdir which points at the linked worktree, and
(2) <worktree>/.git which points back at <repo>/worktrees/<id>. Both
pointers are absolute pathnames.

Aside from manually manipulating those raw files, it is possible to
easily "break" one or both pointers by ignoring the "git worktree move"
command and instead manually moving a linked worktree, moving the
repository, or moving both. The "git worktree repair" command was
invented to handle this case by restoring these pointers to sane values.

For the "repair" command, the "git worktree" manual page states:

  Repair worktree administrative files, if possible, if they have
  become corrupted or outdated due to external factors.

The "if possible" clause was chosen deliberately to convey that the
existing implementation may not be able to fix every possible breakage,
and to imply that improvements may be made to handle other types of
breakage.

A recent problem report[*] illustrates a case in which "git worktree
repair" not only fails to fix breakage, but actually causes breakage.
Specifically, if a repository / main-worktree and linked worktrees are
*copied* as a unit (rather than *moved*), then "git worktree repair" run
in the copy leaves the copy untouched but botches the pointers in the
original repository and the original worktrees.

For instance, given this directory structure:

  orig/
    main/ (main-worktree)
    linked/ (linked worktree)

if "orig" is copied (not moved) to "dup", then immediately after the
manual copy operation:

  * orig/main/.git/worktrees/linked/gitdir points at orig/linked/.git
  * orig/linked/.git points at orig/main/.git/worktrees/linked
  * dup/main/.git/worktrees/linked/gitdir points at orig/linked/.git
  * dup/linked/.git points at orig/main/.git/worktrees/linked

So, dup/main thinks its linked worktree is orig/linked, and worktree
dup/linked thinks its repository / main-worktree is orig/main.

"git worktree repair" is reasonably simple-minded; it wants to trust
valid-looking pointers, hence doesn't try to second-guess them. In this
case, when validating dup/linked/.git, it finds a legitimate repository
pointer, orig/main/.git/worktrees/linked, thus trusts that is correct,
but does notice that gitdir in that directory doesn't point at
dup/linked/.git, so it (incorrectly) _fixes_
orig/main/.git/worktrees/linked/gitdir to point at dup/linked/.git.
Similarly, when validating dup/main/.git/worktrees/linked/gitdir, it
finds a legitimate worktree pointer, orig/linked/.git, but notices that
its .git file doesn't point back at dup/main, thus (incorrectly) _fixes_
orig/linked/.git to point at dup/main/.git/worktrees/linked. Hence, it
has modified and broken the linkage between orig/main and orig/linked
rather than fixing dup/main and dup/linked as expected.

Fix this problem by also checking if a plausible .git/worktrees/<id>
exists in the *current* repository -- not just in the repository pointed
at by the worktree's .git file -- and comparing whether they are the
same. If not, then it is likely because the repository / main-worktree
and linked worktrees were copied, so prefer the discovered plausible
pointer rather than the one from the existing .git file.

[*]: https://lore.kernel.org/git/E1sr5iF-0007zV-2k@binarylane-bailey.stuart.id.au/

Reported-by: Russell Stuart <russell+git.vger.kernel.org@stuart.id.au>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 Documentation/git-worktree.txt |  2 +-
 t/t2406-worktree-repair.sh     | 19 ++++++++++++++++
 worktree.c                     | 40 +++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 2a240f53ba..70437c815f 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -157,7 +157,7 @@ will reestablish the connection. If multiple linked worktrees are moved,
 running `repair` from any worktree with each tree's new `<path>` as an
 argument, will reestablish the connection to all the specified paths.
 +
-If both the main worktree and linked worktrees have been moved manually,
+If both the main worktree and linked worktrees have been moved or copied manually,
 then running `repair` in the main worktree and specifying the new `<path>`
 of each linked worktree will reestablish all connections in both
 directions.
diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh
index edbf502ec5..7686e60f6a 100755
--- a/t/t2406-worktree-repair.sh
+++ b/t/t2406-worktree-repair.sh
@@ -197,4 +197,23 @@ test_expect_success 'repair moved main and linked worktrees' '
 	test_cmp expect-gitfile sidemoved/.git
 '
 
+test_expect_success 'repair copied main and linked worktrees' '
+	test_when_finished "rm -rf orig dup" &&
+	mkdir -p orig &&
+	git -C orig init main &&
+	test_commit -C orig/main nothing &&
+	git -C orig/main worktree add ../linked &&
+	cp orig/main/.git/worktrees/linked/gitdir orig/main.expect &&
+	cp orig/linked/.git orig/linked.expect &&
+	cp -R orig dup &&
+	sed "s,orig/linked/\.git$,dup/linked/.git," orig/main.expect >dup/main.expect &&
+	sed "s,orig/main/\.git/worktrees/linked$,dup/main/.git/worktrees/linked," \
+		orig/linked.expect >dup/linked.expect &&
+	git -C dup/main worktree repair ../linked &&
+	test_cmp orig/main.expect orig/main/.git/worktrees/linked/gitdir &&
+	test_cmp orig/linked.expect orig/linked/.git &&
+	test_cmp dup/main.expect dup/main/.git/worktrees/linked/gitdir &&
+	test_cmp dup/linked.expect dup/linked/.git
+'
+
 test_done
diff --git a/worktree.c b/worktree.c
index 30a947426e..7d1b60ff9f 100644
--- a/worktree.c
+++ b/worktree.c
@@ -683,6 +683,7 @@ void repair_worktree_at_path(const char *path,
 	struct strbuf gitdir = STRBUF_INIT;
 	struct strbuf olddotgit = STRBUF_INIT;
 	char *backlink = NULL;
+	char *inferred_backlink = NULL;
 	const char *repair = NULL;
 	int err;
 
@@ -698,12 +699,24 @@ void repair_worktree_at_path(const char *path,
 		goto done;
 	}
 
+	inferred_backlink = infer_backlink(realdotgit.buf);
 	backlink = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));
 	if (err == READ_GITFILE_ERR_NOT_A_FILE) {
 		fn(1, realdotgit.buf, _("unable to locate repository; .git is not a file"), cb_data);
 		goto done;
 	} else if (err == READ_GITFILE_ERR_NOT_A_REPO) {
-		if (!(backlink = infer_backlink(realdotgit.buf))) {
+		if (inferred_backlink) {
+			/*
+			 * Worktree's .git file does not point at a repository
+			 * but we found a .git/worktrees/<id> in this
+			 * repository with the same <id> as recorded in the
+			 * worktree's .git file so make the worktree point at
+			 * the discovered .git/worktrees/<id>. (Note: backlink
+			 * is already NULL, so no need to free it first.)
+			 */
+			backlink = inferred_backlink;
+			inferred_backlink = NULL;
+		} else {
 			fn(1, realdotgit.buf, _("unable to locate repository; .git file does not reference a repository"), cb_data);
 			goto done;
 		}
@@ -712,6 +725,30 @@ void repair_worktree_at_path(const char *path,
 		goto done;
 	}
 
+	/*
+	 * If we got this far, either the worktree's .git file pointed at a
+	 * valid repository (i.e. read_gitfile_gently() returned success) or
+	 * the .git file did not point at a repository but we were able to
+	 * infer a suitable new value for the .git file by locating a
+	 * .git/worktrees/<id> in *this* repository corresponding to the <id>
+	 * recorded in the worktree's .git file.
+	 *
+	 * However, if, at this point, inferred_backlink is non-NULL (i.e. we
+	 * found a suitable .git/worktrees/<id> in *this* repository) *and* the
+	 * worktree's .git file points at a valid repository *and* those two
+	 * paths differ, then that indicates that the user probably *copied*
+	 * the main and linked worktrees to a new location as a unit rather
+	 * than *moving* them. Thus, the copied worktree's .git file actually
+	 * points at the .git/worktrees/<id> in the *original* repository, not
+	 * in the "copy" repository. In this case, point the "copy" worktree's
+	 * .git file at the "copy" repository.
+	 */
+	if (inferred_backlink && fspathcmp(backlink, inferred_backlink)) {
+		free(backlink);
+		backlink = inferred_backlink;
+		inferred_backlink = NULL;
+	}
+
 	strbuf_addf(&gitdir, "%s/gitdir", backlink);
 	if (strbuf_read_file(&olddotgit, gitdir.buf, 0) < 0)
 		repair = _("gitdir unreadable");
@@ -727,6 +764,7 @@ void repair_worktree_at_path(const char *path,
 	}
 done:
 	free(backlink);
+	free(inferred_backlink);
 	strbuf_release(&olddotgit);
 	strbuf_release(&gitdir);
 	strbuf_release(&realdotgit);
-- 
2.46.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] worktree: repair copied repository and linked worktrees
  2024-09-23  7:54 [PATCH] worktree: repair copied repository and linked worktrees Eric Sunshine
@ 2024-09-23  8:04 ` Eric Sunshine
  2024-09-23 21:22 ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Sunshine @ 2024-09-23  8:04 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: git, Russell Stuart

On Mon, Sep 23, 2024 at 3:55 AM Eric Sunshine <ericsunshine@charter.net> wrote:
> [...]
> Fix this problem by also checking if a plausible .git/worktrees/<id>
> exists in the *current* repository -- not just in the repository pointed
> at by the worktree's .git file -- and comparing whether they are the
> same. If not, then it is likely because the repository / main-worktree
> and linked worktrees were copied, so prefer the discovered plausible
> pointer rather than the one from the existing .git file.
>
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
> ---
> diff --git a/worktree.c b/worktree.c
> @@ -698,12 +699,24 @@ void repair_worktree_at_path(const char *path,
> +       inferred_backlink = infer_backlink(realdotgit.buf);
>         backlink = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));
>         if (err == READ_GITFILE_ERR_NOT_A_FILE) {
>                 fn(1, realdotgit.buf, _("unable to locate repository; .git is not a file"), cb_data);
>                 goto done;
>         } else if (err == READ_GITFILE_ERR_NOT_A_REPO) {
> -               if (!(backlink = infer_backlink(realdotgit.buf))) {
> +               if (inferred_backlink) {
> +                       /*
> +                        * Worktree's .git file does not point at a repository
> +                        * but we found a .git/worktrees/<id> in this
> +                        * repository with the same <id> as recorded in the
> +                        * worktree's .git file so make the worktree point at
> +                        * the discovered .git/worktrees/<id>. (Note: backlink
> +                        * is already NULL, so no need to free it first.)
> +                        */
> +                       backlink = inferred_backlink;
> +                       inferred_backlink = NULL;
> +               } else {
>                         fn(1, realdotgit.buf, _("unable to locate repository; .git file does not reference a repository"), cb_data);
>                         goto done;
>                 }

In case it's not obvious at first glance, there is no change of
behavior here. This changes in this hunk:

(1) factor out the call to infer_backlink() since the result is now
consulted in multiple code paths and the code needs to be careful to
ensure that all allocated strings get freed (at the end of the
function)

(2) add a comment explaining the *existing* behavior

The later hunk in this patch contains the actual behavior change.

> @@ -712,6 +725,30 @@ void repair_worktree_at_path(const char *path,
> +       /*
> +        * If we got this far, either the worktree's .git file pointed at a
> +        * valid repository (i.e. read_gitfile_gently() returned success) or
> +        * the .git file did not point at a repository but we were able to
> +        * infer a suitable new value for the .git file by locating a
> +        * .git/worktrees/<id> in *this* repository corresponding to the <id>
> +        * recorded in the worktree's .git file.
> +        *
> +        * However, if, at this point, inferred_backlink is non-NULL (i.e. we
> +        * found a suitable .git/worktrees/<id> in *this* repository) *and* the
> +        * worktree's .git file points at a valid repository *and* those two
> +        * paths differ, then that indicates that the user probably *copied*
> +        * the main and linked worktrees to a new location as a unit rather
> +        * than *moving* them. Thus, the copied worktree's .git file actually
> +        * points at the .git/worktrees/<id> in the *original* repository, not
> +        * in the "copy" repository. In this case, point the "copy" worktree's
> +        * .git file at the "copy" repository.
> +        */
> +       if (inferred_backlink && fspathcmp(backlink, inferred_backlink)) {
> +               free(backlink);
> +               backlink = inferred_backlink;
> +               inferred_backlink = NULL;
> +       }
> +

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] worktree: repair copied repository and linked worktrees
  2024-09-23  7:54 [PATCH] worktree: repair copied repository and linked worktrees Eric Sunshine
  2024-09-23  8:04 ` Eric Sunshine
@ 2024-09-23 21:22 ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2024-09-23 21:22 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: git, Russell Stuart, Eric Sunshine

Eric Sunshine <ericsunshine@charter.net> writes:

> Fix this problem by also checking if a plausible .git/worktrees/<id>
> exists in the *current* repository -- not just in the repository pointed
> at by the worktree's .git file -- and comparing whether they are the
> same. If not, then it is likely because the repository / main-worktree
> and linked worktrees were copied, so prefer the discovered plausible
> pointer rather than the one from the existing .git file.

In other words, before futzing with a repository to point at a
(potentially moved) worktree that points back to it, make sure that
the repository is in a corrupt state---if one of the worktrees we
know correctly points back to us already, that pointer should not be
mucked with, or we would end up spreading the damage further?

It does make sense.

> -If both the main worktree and linked worktrees have been moved manually,
> +If both the main worktree and linked worktrees have been moved or copied manually,
>  then running `repair` in the main worktree and specifying the new `<path>`
>  of each linked worktree will reestablish all connections in both
>  directions.

OK.

> diff --git a/worktree.c b/worktree.c
> index 30a947426e..7d1b60ff9f 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -683,6 +683,7 @@ void repair_worktree_at_path(const char *path,
>  	struct strbuf gitdir = STRBUF_INIT;
>  	struct strbuf olddotgit = STRBUF_INIT;
>  	char *backlink = NULL;
> +	/*
> +	 * If we got this far, either the worktree's .git file pointed at a
> +	 * valid repository (i.e. read_gitfile_gently() returned success) or
> +	 * the .git file did not point at a repository but we were able to
> +	 * infer a suitable new value for the .git file by locating a
> +	 * .git/worktrees/<id> in *this* repository corresponding to the <id>
> +	 * recorded in the worktree's .git file.
> +	 *
> +	 * However, if, at this point, inferred_backlink is non-NULL (i.e. we
> +	 * found a suitable .git/worktrees/<id> in *this* repository) *and* the
> +	 * worktree's .git file points at a valid repository *and* those two
> +	 * paths differ, then that indicates that the user probably *copied*
> +	 * the main and linked worktrees to a new location as a unit rather
> +	 * than *moving* them. Thus, the copied worktree's .git file actually
> +	 * points at the .git/worktrees/<id> in the *original* repository, not
> +	 * in the "copy" repository. In this case, point the "copy" worktree's
> +	 * .git file at the "copy" repository.
> +	 */

Tricky, but cannot be avoided in order to help those who "copy".

> diff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh
> index edbf502ec5..7686e60f6a 100755
> --- a/t/t2406-worktree-repair.sh
> +++ b/t/t2406-worktree-repair.sh
> @@ -197,4 +197,23 @@ test_expect_success 'repair moved main and linked worktrees' '
>  	test_cmp expect-gitfile sidemoved/.git
>  '
>  
> +test_expect_success 'repair copied main and linked worktrees' '
> +	test_when_finished "rm -rf orig dup" &&
> +	mkdir -p orig &&
> +	git -C orig init main &&
> +	test_commit -C orig/main nothing &&
> +	git -C orig/main worktree add ../linked &&
> +	cp orig/main/.git/worktrees/linked/gitdir orig/main.expect &&
> +	cp orig/linked/.git orig/linked.expect &&
> +	cp -R orig dup &&
> +	sed "s,orig/linked/\.git$,dup/linked/.git," orig/main.expect >dup/main.expect &&
> +	sed "s,orig/main/\.git/worktrees/linked$,dup/main/.git/worktrees/linked," \
> +		orig/linked.expect >dup/linked.expect &&
> +	git -C dup/main worktree repair ../linked &&
> +	test_cmp orig/main.expect orig/main/.git/worktrees/linked/gitdir &&
> +	test_cmp orig/linked.expect orig/linked/.git &&
> +	test_cmp dup/main.expect dup/main/.git/worktrees/linked/gitdir &&
> +	test_cmp dup/linked.expect dup/linked/.git
> +'
> +
>  test_done

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] worktree: repair copied repository and linked worktrees
@ 2024-10-08 15:30 Caleb White
  2024-10-08 15:53 ` Caleb White
  0 siblings, 1 reply; 5+ messages in thread
From: Caleb White @ 2024-10-08 15:30 UTC (permalink / raw)
  To: ericsunshine; +Cc: git, russell+git.vger.kernel.org, sunshine, cdwhite3

[-- Attachment #1: Type: text/plain, Size: 5461 bytes --]

Eric Sunshine <ericsunshine@charter.net> writes:

> +	inferred_backlink = infer_backlink(realdotgit.buf);
>  	backlink = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));
>  	if (err == READ_GITFILE_ERR_NOT_A_FILE) {
>  		fn(1, realdotgit.buf, _("unable to locate repository; .git is not a file"), cb_data);
>  		goto done;
>  	} else if (err == READ_GITFILE_ERR_NOT_A_REPO) {
> -		if (!(backlink = infer_backlink(realdotgit.buf))) {
> +		if (inferred_backlink) {
> +			/*
> +			 * Worktree's .git file does not point at a repository
> +			 * but we found a .git/worktrees/<id> in this
> +			 * repository with the same <id> as recorded in the
> +			 * worktree's .git file so make the worktree point at
> +			 * the discovered .git/worktrees/<id>. (Note: backlink
> +			 * is already NULL, so no need to free it first.)
> +			 */
> +			backlink = inferred_backlink;
> +			inferred_backlink = NULL;
> +		} else {
>  			fn(1, realdotgit.buf, _("unable to locate reposito
ry; .git file does not reference a repository"), cb_data);
>  			goto done;
>  		}

Moving the `infer_backlink()` call outside of the error condition caused me to
discover a bug in my own refactor of infer_backlink() on my relative paths series.
Turns out I needed to clear the `inferred` path if an error occurred.
This is OK.

> +	/*
> +	 * If we got this far, either the worktree's .git file pointed at a
> +	 * valid repository (i.e. read_gitfile_gently() returned success) or
> +	 * the .git file did not point at a repository but we were able to
> +	 * infer a suitable new value for the .git file by locating a
> +	 * .git/worktrees/<id> in *this* repository corresponding to the <id>
> +	 * recorded in the worktree's .git file.
> +	 *
> +	 * However, if, at this point, inferred_backlink is non-NULL (i.e. we
> +	 * found a suitable .git/worktrees/<id> in *this* repository) *and* the
> +	 * worktree's .git file points at a valid repository *and* those two
> +	 * paths 
differ, then that indicates that the user probably *copied*
> +	 * the main and linked worktrees to a new location as a unit rather
> +	 * than *moving* them. Thus, the copied worktree's .git file actually
> +	 * points at the .git/worktrees/<id> in the *original* repository, not
> +	 * in the "copy" repository. In this case, point the "copy" worktree's
> +	 * .git file at the "copy" repository.
> +	 */
> +	if (inferred_backlink && fspathcmp(backlink, inferred_backlink)) {
> +		free(backlink);
> +		backlink = inferred_backlink;
> +		inferred_backlink = NULL;
> +	}

This edge case seems to primarily be an artifact of using absolute paths to link
the worktrees. The test case you provided passes on my relative path series even
with this condition commented out. However, we do still want to support absolute
paths to maintain backwards compatibility so I think we should try to detect
this edge case if we can.

Unfortunately, this change now "repairs" (i.e., breaks) worktr
ees from other
repositories if the worktree_id happens to be identical between the repositories.
For example, the following test passes on `master` (with absolute paths) and on
my relative path series (relative paths without your changes integrated), but it
fails on your patch (and my relative patch series with your changes integrated):

    test_expect_success 'does not repair worktrees from another repo' '
        test_when_finished "rm -rf repo1 repo2" &&
        mkdir -p repo1 &&
        git -C repo1 init main &&
        test_commit -C repo1/main nothing &&
        git -C repo1/main worktree add ../linked &&
        cp repo1/main/.git/worktrees/linked/gitdir repo1/main.expect &&
        cp repo1/linked/.git repo1/linked.expect &&
        mkdir -p repo2 &&
        git -C repo2 init main &&
        test_commit -C repo2/main nothing &&
        git -C repo2/main worktree add ../linked &&
        cp repo2/main/.git/worktrees/linked/gitdir repo2/main.expect &&
        
cp repo2/linked/.git repo2/linked.expect &&
        git -C repo1/main worktree repair ../.. &&
        test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
        test_cmp repo1/linked.expect repo1/linked/.git &&
        test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
        test_cmp repo2/linked.expect repo2/linked/.git &&
        git -C repo2/main worktree repair ../../repo1/linked &&
        test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
        test_cmp repo1/linked.expect repo1/linked/.git &&
        test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
        test_cmp repo2/linked.expect repo2/linked/.git
    '

Granted, this is likely a rare edge case, but I would not expect trying to repair
a valid worktree from another repository to change the pointers. I think a good
solution to this would be to introduce a unique hash on the worktree_id when
creating a worktree to guarantee uniqu
eness across repositories, e.g.,:

    repo1/main/.git/worktrees/linked-6a4b5d/gitdir:
        /path/to/repo1/linked/.git
    repo1/linked/.git:
        gitdir: /path/to/repo1/main/worktrees/linked-6a4b5d

    repo2/main/.git/worktrees/linked-9ab26fe/gitdir:
        /path/to/repo2/linked/.git
    repo2/linked/.git:
        gitdir: /path/to/repo2/main/worktrees/linked-9ab26fe

This would allow us to detect this copied case while not "repairing" valid
worktrees from other repositories with the same linked worktree directory name.


Best,

- Caleb

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] worktree: repair copied repository and linked worktrees
  2024-10-08 15:30 Caleb White
@ 2024-10-08 15:53 ` Caleb White
  0 siblings, 0 replies; 5+ messages in thread
From: Caleb White @ 2024-10-08 15:53 UTC (permalink / raw)
  To: ericsunshine; +Cc: git, russell+git.vger.kernel.org, sunshine, cdwhite3


[-- Attachment #1.1: Type: text/plain, Size: 2590 bytes --]

On Tuesday, October 8th, 2024 at 10:30, Caleb White <cdwhite3@pm.me> wrote:

> test_expect_success 'does not repair worktrees from another repo' '
> test_when_finished "rm -rf repo1 repo2" &&
> mkdir -p repo1 &&
> git -C repo1 init main &&
> test_commit -C repo1/main nothing &&
> git -C repo1/main worktree add ../linked &&
> cp repo1/main/.git/worktrees/linked/gitdir repo1/main.expect &&
> cp repo1/linked/.git repo1/linked.expect &&
> mkdir -p repo2 &&
> git -C repo2 init main &&
> test_commit -C repo2/main nothing &&
> git -C repo2/main worktree add ../linked &&
> cp repo2/main/.git/worktrees/linked/gitdir repo2/main.expect &&
> cp repo2/linked/.git repo2/linked.expect &&
> git -C repo1/main worktree repair ../.. &&
> test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
> test_cmp repo1/linked.expect repo1/linked/.git &&
> test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
> test_cmp repo2/linked.expect repo2/linked/.git &&
> git -C repo2/main worktree repair ../../repo1/linked &&
> test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
> test_cmp repo1/linked.expect repo1/linked/.git &&
> test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
> test_cmp repo2/linked.expect repo2/linked/.git
> '

Apologies on this test case, it should be:

    test_expect_success 'does not repair worktrees from another repo' '
	test_when_finished "rm -rf repo1 repo2" &&
	mkdir -p repo1 &&
	git -C repo1 init main &&
	test_commit -C repo1/main nothing &&
	git -C repo1/main worktree add ../linked &&
	cp repo1/main/.git/worktrees/linked/gitdir repo1/main.expect &&
	cp repo1/linked/.git repo1/linked.expect &&
	mkdir -p repo2 &&
	git -C repo2 init main &&
	test_commit -C repo2/main nothing &&
	git -C repo2/main worktree add ../linked &&
	cp repo2/main/.git/worktrees/linked/gitdir repo2/main.expect &&
	cp repo2/linked/.git repo2/linked.expect &&
	git -C repo1/main worktree repair ../../repo2/linked &&
	test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
	test_cmp repo1/linked.expect repo1/linked/.git &&
	test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
	test_cmp repo2/linked.expect repo2/linked/.git &&
	git -C repo2/main worktree repair ../../repo1/linked &&
	test_cmp repo1/main.expect repo1/main/.git/worktrees/linked/gitdir &&
	test_cmp repo1/linked.expect repo1/linked/.git &&
	test_cmp repo2/main.expect repo2/main/.git/worktrees/linked/gitdir &&
	test_cmp repo2/linked.expect repo2/linked/.git
    '

- Caleb

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-08 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-23  7:54 [PATCH] worktree: repair copied repository and linked worktrees Eric Sunshine
2024-09-23  8:04 ` Eric Sunshine
2024-09-23 21:22 ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2024-10-08 15:30 Caleb White
2024-10-08 15:53 ` Caleb White

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).