Skip to main content
Mercurial Autohooks Extension
=============================

This project is an extension for Mercurial that enables Mercurial hooks to
be included inside a source repository such that they are automatically
detected and utilised merely by being present.

It is important to realise that using this extension means that you
are giving permission to run code as your user to anyone who can commit to
the repositories you are using. For this reason, the extension will only
be activated for respositories with a default upstream that you have
configured as 'trusted'.

Installation
------------

pip install hg-autohooks

Add the following to your Mercurial configuration:

[extensions]
hgautohooks=

[autohooks]
trusted="ssh://hg@hg/"

The `trusted` configuration is a list of repository upstream address
prefixes are trusted. The extension will only be active for repositories
whose default upstream starts with one of the strings in this list.

Automatic hooks
---------------

To use the automatic hooks, create a top-level directory inside your
repository named either `hg-autohooks` or `.hg-autohooks` and then
add hook files inside it. The file names should be prefixed with the
hook name and have a suffix of `.sh` or `.py` for shell or Python
extensions respectively. Pre- and post- hooks should be named
'pre_hookname.ext' or 'post_hookname.ext' respectively.

Example
-------

To require that your Python module can be successfully imported
before allowing it to be committed, create a file named
`hg-autohooks/pre_commit.import.py` containing:

```python
"""Mercurial pre-commit hook to try importing the project."""
# pylint: disable=invalid-name,unused-argument

import subprocess

def pre_commit(ui, repo, **kwargs):
"""Try importing the project and see if anything bad happens."""
imp = subprocess.Popen(("bin/python", "-c", "import foo"),
cwd=repo.root, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = imp.communicate()
if imp.returncode or stdout or stderr:
if stdout:
ui.write(stdout)
if stderr:
ui.write(stderr)
return True
return False
```

Metadata

Release files for hg-autohooks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hg-autohooks 0.1.0
File Size Uploaded Provenance Actions
hg-autohooks-0.1.0.tar.gz 9.9 kB Without provenance Details for hg-autohooks-0.1.0.tar.gz

Release files / hg-autohooks-0.1.0.tar.gz

Download URL hg-autohooks-0.1.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1a7fc5e21ac10d0d1981b71c81535aedafe8d0085ae6bc5c356cc8812ef810c9
BLAKE2b-256 checksum
How to use checksums
f63a946de4d7abe61c513be012fa07efddcc73f02cbfd227d11961e5370956ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for hg-autohooks 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page