Commands
chamoji hook
Install or remove chamoji’s prepare-commit-msg hook. With it, git commit
with no message opens the commit composer. While a workstream is active, the
hook adds its Workstream: line to commits made with -m, -F or the
composer. The hook never blocks a commit.
The hook lives in .git/hooks, which git doesn’t clone, so install it once in
each clone. Its worktrees share it.
What it does, in order
- Finds the hooks folder. The one git runs hooks from:
.git/hooks, or the foldercore.hooksPathnames. - Hands over to your hook manager. When
core.hooksPathis set, as husky sets it, it writes nothing and prints the line to add to that folder’sprepare-commit-msgyourself. - Looks at the hook that’s there. chamoji’s own is updated, and gitmoji-cli’s is replaced. lefthook’s, or any other, is left alone: it prints what to add instead and exits 2.
- Writes the hook. A short script that runs
chamoji hook run, or the same through npx when chamoji isn’t on the PATH, and always exits 0.
On each commit, the hook opens the composer only for a plain git commit on a terminal, and leaves everything else alone: -m and -F, merges, squashes, amends, rebases, a message that already has a gitmoji, CI, and commits with no terminal, such as an editor’s commit button. Ctrl-C in the composer keeps git’s own message. While a workstream is active, it adds the Workstream: line to -m, -F and composer commits. Editor commits, merges, squashes, amends without -m, rebases, cherry-picks, reverts and commit.template messages aren’t stamped. Writing commits has the details.
The hook
.git/hooks/prepare-commit-msg
#!/bin/sh
# chamoji: offers the commit composer on a plain `git commit`.
# Remove it with `chamoji hook uninstall`.
if command -v chamoji >/dev/null 2>&1; then
chamoji hook run "$@"
else
npx --yes @chamoji/cli hook run "$@"
fi
exit 0
The # chamoji line marks it as chamoji’s, so uninstall never removes another tool’s hook.
Subcommands
- Name
chamoji hook install- Description
Install the hook in this clone, or update chamoji’s own. It replaces gitmoji-cli’s hook, and leaves any other alone. With
core.hooksPathset, it changes nothing and prints the line to add.
- Name
chamoji hook uninstall- Description
Delete
prepare-commit-msgwhen it’s chamoji’s. Any other hook, and a line you added to a hook manager’s file, stay. With no chamoji hook, it changes nothing and says so.
- Name
chamoji hook run <file> [source]- Description
What the installed hook runs, with the arguments git gives
prepare-commit-msg: the message file and where the message came from. You don’t run it yourself. It always exits 0, and when anything goes wrong it leaves the message as it was.
Arguments
- Name
action- Type
- install | uninstall | run · required
- Description
What to do. None, or any other word, exits 2.
Flags
chamoji hook takes no flags. It never checks npm for a newer chamoji, so --no-update-check changes nothing.
Common combinations
chamoji hook install
Open the composer on a plain git commit in this clone.
chamoji hook uninstall
Go back to git’s own editor.
chamoji setup hook --yes
The same install, as a step of chamoji setup.
Output
These are from real runs in throwaway repos under /tmp:
chamoji hook install
Installed the hook: /private/tmp/widgets/.git/hooks/prepare-commit-msg
A plain `git commit` now opens the composer; -m, merges, amends and rebases are left alone.
Other hooks
$ chamoji hook install
Updated the hook: /private/tmp/widgets/.git/hooks/prepare-commit-msg
A plain `git commit` now opens the composer; -m, merges, amends and rebases are left alone.
Uninstall
$ chamoji hook uninstall
Removed the chamoji hook.
Exit codes
- Name
0- Description
installinstalled or updated the hook, or printed the line forcore.hooksPath.uninstallremoved it, or found none.
- Name
2- Description
installfound lefthook’s hook or another tool’s, and left it alone. Also no action, or an unknown one.
- Name
1- Description
- Outside a git repo, or anything else that fails.
hook run always exits 0, so the hook never blocks a commit. Exit codes has every command’s codes.