Repository navigation
commitizen-branch fails with exit code: 23 and message fatal: ..: '..' is outside repository #1923
Description
Activity
- addedos: macOShas issue on macOShas issue on macOS
on Apr 4, 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:
- repo: local hooks: - id: commitizen-branch name: commitizen check branch entry: bash -c 'uv run --quiet cz check --rev-range "$PRE_COMMIT_FROM_REF..$PRE_COMMIT_TO_REF"' -- language: system stages: [ pre-push ] pass_filenames: false always_run: true
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:
- Default
commitizen-branchhook arguments changed to use pre-commit variables
PR: #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 changed
PR: #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.
- Exit code changed from 3 to 23
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.- Expansion of environment variables in
--rev-range
PR: #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:
- Expansion of both variables was added here.
- Expansion of a single variable can be observed after this change when only one environment variable is available, for example:
$PRE_COMMIT_FROM_REF..00c7da778d77ffdd2e380415e3fd47bab286bc88
Of 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.
#!/usr/bin/env bash set -u set -o pipefail REV="${1:?Usage: $0 <commitizen-rev>}" ROOT=$(mktemp -d) REPO="$ROOT/repro" REMOTE="$ROOT/remote.git" echo "Testing Commitizen rev: $REV" echo "Temp dir: $ROOT" mkdir "$REPO" cd "$REPO" uv init >/dev/null uv add --dev prek >/dev/null cat > .pre-commit-config.yaml <<EOF default_install_hook_types: - pre-push - commit-msg repos: - repo: https://github.com/commitizen-tools/commitizen rev: $REV hooks: - id: commitizen stages: [commit-msg] - id: commitizen-branch stages: [pre-push] EOF git init -q uv run prek install --hook-type pre-push --hook-type commit-msg git config user.name "Test" git config user.email "test@example.com" git add . git commit -m "feat: initial commit" git branch -M main git init --bare -q "$REMOTE" git remote add origin "$REMOTE" git checkout -b test-commitizen-branch git commit --allow-empty -m "feat: reproduce issue" git push -u origin test-commitizen-branch
Hope this helps!
- Default
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
uvto bootstrap the projectClean-up
Current behavior
The pre-push command results in:
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