git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] builtin/worktree.c: add option for setting worktree name
@ 2016-06-25  5:15 Barret Rennie
  2016-06-25  6:17 ` Junio C Hamano
  2016-06-25  7:15 ` Johannes Sixt
  0 siblings, 2 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-25  5:15 UTC (permalink / raw)
  To: git
  Cc: Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo, Barret Rennie

Add the --name parameter to git worktree add that allows the user to set
the name of the created worktree directory. A worktree must not already
exist with the current name or creation will fail.

Signed-off-by: Barret Rennie <barret@brennie.ca>
---
 Documentation/git-worktree.txt |  6 +++++-
 builtin/worktree.c             | 24 ++++++++++++++++++------
 t/t2025-worktree-add.sh        | 16 ++++++++++++++++
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 23d8d2a..2af0ee4 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees
 SYNOPSIS
 --------
 [verse]
-'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] <path> [<branch>]
+'git worktree add' [-f] [--detach] [--checkout] [-b <new-branch>] [--name <name>] <path> [<branch>]
 'git worktree prune' [-n] [-v] [--expire <expire>]
 'git worktree list' [--porcelain]
 
@@ -88,6 +88,10 @@ OPTIONS
 	With `add`, detach HEAD in the new working tree. See "DETACHED HEAD"
 	in linkgit:git-checkout[1].
 
+--name::
+	Set the name for the worktree. If there is already a worktree with this
+	name, the command will fail.
+
 --[no-]checkout::
 	By default, `add` checks out `<branch>`, however, `--no-checkout` can
 	be used to suppress checkout in order to make customizations,
diff --git a/builtin/worktree.c b/builtin/worktree.c
index e3199a2..ed071b2 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -24,6 +24,7 @@ struct add_opts {
 	int checkout;
 	const char *new_branch;
 	int force_new_branch;
+	const char *name;
 };
 
 static int show_only;
@@ -212,19 +213,29 @@ static int add_worktree(const char *path, const char *refname,
 			die(_("invalid reference: %s"), refname);
 	}
 
-	name = worktree_basename(path, &len);
+	if (opts->name) {
+		name = opts->name;
+		len = strlen(name);
+	} else {
+		name = worktree_basename(path, &len);
+	}
+
 	strbuf_addstr(&sb_repo,
 		      git_path("worktrees/%.*s", (int)(path + len - name), name));
+
 	len = sb_repo.len;
 	if (safe_create_leading_directories_const(sb_repo.buf))
 		die_errno(_("could not create leading directories of '%s'"),
 			  sb_repo.buf);
-	while (!stat(sb_repo.buf, &st)) {
-		counter++;
-		strbuf_setlen(&sb_repo, len);
-		strbuf_addf(&sb_repo, "%d", counter);
+
+	if (!opts->name) {
+		while (!stat(sb_repo.buf, &st)) {
+			counter++;
+			strbuf_setlen(&sb_repo, len);
+			strbuf_addf(&sb_repo, "%d", counter);
+		}
+		name = strrchr(sb_repo.buf, '/') + 1;
 	}
-	name = strrchr(sb_repo.buf, '/') + 1;
 
 	junk_pid = getpid();
 	atexit(remove_junk);
@@ -326,6 +337,7 @@ static int add(int ac, const char **av, const char *prefix)
 			   N_("create or reset a branch")),
 		OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
 		OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
+		OPT_STRING(0, "name", &opts.name, N_("name"), N_("set name for working tree")),
 		OPT_END()
 	};
 
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index 4bcc335..9abcf8e 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -63,6 +63,22 @@ test_expect_success '"add" worktree' '
 	)
 '
 
+test_expect_success '"add" worktree with name' '
+	git worktree add --detach --name custom-name another-worktree master &&
+	(
+		cd here &&
+		test_cmp ../init.t init.t
+	) &&
+	(
+		cd .git/worktrees &&
+		test -d custom-name
+	)
+'
+
+test_expect_success '"add" worktree with name that already exists' '
+	test_must_fail git worktree add --name custom-name --detach yet-another-worktree master
+'
+
 test_expect_success '"add" worktree from a subdir' '
 	(
 		mkdir sub &&
-- 
2.9.0


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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  5:15 [PATCH] builtin/worktree.c: add option for setting worktree name Barret Rennie
@ 2016-06-25  6:17 ` Junio C Hamano
  2016-06-25  6:28   ` Barret Rennie
  2016-06-25  7:15 ` Johannes Sixt
  1 sibling, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2016-06-25  6:17 UTC (permalink / raw)
  To: Barret Rennie
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

Barret Rennie <barret@brennie.ca> writes:

> Add the --name parameter to git worktree add that allows the user to set
> the name of the created worktree directory. A worktree must not already
> exist with the current name or creation will fail.

Hmph.  This strongly smells like "because we can add this feature",
not "because we need to add this feature".

What problem does it solve?  Please do not give me "currently we
cannot give a name and instead live with the automatically given
one, and with this patch we can give arbitrary name" as the answer.
That is what I called "because we can".  Why is it bad that you have
to live with the name automatically given to your new worktree?

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  6:17 ` Junio C Hamano
@ 2016-06-25  6:28   ` Barret Rennie
  0 siblings, 0 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-25  6:28 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

This is really to scratch an itch I have when I break my worktrees and can’t figure out which worktree dir is the one I’ve broken. For example, I organize my code as follows:

projects/reviewboard/branches/<branch-name>/src/
	django/
	djblets/  
	reviewboard/

for each release branch I maintain (4 or 5 of them), where each of the above is a worktree checkout of the correct branch. This is so I have all my dependencies for the project at the right development version.

However, when I inevitably break a worktree for, e.g., Review Board, I have to figure out which of reviewboard, reviewboard1, reviewboard2, etc. it is that I’ve broken, instead of being able to just go into the worktree named for the release branch.

Hope this clarifies things.

> On Jun 25, 2016, at 12:17 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Barret Rennie <barret@brennie.ca> writes:
> 
>> Add the --name parameter to git worktree add that allows the user to set
>> the name of the created worktree directory. A worktree must not already
>> exist with the current name or creation will fail.
> 
> Hmph.  This strongly smells like "because we can add this feature",
> not "because we need to add this feature".
> 
> What problem does it solve?  Please do not give me "currently we
> cannot give a name and instead live with the automatically given
> one, and with this patch we can give arbitrary name" as the answer.
> That is what I called "because we can".  Why is it bad that you have
> to live with the name automatically given to your new worktree?


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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  5:15 [PATCH] builtin/worktree.c: add option for setting worktree name Barret Rennie
  2016-06-25  6:17 ` Junio C Hamano
@ 2016-06-25  7:15 ` Johannes Sixt
  2016-06-25  7:29   ` Barret Rennie
                     ` (2 more replies)
  1 sibling, 3 replies; 16+ messages in thread
From: Johannes Sixt @ 2016-06-25  7:15 UTC (permalink / raw)
  To: Barret Rennie
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

Am 25.06.2016 um 07:15 schrieb Barret Rennie:
> +--name::
> +	Set the name for the worktree. If there is already a worktree with this

What is "the name for the worktree"? Is it the directory where it lives 
in? Is it how it is listed with 'git worktree list'?

How is --name different from the <path> argument?

-- Hannes


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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  7:15 ` Johannes Sixt
  2016-06-25  7:29   ` Barret Rennie
@ 2016-06-25  7:29   ` Barret Rennie
  2016-06-25  7:32   ` Barret Rennie
  2 siblings, 0 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-25  7:29 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

> What is "the name for the worktree"? Is it the directory where it lives in?
>Is it how it is listed with 'git worktree list'?

The name of the worktree is the name of the created directory in
`.git/worktrees`.

> How is --name different from the <path> argument?

Currently, if you run:
	
	git worktree add /my/worktree/checkout <branch>

you get a worktree "named" checkout, i.e., `.git/worktrees/checkout`. The
idea with this patch is to allow you use a more specific name when you would
otherwise have mulitiple worktrees of the form `checkout`, `checkout1`, etc.

That is, you could do

	git worktree add --name branch1 /worktrees/branch1/src branch1
	git worktree add --name branch2 /worktrees/branch2/src branch2
	git worktree add --name branch3 /worktrees/branch3/src branch3

and have `.git/worktrees/branch1`, `.git/worktrees/branch2` and
`.git/worktrees/branch3` instead of `.git/worktrees/src`,
`.git/worktrees/src1`, `.git/worktrees/src2`. That way, it becomes more clear
when poking inside `.git/worktrees` which directory points to which checkout.

Perhaps "worktree name" isn't the most clear nomenclature for this feature.
Would "worktree directory name" be better?

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  7:15 ` Johannes Sixt
@ 2016-06-25  7:29   ` Barret Rennie
  2016-06-25 19:45     ` Junio C Hamano
  2016-06-25  7:29   ` Barret Rennie
  2016-06-25  7:32   ` Barret Rennie
  2 siblings, 1 reply; 16+ messages in thread
From: Barret Rennie @ 2016-06-25  7:29 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

> What is "the name for the worktree"? Is it the directory where it lives in?
>Is it how it is listed with 'git worktree list'?

The name of the worktree is the name of the created directory in
`.git/worktrees`.

> How is --name different from the <path> argument?

Currently, if you run:
	
	git worktree add /my/worktree/checkout <branch>

you get a worktree "named" checkout, i.e., `.git/worktrees/checkout`. The
idea with this patch is to allow you use a more specific name when you would
otherwise have mulitiple worktrees of the form `checkout`, `checkout1`, etc.

That is, you could do

	git worktree add --name branch1 /worktrees/branch1/src branch1
	git worktree add --name branch2 /worktrees/branch2/src branch2
	git worktree add --name branch3 /worktrees/branch3/src branch3

and have `.git/worktrees/branch1`, `.git/worktrees/branch2` and
`.git/worktrees/branch3` instead of `.git/worktrees/src`,
`.git/worktrees/src1`, `.git/worktrees/src2`. That way, it becomes more clear
when poking inside `.git/worktrees` which directory points to which checkout.

Perhaps "worktree name" isn't the most clear nomenclature for this feature.
Would "worktree directory name" be better?

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  7:15 ` Johannes Sixt
  2016-06-25  7:29   ` Barret Rennie
  2016-06-25  7:29   ` Barret Rennie
@ 2016-06-25  7:32   ` Barret Rennie
  2 siblings, 0 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-25  7:32 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: git, Eric Sunshine, Nguyễn Thái Ngọc Duy,
	Michael Rappazzo

Sorry for replying to that message twice. I hit a bug in Apple Mail.

--Barret

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25  7:29   ` Barret Rennie
@ 2016-06-25 19:45     ` Junio C Hamano
  2016-06-25 20:19       ` Barret Rennie
                         ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Junio C Hamano @ 2016-06-25 19:45 UTC (permalink / raw)
  To: Barret Rennie
  Cc: Johannes Sixt, git, Eric Sunshine,
	Nguyễn Thái Ngọc Duy, Michael Rappazzo

Barret Rennie <barret@brennie.ca> writes:

>> What is "the name for the worktree"? Is it the directory where it lives in?
>>Is it how it is listed with 'git worktree list'?
>
> The name of the worktree is the name of the created directory in
> `.git/worktrees`.
>
>> How is --name different from the <path> argument?
>
> Currently, if you run:
> 	
> 	git worktree add /my/worktree/checkout <branch>
>
> you get a worktree "named" checkout, i.e., `.git/worktrees/checkout`. The
> idea with this patch is to allow you use a more specific name when you would
> otherwise have mulitiple worktrees of the form `checkout`, `checkout1`, etc.
>
> That is, you could do
>
> 	git worktree add --name branch1 /worktrees/branch1/src branch1
> 	git worktree add --name branch2 /worktrees/branch2/src branch2
> 	git worktree add --name branch3 /worktrees/branch3/src branch3
>
> and have `.git/worktrees/branch1`, `.git/worktrees/branch2` and
> `.git/worktrees/branch3` instead of `.git/worktrees/src`,
> `.git/worktrees/src1`, `.git/worktrees/src2`. That way, it becomes more clear
> when poking inside `.git/worktrees` which directory points to which checkout.

That is a way better justification of "why we need to use a custom
name, not the default one" than the previous "with this we can use a
custom name".

As long as you can justify why having anything underneath branch$n/
is necessary, that is.  In your explanation above, it is still
unclear why you need a checkout at /worktrees/branch$n/src/, and why
it would not work if it is at /worktrees/branch$n/.

Note that I am not saying "there cannot be a good reason, do not add
this feature" when I say "it is unclear why".  I am encouraging you
and others in this discussion thread to find good use cases for the
proposed new feature and come up with materials to help improving
the documentation part of the patch.  That way, the users with
similar needs can find how the feature is supposed to be used and
understand the feature better.

I suspect that this new feature might be useful when two more more
interdependent projects (they could be organized as submodules in a
superproject, but they can be independent checkouts of different
projects) are used together.  Imagine frotz and nitfol projects, and
without fancier setup to have multiple checkouts, you may be
expected (by these two projects) to check them out like so:

    $top/frotz/
    $top/libs/nitfol/

where $top can be anywhere but to clarify the line of thought, lets
pick a concrete place, say $HOME/xyzzy.  So without worktrees, you
would have

    $HOME/xyzzy/frotz
    $HOME/xyzzy/libs/nitfol

Now, if you do the worktree, you may still want the relative
structure between these two, i.e. if you want to work on two
different branch combinations of the whole thing, you would want to
do this:

    $HOME/xyzzy-1/frotz       - borrow from $HOME/xyzzy/frotz
    $HOME/xyzzy-1/libs/nitfol - likewise for nitfol

    $HOME/xyzzy-2/frotz       - borrow from $HOME/xyzzy/frotz
    $HOME/xyzzy-2/libs/nitfol - likewise for nitfol

where xyzzy-$n may be for topic-$n branch both in frotz and nitfol.

And explained that way, it becomes clearer that you would want to
name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
name you would get "frotz" (because the default gives you the leaf
level name of the newly created worktree).

After the discussion above (which may or may not match what you
raised this topic for), I think a feature to let you override the
default name makes sense.

It just needs to be explained better to help the users when the
feature eventually becomes part of Git.  Also, others (especially
Duy) may have even better ideas (e.g. instead of having to always
use --name to give custom name for all worktrees, set a "hint" just
once to help the logic that comes up with the default name give a
better name), so while the feature may be desirable, your exact
implementation may or may not be what we eventually want to adopt.

Thanks.



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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25 19:45     ` Junio C Hamano
@ 2016-06-25 20:19       ` Barret Rennie
  2016-06-26 18:15       ` Junio C Hamano
  2016-06-26 23:00       ` Eric Sunshine
  2 siblings, 0 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-25 20:19 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git, Eric Sunshine,
	Nguyễn Thái Ngọc Duy, Michael Rappazzo


> On Jun 25, 2016, at 1:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Barret Rennie <barret@brennie.ca> writes:
> 
>>> What is "the name for the worktree"? Is it the directory where it lives in?
>>> Is it how it is listed with 'git worktree list'?
>> 
>> The name of the worktree is the name of the created directory in
>> `.git/worktrees`.
>> 
>>> How is --name different from the <path> argument?
>> 
>> Currently, if you run:
>> 	
>> 	git worktree add /my/worktree/checkout <branch>
>> 
>> you get a worktree "named" checkout, i.e., `.git/worktrees/checkout`. The
>> idea with this patch is to allow you use a more specific name when you would
>> otherwise have mulitiple worktrees of the form `checkout`, `checkout1`, etc.
>> 
>> That is, you could do
>> 
>> 	git worktree add --name branch1 /worktrees/branch1/src branch1
>> 	git worktree add --name branch2 /worktrees/branch2/src branch2
>> 	git worktree add --name branch3 /worktrees/branch3/src branch3
>> 
>> and have `.git/worktrees/branch1`, `.git/worktrees/branch2` and
>> `.git/worktrees/branch3` instead of `.git/worktrees/src`,
>> `.git/worktrees/src1`, `.git/worktrees/src2`. That way, it becomes more clear
>> when poking inside `.git/worktrees` which directory points to which checkout.
> 
> That is a way better justification of "why we need to use a custom
> name, not the default one" than the previous "with this we can use a
> custom name".
> 
> As long as you can justify why having anything underneath branch$n/
> is necessary, that is.  In your explanation above, it is still
> unclear why you need a checkout at /worktrees/branch$n/src/, and why
> it would not work if it is at /worktrees/branch$n/.

That was a less-than-concrete example, I'll grant you. I do follow the method
you suggest below for the projects I maintain with this workflow.

> 
> Note that I am not saying "there cannot be a good reason, do not add
> this feature" when I say "it is unclear why".  I am encouraging you
> and others in this discussion thread to find good use cases for the
> proposed new feature and come up with materials to help improving
> the documentation part of the patch.  That way, the users with
> similar needs can find how the feature is supposed to be used and
> understand the feature better.
> 
> I suspect that this new feature might be useful when two more more
> interdependent projects (they could be organized as submodules in a
> superproject, but they can be independent checkouts of different
> projects) are used together.  Imagine frotz and nitfol projects, and
> without fancier setup to have multiple checkouts, you may be
> expected (by these two projects) to check them out like so:
> 
>    $top/frotz/
>    $top/libs/nitfol/
> 
> where $top can be anywhere but to clarify the line of thought, lets
> pick a concrete place, say $HOME/xyzzy.  So without worktrees, you
> would have
> 
>    $HOME/xyzzy/frotz
>    $HOME/xyzzy/libs/nitfol
> 
> Now, if you do the worktree, you may still want the relative
> structure between these two, i.e. if you want to work on two
> different branch combinations of the whole thing, you would want to
> do this:
> 
>    $HOME/xyzzy-1/frotz       - borrow from $HOME/xyzzy/frotz
>    $HOME/xyzzy-1/libs/nitfol - likewise for nitfol
> 
>    $HOME/xyzzy-2/frotz       - borrow from $HOME/xyzzy/frotz
>    $HOME/xyzzy-2/libs/nitfol - likewise for nitfol
> 
> where xyzzy-$n may be for topic-$n branch both in frotz and nitfol.
> 
> And explained that way, it becomes clearer that you would want to
> name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
> name you would get "frotz" (because the default gives you the leaf
> level name of the newly created worktree).
> 
> After the discussion above (which may or may not match what you
> raised this topic for), I think a feature to let you override the
> default name makes sense.
> 
> It just needs to be explained better to help the users when the
> feature eventually becomes part of Git.  Also, others (especially
> Duy) may have even better ideas (e.g. instead of having to always
> use --name to give custom name for all worktrees, set a "hint" just
> once to help the logic that comes up with the default name give a
> better name), so while the feature may be desirable, your exact
> implementation may or may not be what we eventually want to adopt.

Would you like me to re-submit this with a more detailed
explanation in the commit message? Also, I agree that always having
to use `--name` to set a custom name could be possibly cumbersome.
An alternate way I can think of would be to a config option such as
`worktree.nameHint` which would let you set the kind of name you'd
like for your worktrees, say `default` (the current behaviour) or
`branch` (where it would be named <topic-branch><n>).

The only issue I have with that is I maintain two projects that
have a dependency on the same version of a library. My current
project directory looks like the following:

projects/reviewboard/branches/
	2.5.x/
		reviewboard/  # Version 2.0
		djblets/      # Version 0.8
	3.0.x/
		reviewboard/  # Version 3.0
		djblets/      # Version 0.10

projects/splat/src/
	splat/    # master checkout
	djblets/  # Version 0.10

If we used some sort of hint system, I'd end up with two worktrees
named something like `release-0.10.x` and `release-0.10.x1`, which
is better than the current situation, but still not ideal for my
use case.

If someone suggests a better scheme for naming the worktrees, I'd
be happy to rewrite this patch to use it.

> Thanks.
Thanks for reviewing.


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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25 19:45     ` Junio C Hamano
  2016-06-25 20:19       ` Barret Rennie
@ 2016-06-26 18:15       ` Junio C Hamano
  2016-06-27  5:40         ` Barret Rennie
  2016-06-26 23:00       ` Eric Sunshine
  2 siblings, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2016-06-26 18:15 UTC (permalink / raw)
  To: Barret Rennie
  Cc: Johannes Sixt, git, Eric Sunshine,
	Nguyễn Thái Ngọc Duy, Michael Rappazzo

Junio C Hamano <gitster@pobox.com> writes:

> Now, if you do the worktree, you may still want the relative
> structure between these two, i.e. if you want to work on two
> different branch combinations of the whole thing, you would want to
> do this:
>
>     $HOME/xyzzy-1/frotz       - borrow from $HOME/xyzzy/frotz
>     $HOME/xyzzy-1/libs/nitfol - likewise for nitfol
>
>     $HOME/xyzzy-2/frotz       - borrow from $HOME/xyzzy/frotz
>     $HOME/xyzzy-2/libs/nitfol - likewise for nitfol
>
> where xyzzy-$n may be for topic-$n branch both in frotz and nitfol.
>
> And explained that way, it becomes clearer that you would want to
> name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
> name you would get "frotz" (because the default gives you the leaf
> level name of the newly created worktree).
>
> After the discussion above (which may or may not match what you
> raised this topic for), I think a feature to let you override the
> default name makes sense.
>
> It just needs to be explained better to help the users when the
> feature eventually becomes part of Git.  Also, others (especially
> Duy) may have even better ideas (e.g. instead of having to always
> use --name to give custom name for all worktrees, set a "hint" just
> once to help the logic that comes up with the default name give a
> better name), so while the feature may be desirable, your exact
> implementation may or may not be what we eventually want to adopt.

For example, the "frotz" and "nitfol" repositories (i.e. where their
worktrees borrow their refs and object stores from) could have a
single configuration variable each, i.e.

	(in $HOME/xyzzy/frotz/.git/config)
        [worktree] location = "~/*/frotz"

	(in $HOME/xyzzy/libs/nitfol/.git/config)
        [worktree] location = "~/*/libs/nitfol"

and then the user could do in each of these two repositories

	$ git -C ~/xyzzy/frotz worktree add --by-name xyzzy-1 topic-1
	$ git -C ~/xyzzy/lib/nitfol worktree add --by-name xyzzy-1 topic-1

to get the desired layout instead.

The traditional way may be "create one HERE", and your patch tries
to tweak it to "create one at HERE with this NAME".  The above
attempts to remove the need for specifying the exact location every
time a new worktree is created, and instead let you specify the
systematic way in which you lay out your worktrees based on their
names.


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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-25 19:45     ` Junio C Hamano
  2016-06-25 20:19       ` Barret Rennie
  2016-06-26 18:15       ` Junio C Hamano
@ 2016-06-26 23:00       ` Eric Sunshine
  2016-06-27  5:52         ` Barret Rennie
  2 siblings, 1 reply; 16+ messages in thread
From: Eric Sunshine @ 2016-06-26 23:00 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Barret Rennie, Johannes Sixt, Git List,
	Nguyễn Thái Ngọc, Michael Rappazzo

On Sat, Jun 25, 2016 at 3:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
> [...snip...]
> And explained that way, it becomes clearer that you would want to
> name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
> name you would get "frotz" (because the default gives you the leaf
> level name of the newly created worktree).
>
> After the discussion above (which may or may not match what you
> raised this topic for), I think a feature to let you override the
> default name makes sense.

One thing which hasn't been explained, and about which I'm still
confused even after reading this thread in its entirety, is what
Barret means when he says that he "breaks" his worktrees. What is the
nature of this breakage? Depending upon that answer, would "git
rev-parse --git-dir" be sufficient for your needs? Or, would "git
worktree list" be able to give you the desired information? (As
envisioned, "git worktree list" was intended to provide much more
information than it currently does, such as the .git/worktree dir
name, and such an enhancement might be welcome.)

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-26 18:15       ` Junio C Hamano
@ 2016-06-27  5:40         ` Barret Rennie
  2016-06-27 13:17           ` Junio C Hamano
  0 siblings, 1 reply; 16+ messages in thread
From: Barret Rennie @ 2016-06-27  5:40 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git, Eric Sunshine,
	Nguyễn Thái Ngọc Duy, Michael Rappazzo


> On Jun 26, 2016, at 12:15 PM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Junio C Hamano <gitster@pobox.com> writes:
> 
>> Now, if you do the worktree, you may still want the relative
>> structure between these two, i.e. if you want to work on two
>> different branch combinations of the whole thing, you would want to
>> do this:
>> 
>>    $HOME/xyzzy-1/frotz       - borrow from $HOME/xyzzy/frotz
>>    $HOME/xyzzy-1/libs/nitfol - likewise for nitfol
>> 
>>    $HOME/xyzzy-2/frotz       - borrow from $HOME/xyzzy/frotz
>>    $HOME/xyzzy-2/libs/nitfol - likewise for nitfol
>> 
>> where xyzzy-$n may be for topic-$n branch both in frotz and nitfol.
>> 
>> And explained that way, it becomes clearer that you would want to
>> name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
>> name you would get "frotz" (because the default gives you the leaf
>> level name of the newly created worktree).
>> 
>> After the discussion above (which may or may not match what you
>> raised this topic for), I think a feature to let you override the
>> default name makes sense.
>> 
>> It just needs to be explained better to help the users when the
>> feature eventually becomes part of Git.  Also, others (especially
>> Duy) may have even better ideas (e.g. instead of having to always
>> use --name to give custom name for all worktrees, set a "hint" just
>> once to help the logic that comes up with the default name give a
>> better name), so while the feature may be desirable, your exact
>> implementation may or may not be what we eventually want to adopt.
> 
> For example, the "frotz" and "nitfol" repositories (i.e. where their
> worktrees borrow their refs and object stores from) could have a
> single configuration variable each, i.e.
> 
> 	(in $HOME/xyzzy/frotz/.git/config)
>        [worktree] location = "~/*/frotz"
> 
> 	(in $HOME/xyzzy/libs/nitfol/.git/config)
>        [worktree] location = "~/*/libs/nitfol"
> 
> and then the user could do in each of these two repositories
> 
> 	$ git -C ~/xyzzy/frotz worktree add --by-name xyzzy-1 topic-1
> 	$ git -C ~/xyzzy/lib/nitfol worktree add --by-name xyzzy-1 topic-1
> 
> to get the desired layout instead.
> 
> The traditional way may be "create one HERE", and your patch tries
> to tweak it to "create one at HERE with this NAME".  The above
> attempts to remove the need for specifying the exact location every
> time a new worktree is created, and instead let you specify the
> systematic way in which you lay out your worktrees based on their
> names.

Are you proposing that `--by-name` creates a worktree in the current working
directory or that the default behaviour of `git worktree add` is changed to
to create the worktree in the current working directory when executed with
only one argument (the branch)?

In either case, I'm not sure what `worktree.location` does here, since we're
creating the worktree in the working directory, unless I'm misunderstanding
your example.

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-26 23:00       ` Eric Sunshine
@ 2016-06-27  5:52         ` Barret Rennie
  2016-06-27 23:11           ` Eric Sunshine
  0 siblings, 1 reply; 16+ messages in thread
From: Barret Rennie @ 2016-06-27  5:52 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Junio C Hamano, Johannes Sixt, Git List,
	Nguyễn Thái Ngọc, Michael Rappazzo


> On Jun 26, 2016, at 5:00 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> On Sat, Jun 25, 2016 at 3:45 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> [...snip...]
>> And explained that way, it becomes clearer that you would want to
>> name $HOME/xyzzy-1/frotz worktree after "topic-1", not the default
>> name you would get "frotz" (because the default gives you the leaf
>> level name of the newly created worktree).
>> 
>> After the discussion above (which may or may not match what you
>> raised this topic for), I think a feature to let you override the
>> default name makes sense.
> 
> One thing which hasn't been explained, and about which I'm still
> confused even after reading this thread in its entirety, is what
> Barret means when he says that he "breaks" his worktrees. What is the
> nature of this breakage? Depending upon that answer, would "git
> rev-parse --git-dir" be sufficient for your needs? Or, would "git
> worktree list" be able to give you the desired information? (As
> envisioned, "git worktree list" was intended to provide much more
> information than it currently does, such as the .git/worktree dir
> name, and such an enhancement might be welcome.)

My worktree breakages are usually the result of my reorganizing my projects,
usually because a branch changes name (for example, if branch release-1 gets
pushed back to release-2). Then I go and rename all my directories and git 
gets unhappy and I have to manually fix them or re-create the worktrees.

Having `git worktree list` give the worktree directory would be very useful,
but I still would like the ability to change the name of a worktree.

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-27  5:40         ` Barret Rennie
@ 2016-06-27 13:17           ` Junio C Hamano
  0 siblings, 0 replies; 16+ messages in thread
From: Junio C Hamano @ 2016-06-27 13:17 UTC (permalink / raw)
  To: Barret Rennie
  Cc: Johannes Sixt, git, Eric Sunshine,
	Nguyễn Thái Ngọc Duy, Michael Rappazzo

Barret Rennie <barret@brennie.ca> writes:

>> For example, the "frotz" and "nitfol" repositories (i.e. where their
>> worktrees borrow their refs and object stores from) could have a
>> single configuration variable each, i.e.
>> 
>> 	(in $HOME/xyzzy/frotz/.git/config)
>>        [worktree] location = "~/*/frotz"
>> 
>> 	(in $HOME/xyzzy/libs/nitfol/.git/config)
>>        [worktree] location = "~/*/libs/nitfol"
>> 
>> and then the user could do in each of these two repositories
>> 
>> 	$ git -C ~/xyzzy/frotz worktree add --by-name xyzzy-1 topic-1
>> 	$ git -C ~/xyzzy/lib/nitfol worktree add --by-name xyzzy-1 topic-1
>> 
>> to get the desired layout instead.
>> 
>> The traditional way may be "create one HERE", and your patch tries
>> to tweak it to "create one at HERE with this NAME".  The above
>> attempts to remove the need for specifying the exact location every
>> time a new worktree is created, and instead let you specify the
>> systematic way in which you lay out your worktrees based on their
>> names.
>
> Are you proposing that `--by-name` creates a worktree in the current working
> directory or that the default behaviour of `git worktree add` is changed to
> to create the worktree in the current working directory when executed with
> only one argument (the branch)?

It is not a proposal but an illustration of what I meant by "hint".

What I am envisioning is that we may enhance the "worktree add"
subcommand to take two forms.  In addition to traditional

    $ git worktree add [opts] <path> [<branch>]

when worktree.location configuration is present, you could say

    $ git worktree add [opts] --by-name <name> [<branch>]

omitting <path> and instead giving <name>.  Use the <name> to
substitute the wildcard in the pattern given by worktree.location,
i.e. with the above example for "frotz",

    $ git worktree add --by-name xyzzy-1 topic-1

because the worktree.location configuration is set to "~/*/frotz",
that would act as if <path> was given as ~/xyzzy-1/frotz.  Name is
set to xyzzy-1, and the newly created worktree would initially check
out topic-1 branch.

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-27  5:52         ` Barret Rennie
@ 2016-06-27 23:11           ` Eric Sunshine
  2016-06-29  4:45             ` Barret Rennie
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Sunshine @ 2016-06-27 23:11 UTC (permalink / raw)
  To: Barret Rennie
  Cc: Junio C Hamano, Johannes Sixt, Git List,
	Nguyễn Thái Ngọc, Michael Rappazzo

On Mon, Jun 27, 2016 at 1:52 AM, Barret Rennie <barret@brennie.ca> wrote:
> On Jun 26, 2016, at 5:00 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> One thing which hasn't been explained, and about which I'm still
>> confused even after reading this thread in its entirety, is what
>> Barret means when he says that he "breaks" his worktrees. What is the
>> nature of this breakage? Depending upon that answer, would "git
>> rev-parse --git-dir" be sufficient for your needs? Or, would "git
>> worktree list" be able to give you the desired information? (As
>> envisioned, "git worktree list" was intended to provide much more
>> information than it currently does, such as the .git/worktree dir
>> name, and such an enhancement might be welcome.)
>
> My worktree breakages are usually the result of my reorganizing my projects,
> usually because a branch changes name (for example, if branch release-1 gets
> pushed back to release-2). Then I go and rename all my directories and git
> gets unhappy and I have to manually fix them or re-create the worktrees.

