commitizen-branch fails with exit code: 23 and message fatal: ..: '..' is outside repository #1923
Copy link
Copy link
Open
Labels
Description
Description
I cannot get the commitizen-branch hook to work, please see a self-contained demo in the reproduction steps below.
Steps to reproduce
I used uv to bootstrap the project
uv init commitizen-hook-test
cd commitizen-hook-test
uv add pre-commit --dev
uv add commitizen --dev
source .venv/bin/activate
# files below originally generated with cz init
cat << 'EOF' > .pre-commit-config.yaml
repos:
- hooks:
- id: commitizen
- id: commitizen-branch
stages:
- pre-push
repo: https://github.com/commitizen-tools/commitizen
rev: v4.13.9
EOF
cat << 'EOF' > .cz.toml
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "semver2"
version_provider = "scm"
major_version_zero = true
EOF
pre-commit install --hook-type commit-msg --hook-type pre-push
git add *
git commit -am'feat: just a confirming commit'
pre-commit run --hook-stage pre-push
Clean-up
deactivate
cd ..
rm -rf commitizen-hook-test
Current behavior
The pre-push command results in:
commitizen check branch..................................................Failed
- hook id: commitizen-branch
- exit code: 23
fatal: ..: '..' is outside repository at '/Users/<redacted>/commitizen-hook-test'
Desired behavior
I would like the hook to pass.
Screenshots
No response
Environment
Commitizen Version: 4.13.9
Python Version: 3.12.3 (main, Dec 31 2024, 17:41:17) [Clang 15.0.0 (clang-1500.3.9.4)]
Operating System: Darwin
Reactions are currently unavailable
Activity
natelandau commentedon May 8, 2026
I ran in to the same problem, I think this hook depends on an args-substitution behavior that doesn't work in all pre-commit runners (I use Prek).
As a workaround, I wrote my own local hook to get the expected behavior:
mcsitter commentedon Jul 28, 2026
Some of my findings.
Running against
master,commitizen-branchfails with bothprekandpre-commit, but differently.With
prek,PRE_COMMIT_TO_REFis expanded whilePRE_COMMIT_FROM_REFremains literal ($PRE_COMMIT_FROM_REF..<sha>).With
pre-commit, both variables remain literal ($PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF).Here is more info regarding the changes to the variables.
The relevant changes were introduced in these pull requests:
commitizen-branchhook arguments changed to use pre-commit variablesPR: #1815
Changed:
args: [--rev-range, origin/HEAD..HEAD]to:
args: [--rev-range, "$PRE_COMMIT_TO_REF $PRE_COMMIT_FROM_REF"]This introduced the use of
PRE_COMMIT_FROM_REF/PRE_COMMIT_TO_REFin the packaged hook configuration.commitizen-branchrev-range syntax changedPR: #1841
Changed:
args: [--rev-range, "$PRE_COMMIT_TO_REF $PRE_COMMIT_FROM_REF"]to:
args: [--rev-range, "$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF"]This changed the hook argument from two space-separated refs to the Git range syntax.
PR: #1941
This changed Git command execution from shell-based execution to
shell=False.After this change, the literal argument:
$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REFwas passed directly to Git instead of being expanded by the shell.
The failure changed from:
- exit code: 3to:
- exit code: 23with:
fatal: ambiguous argument '$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF': unknown revision or path not in the working tree.--rev-rangePR: #2005
Added explicit environment variable expansion in
cz check --rev-range.This restored handling of:
$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REFwithout using shell expansion.
Additional detail:
$PRE_COMMIT_FROM_REF..00c7da778d77ffdd2e380415e3fd47bab286bc88Of course these PRs are linked, but i tested commits with this script which accepts a ref for commitizen to test the hook behaviour for a given tag or commit.
Hope this helps!