Best way to use post commit git hooks?

So this might not be on topic and apologies if it’s not.

We have a service implemented internally that tracks release tasks and ensures that sub-tasks are added to it regularly to make tracking easier.

I’m attempting to add a post-commit hook to our git repo that will call our to this service.

However I’m running into issues that when I attempt to commit the post-commit hook I run into issues.

git add .git/hooks/post-commit 
git commit
On branch nhendrickson/ticket-tracker-commit-hook
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
no changes added to commit (use "git add" and/or "git commit -a")

Is this something specific to a repo hosted on phabricator? (I wouldn’t think so?)

I was advised to create a hooks.d dir under the repo root to store commit hooks. However those would just be managed and run on the phabricator end no?

That’s not how hooks work. .git directory is outside of version control, so you can’t “add” or “commit” changes to it.

Hooks are local to the location where they are installed; post-commit hook is installed on a developer’s repo, and will only effect this developer. There’s no mechanism in git to distribute/enforce hooks (there are a couple of 3rd party tools for that though).

See Git - Git Hooks for more general information about hooks.

On the server side, you can use pre/post-receive hooks (not commit hooks) that operate during git push flows. In Phabricator, you can use those (see here: ◉ Diffusion User Guide: Commit Hooks, as it’s not trivial), or, better yet, use Herald rules, which are usually easier to work with.

@avivey So for **Git** Put hooks in hooks/pre-receive-phabricator.d/

Could I just add that dir and push it? Or do I need to specifically find the repo on disk on the phabricator host and include it there?

Following that is there somewhere I can find the output of the script once it runs? Should I see that on my client side?

You’ll need to specifically find the repo on disk on the Phabricator host and place the hooks there. You can find the disk location from the repository settings page.
The outputs from the hooks will normally be printed to the user when they run git push (but may be hidden if the user is using some GUI client).

You may also want to consider using a webhook instead of a post-receive hook if your hook does not need to directly interact with the repository and does not need to reject pushes. Webhooks are generally easier to configure, debug, and customize, and have better error handling and retry behavior.

The major reason to use a custom pre-receive hook is to reject pushes that match criteria Herald can not test for.

The major reason to use any other server-side custom hook is to take some repository action which would be prohibitively complex or expensive to perform via a webhook (e.g., examining large amounts of repository history or doing substantial parsing of the change itself).

Got it thanks @epriestley @avivey