Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Eric Sunshine <ericsunshine@gmail.com>
Cc: "D. Ben Knoble" <ben.knoble@gmail.com>,
	Bhushan Gaikwad via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Bhushan Gaikwad <bhushan@alfredscholar.com>
Subject: Re: [PATCH] worktree: allow sharing root files with linked worktrees
Date: Tue, 1 Dec 2026 14:31:05 +0100	[thread overview]
Message-ID: <aw7MGWp_O6cPhFty@pks.im> (raw)
In-Reply-To: <CAPig+cSLCcMzQGZggOBDnwjveKBqKuhNr5c=HFbnbvox1Fm0oA@mail.gmail.com>

On Tue, Dec 01, 2026 at 12:31:20AM -0500, Eric Sunshine wrote:
> On Mon, Nov 30, 2026 at 11:08 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:
> > On Thu, Nov 26, 2026 at 1:25 PM Bhushan Gaikwad via GitGitGadget
> > <gitgitgadget@gmail.com> wrote:
> > > Ignored configuration files such as .env often need to remain identical
> > > across linked worktrees. Today users must copy them manually or install a
> > > post-checkout hook, which is easy to forget and can create divergent local
> > > configuration.
> > >
> > > Add a multi-valued worktree.sharedFile setting. For each configured
> > > root-level regular file, worktree add creates an absolute symbolic link
> > > from the new worktree to the primary worktree before running the
> > > post-checkout hook.
> > >
> > > Reject nested paths and source symlinks, avoid replacing checkout files,
> > > and fail cleanly when symbolic links are unavailable.
> >
> > The limitations and design choices seem odd to me:
> >
> > • On what platforms do we not support symlinks? Wikipedia suggests
> > Windows has equivalents, but our mingw compatibility layer says they
> > are disabled unless MSYS contains winsymlinks:nativestrict, and of
> > course I don't know what other platforms do to customize the build.
> > • Why reject nested paths? A project at work has api/.env{,.example}
> > which might benefit.
> > • Why use absolute symlinks? I suppose that might be annoying when a
> > directory might have a different absolute path on different machines
> > (due to NFS or something)? Is it a security thing, something about
> > relative symlinks becoming a nice target for some kind of exploit?
> 
> For what it's worth, these are the exact same questions/oddities which
> came to my mind upon reading the commit message.
> 
> > I am somewhat negative on making Git do this automatically,
> > personally, especially since the example ".env" is typically ignored
> > (i.e., not managed by Git at all). But that's just my opinion, so if
> > the design is fleshed out and others are positive, ok.
> 
> I am similarly negative on this proposal. While I understand that it
> addresses a real need, I can't help but feel that it is too
> specialized and narrowly focused. It feels quite out of place for the
> otherwise generic worktree mechanism. I could imagine having a more
> favorable reaction to a proposal for a more generally applicable
> solution, however, a very general mechanism already exists in the form
> of hooks. (And, yes, I am aware that the commit message mentions the
> potential downside of employing a hook for this case.)
> 
> Bhushan's alternative proposal[*] of instead documenting a hook recipe
> in git-worktree(1), on the other hand, seems reasonable. Adding a
> sample hook to .git/hooks/ might be even better.
> 
> [*]: https://lore.kernel.org/git/010601a22ff63cd4-ad6646b6-c34d-414e-ad82-1338e97b7d96-000000@ap-northeast-1.amazonses.com/

Sorry for repeating what you're saying, but my immediate reaction was
also that this is way too niche of a use case, and that adding a hook
would be the better solution to this.

But the other question is whether you really need a hook in order to
achieve this. In other words, isn't it sufficient to have a small script
that wraps git-worktree(1) to create the worktree and copy over the
files? We typically only add hooks when there really is no other way to
achieve something, e.g. when it happens in the middle of an operation
performed by Git. But that's not really the case here, as it can be
trivially achieved by such a small wrapper script.

Thanks!

Patrick

      reply	other threads:[~2026-12-01 13:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 18:25 [PATCH] worktree: allow sharing root files with linked worktrees Bhushan Gaikwad via GitGitGadget
2026-11-30 16:08 ` D. Ben Knoble
2026-12-01  4:56   ` Bhushan Gaikwad
2026-12-01  5:31   ` Eric Sunshine
2026-12-01 13:31     ` Patrick Steinhardt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw7MGWp_O6cPhFty@pks.im \
    --to=ps@pks.im \
    --cc=ben.knoble@gmail.com \
    --cc=bhushan@alfredscholar.com \
    --cc=ericsunshine@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox