sapling
sapling copied to clipboard
Is "hook" support yet?
RT
Hooks are documented in sl help config under the hooks section. Note that the documentation is still written for Mercurial, so there are some differences (e.g. Sapling does not have Mercurial's incoming command). But in principle they should work, based on my preliminary testing with precommit and commit hooks.
There is also this chapter in the old Mercurial book that has an introduction to hooks.
I'm not sure if there are plans for changing the names of the environment variables that are being passed to hooks, such as HG_PARENT1. So far, they seem to work the same way as for Mercurial.
While hooks still work today, we might break their compatibility in the future. In particular, various commit hooks imply that the hook script has access to the current working copy, and sometimes we want to skip writing to the working copy for performance reasons. For example, absorb today is much faster than histedit because absorb does not write to the working copy while histedit does. As a side effect, commits created by absorb already skip pre-commit hooks. Besides, as we migrate logic to Rust, Python hooks might become incompatible over time and only shell hooks remain. But those are general directions. The exact compatibility change is uncertain at this time.
Let us know your use-case so we can consider them when making trade-off decisions.
Let us know your use-case so we can consider them when making trade-off decisions.
Concrete use cases that I have are running clang-format (or other code formatters) and mypy (or other linters) before/after a commit or before a push.
I can see this being useful to integrate with pre-commit as that would then allow running all kind of other linters and formatters as pre-flight checks.
But I'm not sure how easy it would be since I believe pre-commit depends heavily on git semantics which are unlikely to translate directly.
Another use case is automatically running (p)npm install after checking out or pulling (previously we had git hooks [using husky] for post-checkout and post-merge which would check if pnpm-lock.yaml was modified, and automatically install if so).
We also had a pre-push hook for git lfs although that would likely take a lot more work to port over