# Add post-worktree-add hook?

2 messages from 2016-01-22 to 2016-01-22. Participants: Duy Nguyen, Junio C Hamano.
Thread: https://gitlist.dev/t/41239

## Duy Nguyen, 2016-01-22 09:45

Subject: Add post-worktree-add hook?
Message-ID: <CACsJy8C9OELrkHZLzwoRx26AtzVvgouRA2+m0VH7GrJGSA8PCQ@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8C9OELrkHZLzwoRx26AtzVvgouRA2%2Bm0VH7GrJGSA8PCQ%40mail.gmail.com

```
I started moving my git work space to multi-worktree and found it
annoying that every time I add a new worktree, my first step must be
copy my config.mak over. Room for improvement. I see three options:

1) add an option in 'worktree add' to copy all untracked files from
current worktree over

Only fits when you keep your .gitignore uptodate or we may copy a lot
of rubbish. Good for the lazies who don't want to write hooks though.

2) improve post-checkout hook, pass something else to indicate the
worktree add operation

We also pass the current working directory where 'worktree add' is
executed, so the user can copy selected files from the "source"
worktree if they want.

3) add a new post-worktree-add hook

Pretty much like 2 except that we separate the two. But I don't see
much point in adding this after reading that post-checkout hook is
also executed in git-clone.

Comments?
-- 
Duy

```

## Junio C Hamano, 2016-01-22 17:28

Subject: Re: Add post-worktree-add hook?
Message-ID: <xmqqy4bhv7za.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqy4bhv7za.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <CACsJy8C9OELrkHZLzwoRx26AtzVvgouRA2+m0VH7GrJGSA8PCQ@mail.gmail.com>

```
Duy Nguyen <pclouds@gmail.com> writes:

> I started moving my git work space to multi-worktree and found it
> annoying that every time I add a new worktree, my first step must be
> copy my config.mak over. Room for improvement. I see three options:

4) none of the above.

Everybody should learn to think before uttering post-X hook the
following:

 * Is X an end user initiated action?

 * What does the hypothetical post-X hook need to decide what to do?
   If it needs to change behaviour based on what X did, does it need
   more than what it can get by observing its outcome (i.e. exit
   status and what is left in the working tree and the repository)?

 * Does the hypothetical post-X hook need other end-user supplied
   customization beyond what argument the end user gave to run X?

The answer to these questions would often reveal that post-X hook is
a bad idea and you are much better off with a wrapper script that
runs X as the first thing (and the remainder can do different things
based on the outcome of X if you wanted it to).

```
