Re: [PATCH] builtin/worktree.c: add option for setting worktree name
From: Barret Rennie <hidden>
Date: 2016-06-27 05:40:29
On Jun 26, 2016, at 12:15 PM, Junio C Hamano [off-list ref] wrote: Junio C Hamano [off-list ref] writes:quoted
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.