mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-07 13:21:02 +01:00
925a0d3d59
Summary: Ref T4245. We pass this exclusively for use by additional third-party hooks. This is technically a backward compatibility break, but I suspect it doesn't affect anyone: - Probably almost no one is using this (there are few reasons to, even for the tiny number of installs with custom commit hooks). - If they are, there's a good chance the PHID will work anyway, since nearly all scripts and Conduit methods will accept it in place of a callsign now, and if it's in logging or debugging code the PHID is a reasonable substitute - Even if it doesn't just keep working, the break should be very obvious in most reasonable cases. I'll call this out explicitly in the changelog, though -- almost everything else will just continue working, but this is a strict compatibility break. Test Plan: - Ugh. - Picked a hosted Git repo out of Diffusion. - Went to the path on disk. - Went into `hooks/`. - Went into `pre-receive-phabricator.d/`. - Wrote this hook and gave it `chmod +x`: ```name=stuff.sh #!/bin/sh echo $PHABRICATOR_REPOSITORY >> /tmp/stuff.log ``` - Pushed to the repository. - Saw a PHID show up in the log: ``` $ cat /tmp/stuff.log PHID-REPO-bqkcdp47euwnwlasrsrh ``` Reviewers: chad, avivey Reviewed By: avivey Subscribers: avivey Maniphest Tasks: T4245 Differential Revision: https://secure.phabricator.com/D15294
52 lines
2.2 KiB
Text
52 lines
2.2 KiB
Text
@title Diffusion User Guide: Commit Hooks
|
|
@group userguide
|
|
|
|
Guide to commit hooks in hosted repositories.
|
|
|
|
= Overview =
|
|
|
|
Phabricator installs pre-receive/pre-commit hooks in hosted repositories
|
|
automatically. They enforce a few rules automatically (like preventing
|
|
dangerous changes unless a repository is configured to allow them). They can
|
|
also enforce more complex rules via Herald, using the "Commit Hook:
|
|
Branches/Tags/Bookmarks" and "Commit Hook: Commit Content" rule types.
|
|
|
|
Herald rules are flexible, and can express many of the most common hooks that
|
|
are often installed on repositories (like protecting branches, restricting
|
|
access to repositories, and requiring review).
|
|
|
|
However, if Herald isn't powerful enough to enforce everything you want to
|
|
check, you can install additional custom hooks. These work mostly like normal
|
|
hooks, but with a few differences.
|
|
|
|
= Installing Custom Hooks =
|
|
|
|
With hosted repositories, you can install hooks by dropping them into the
|
|
relevant directory of the repository on disk:
|
|
|
|
- **SVN** Put hooks in `hooks/pre-commit-phabricator.d/`.
|
|
- **Git** Put hooks in `hooks/pre-receive-phabricator.d/`.
|
|
- **Mercurial** Phabricator does not currently support custom hooks in
|
|
Mercurial.
|
|
|
|
These hooks act like normal `pre-commit` or `pre-receive` hooks:
|
|
|
|
- Executables in these directories will be run one at a time, in alphabetical
|
|
order.
|
|
- They'll be passed the arguments and environment that normal hooks are
|
|
passed.
|
|
- They should emit output and return codes like normal hooks do.
|
|
- These hooks will run only after all the Herald rules have passed and
|
|
Phabricator is otherwise ready to accept the commit or push.
|
|
|
|
These additional variables will be available in the environment, in addition
|
|
to the variables the VCS normally provides:
|
|
|
|
- `PHABRICATOR_REPOSITORY` The PHID of the repository the hook is
|
|
executing for.
|
|
- `PHABRICATOR_USER` The Phabricator username that the session is
|
|
authenticated under.
|
|
- `PHABRICATOR_REMOTE_ADDRESS` The connection's remote address (that is,
|
|
the IP address of whoever is pushing or committing).
|
|
- `PHABRICATOR_REMOTE_PROTOCOL` The protocol the connection is using (for
|
|
example, "ssh" or "http").
|