# 'git worktree add' does not fire post-checkout hook

3 messages from 2017-12-06 to 2017-12-07. Participants: Gumbel, Matthew K, Eric Sunshine.
Thread: https://gitlist.dev/t/47389

## Gumbel, Matthew K, 2017-12-06 21:00

Subject: 'git worktree add' does not fire post-checkout hook
Message-ID: <DA0A42D68346B1469147552440A64503C60832DB@ORSMSX105.amr.corp.intel.com>
URL: https://gitlist.dev/e/DA0A42D68346B1469147552440A64503C60832DB%40ORSMSX105.amr.corp.intel.com

```
Hello all,

I've noticed that when I run 'git worktree add /path/to/new/tree', the post-checkout hook does not fire, even though the worktree manpage explicitly states that "worktree add" will, "Create <path> and checkout <branch> into it."

Is this the intended behavior? Seems like maybe a bug, but I'm not sure.

Thanks
Matt



```

## Eric Sunshine, 2017-12-06 21:45

Subject: Re: 'git worktree add' does not fire post-checkout hook
Message-ID: <CAPig+cQXeC5Nh+=rO9U46PNgnNALd4H3on+feo_NzMg45HqUkQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQXeC5Nh%2B%3DrO9U46PNgnNALd4H3on%2Bfeo_NzMg45HqUkQ%40mail.gmail.com
In-Reply-To: <DA0A42D68346B1469147552440A64503C60832DB@ORSMSX105.amr.corp.intel.com>

```
On Wed, Dec 6, 2017 at 4:00 PM, Gumbel, Matthew K
<matthew.k.gumbel@intel.com> wrote:
> I've noticed that when I run 'git worktree add /path/to/new/tree',
> the post-checkout hook does not fire, even though the worktree
> manpage explicitly states that "worktree add" will, "Create <path>
> and checkout <branch> into it."
>
> Is this the intended behavior? Seems like maybe a bug, but I'm not
> sure.

Seems like an oversight. Given that 'git worktree' is like a cross of
'git clone' and 'git checkout', both of which run that hook, it seems
reasonable that 'git-worktree' should do so, as well.

If you'd like to get your feet wet at contributing to the Git project,
this might be a good first dip, as it looks like an easy fix (a one-
or two-liner). The only thing which needs a bit of care is to skip the
hook when --no-checkout is specified. Other than that, 'githooks'
documentation would need an update to mention that git-worktree also
runs the hook, and t2025-worktree-add.sh would want a couple new tests
(which would probably be the most complex part of the patch).

```

## Eric Sunshine, 2017-12-07 10:19

Subject: Re: 'git worktree add' does not fire post-checkout hook
Message-ID: <CAPig+cRAth85f+Euim8Sw7An8UQQeOAo6e6kVP_yruw400aJug@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcRAth85f%2BEuim8Sw7An8UQQeOAo6e6kVP_yruw400aJug%40mail.gmail.com
In-Reply-To: <CAPig+cQXeC5Nh+=rO9U46PNgnNALd4H3on+feo_NzMg45HqUkQ@mail.gmail.com>

```
On Wed, Dec 6, 2017 at 4:45 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Wed, Dec 6, 2017 at 4:00 PM, Gumbel, Matthew K
> <matthew.k.gumbel@intel.com> wrote:
>> I've noticed that when I run 'git worktree add /path/to/new/tree',
>> the post-checkout hook does not fire, even though the worktree
>> manpage explicitly states that "worktree add" will, "Create <path>
>> and checkout <branch> into it."
>>
>> Is this the intended behavior? Seems like maybe a bug, but I'm not
>> sure.
>
> If you'd like to get your feet wet at contributing to the Git project,
> this might be a good first dip, as it looks like an easy fix (a one-
> or two-liner). The only thing which needs a bit of care is to skip the
> hook when --no-checkout is specified. Other than that, 'githooks'
> documentation would need an update to mention that git-worktree also
> runs the hook, and t2025-worktree-add.sh would want a couple new tests
> (which would probably be the most complex part of the patch).

I worked up a patch to fix this oversight which I'll try to send out
later today.

```
