setup
The rs setup command installs repository-level Git hooks and runs them in the project that invokes the command.
Usage
By default, hook scripts are stored in .rstack/hooks, relative to the Git repository root. If the current directory is not inside a Git repository, the command skips installation.
Add rs setup to the prepare script of the project that should manage the repository hooks:
Run the script once to generate the hook files:
For example, create a pre-commit hook that runs rs staged:
rs setup updates the repository's core.hooksPath. It skips installation when another hooks path or existing Git hook is detected. Migrate the required hooks and remove the existing hooks configuration before running the command.
Options
--hooks-dir
Sets the directory for hook scripts, relative to the Git repository root.
When using a custom directory, add the full command to the prepare script of the project that manages hooks:
To prevent Git hook files from being created or overwritten outside the repository through parent directory paths, the path must not contain
...
--help
--help (or -h) displays the command's usage and options.
Hook files
The default directory structure is:
Files next to _ are repository hook scripts. The _ directory contains generated files and is ignored by Git. rs setup points core.hooksPath to .rstack/hooks/_; rerun it after cloning the repository or when generated files are missing.
Supported hooks
Rstack supports these client-side Git hooks:
pre-commitpre-merge-commitprepare-commit-msgcommit-msgpost-commitapplypatch-msgpre-applypatchpost-applypatchpre-rebasepost-rewritepost-checkoutpost-mergepre-pushpre-auto-gc
Create a file with the matching name next to the _ directory.
Hook runtime
Rstack runs hook scripts with POSIX sh -e, forwards Git's arguments and standard input, and returns the hook's exit code. Before running a hook, it changes to the project that installed the hooks and prepends that project's node_modules/.bin to PATH.
Disable and debug
Set RSTACK_HOOKS=0 to skip installation or hook execution:
Set RSTACK_HOOKS=2 to trace Rstack's hook runtime, including how it invokes the hook script and handles its exit code; to trace commands inside the hook script, add set -x to the script:
Configure the hook environment
Before running a hook script, Rstack loads this optional POSIX shell file:
Use it to initialize a Node.js version manager, update PATH, or set RSTACK_HOOKS=0 for the current user.
Monorepo
In a monorepo, the project that provides Rstack may be located in a subdirectory such as frontend/. Running rs setup from that directory still installs hooks at the Git repository root:
Rstack records frontend as the project that owns the hooks. Hook scripts remain at the repository root, but run from frontend, so they can use its configuration and dependencies without an explicit cd:
A Git repository has one hooks owner. Only that project should include rs setup in its prepare script. Calls from another project are skipped with a warning.
To change the owner, remove rs setup from the previous project's prepare script, delete the generated _ directory, and then run rs setup from the new project.
Remove hooks
To remove Rstack-managed hooks:
-
Remove
rs setupfrom thepreparescript. -
Unset the repository's hooks path:
-
Delete
.rstack/hooks/, or the directory passed to--hooks-dir.
Troubleshooting
Hook does not run
- Check that the hook script has a supported name and is next to the
_directory. - Run
git config --local --get core.hooksPathand verify the configured path. - Rerun
rs setupto restore generated files and executable permissions. - Check that
RSTACK_HOOKSis not set to0in the environment or initialization file. - If another hooks setup is reported, migrate or remove the conflicting setup before rerunning the command.
- If another Rstack owner is reported, follow the ownership transfer steps in Monorepo.
Hook scripts do not need to be executable because Rstack runs them with sh.
Command not found
For exit code 127, Rstack prints the effective PATH. If a GUI Git client cannot find Node.js or the package manager, initialize them in hooks-init.sh.
Windows and Yarn
On Windows, hooks run in the POSIX shell included with Git for Windows. Use LF line endings and / path separators in hooks.
Yarn PnP does not provide node_modules/.bin. Run tools through a Yarn script, such as yarn run test, and make Node.js and Yarn available through hooks-init.sh when needed.