Quoting from your earlier email justifying why you consider this patch
desirable:

    ...when I break my worktrees and can’t figure out
    which worktree dir is the one I’ve broken.

But, doesn't "git rev-parse --git-dir" from within a "broken" worktree
answer that question? Or, wouldn't an enhanced "git worktree list"
answer the question from the opposite side?

> Having `git worktree list` give the worktree directory would be very useful,
> but I still would like the ability to change the name of a worktree.

My knee-jerk reaction is that the directory name under .git/worktrees
is an implementation detail (and could easily have been an arbitrary
ID, such as .git/worktrees/7ba84ec0) and rather than exposing it
further and encouraging people to muck around in it manually, we
should be providing higher-level solutions so that they don't have to.

Even without the higher-level solutions, it seems like "git rev-parse
--git-dir" should satisfy your needs, and if someone enhances "git
worktree list" to provide the additional worktree tag name (as
envisioned all along), then you'd likewise have sufficient information
to "fix" your worktrees.

As an example of higher-level solutions, Duy's "git worktree move"
series[1] would, I think, be exactly what you need to avoid such
breakage in the first place (assuming you can retrain your fingers or
fix your scripts, if they are doing the worktree renaming).

I don't know how Duy and Junio feel about it, but my response to this
patch and what it wants to accomplish (even with Junio's input) is
fairly negative. I'd much rather see more missing high-level worktree
features implemented rather than see patches further exposing
git-worktree's internals.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/298194

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

* Re: [PATCH] builtin/worktree.c: add option for setting worktree name
  2016-06-27 23:11           ` Eric Sunshine
@ 2016-06-29  4:45             ` Barret Rennie
  0 siblings, 0 replies; 16+ messages in thread
From: Barret Rennie @ 2016-06-29  4:45 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Junio C Hamano, Johannes Sixt, Git List,
	Nguyễn Thái Ngọc, Michael Rappazzo


> On Jun 27, 2016, at 5:11 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> [snip]
> 
> My knee-jerk reaction is that the directory name under .git/worktrees
> is an implementation detail (and could easily have been an arbitrary
> ID, such as .git/worktrees/7ba84ec0) and rather than exposing it
> further and encouraging people to muck around in it manually, we
> should be providing higher-level solutions so that they don't have to.
> 
> Even without the higher-level solutions, it seems like "git rev-parse
> --git-dir" should satisfy your needs, and if someone enhances "git
> worktree list" to provide the additional worktree tag name (as
> envisioned all along), then you'd likewise have sufficient information
> to "fix" your worktrees.
> 
> As an example of higher-level solutions, Duy's "git worktree move"
> series[1] would, I think, be exactly what you need to avoid such
> breakage in the first place (assuming you can retrain your fingers or
> fix your scripts, if they are doing the worktree renaming).
> 
> I don't know how Duy and Junio feel about it, but my response to this
> patch and what it wants to accomplish (even with Junio's input) is
> fairly negative. I'd much rather see more missing high-level worktree
> features implemented rather than see patches further exposing
> git-worktree's internals.
> 
> [1]: http://thread.gmane.org/gmane.comp.version-control.git/298194
Yes, it does seem like `git worktree move` will  solve all my issues and
is a much more elegant solution. Thanks for pointing it out to me and
looking at this patch.

I may write a patch to print out the worktree tag name instead and submit
that later.

Regards,
Barret Rennie

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

end of thread, other threads:[~2016-06-29  4:45 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-25  5:15 [PATCH] builtin/worktree.c: add option for setting worktree name Barret Rennie
2016-06-25  6:17 ` Junio C Hamano
2016-06-25  6:28   ` Barret Rennie
2016-06-25  7:15 ` Johannes Sixt
2016-06-25  7:29   ` Barret Rennie
2016-06-25 19:45     ` Junio C Hamano
2016-06-25 20:19       ` Barret Rennie
2016-06-26 18:15       ` Junio C Hamano
2016-06-27  5:40         ` Barret Rennie
2016-06-27 13:17           ` Junio C Hamano
2016-06-26 23:00       ` Eric Sunshine
2016-06-27  5:52         ` Barret Rennie
2016-06-27 23:11           ` Eric Sunshine
2016-06-29  4:45             ` Barret Rennie
2016-06-25  7:29   ` Barret Rennie
2016-06-25  7:32   ` Barret Rennie

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).