threads / discuss / 41239

Add post-worktree-add hook?

Subject: Add post-worktree-add hook?

## tl;dr

2 messages between Jan 22, 2016 and Jan 22, 2016.

replies: 1people: 2as markdown or json

Duy Nguyen· Jan 22, 2016, 09:45 UTC · lore

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· Jan 22, 2016, 17:28 UTC · re: Duy Nguyen · lore

Re: Add post-worktree-add hook?

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).

← back to recent threads