Description
pre-push hook determines whether a remote branch exists using:
git branch -r | grep "${GIT_CURRENT_BRANCH}"
This uses substring matching, which can lead to false positives when branch names share prefixes or substrings.
Observed Behavior
In certain cases, the hook reports that a remote branch exists even when the exact branch does not exist.
Prefix collision
Remote branch:
refactor/stats-base-dists-chi
Local branch:
refactor/stats-base-dists
Running:
git branch -r | grep "refactor/stats-base-dists"
matches refactor/stats-base-dists-chi, causing the hook to incorrectly assume that the remote branch exists.
This leads to:
git log origin/refactor/stats-base-dists..refactor/stats-base-dists
which fails with:
fatal: bad revision 'origin/refactor/stats-base-dists..refactor/stats-base-dists'
Related Issues
NA
Questions
Is this behavior intentional, or would it be preferable to switch to an exact ref check (e.g., using git rev-parse --verify refs/remotes/<remote>/<branch>) to avoid false positives?
Demo
No response
Reproduction
1. Create and push a branch to the remote:
git checkout -b refactor/stats-base-dists-chi
git push origin refactor/stats-base-dists-chi
2. Create a new local branch whose name is a prefix of the existing remote branch:
git checkout -b refactor/stats-base-dists
3. Make a commit:
git commit --allow-empty -m "test commit"
4. Attempt to push:
git push origin refactor/stats-base-dists
5. Observe that the pre-push hook reports that the remote branch exists and fails with:
fatal: bad revision 'origin/refactor/stats-base-dists..refactor/stats-base-dists'
This occurs even though `origin/refactor/stats-base-dists` does not actually exist.
Expected Results
Should push without error
Actual Results
fatal: bad revision 'origin/refactor/stats-base-dists..refactor/stats-base-dists'
Version
No response
Environments
N/A
Browser Version
No response
Node.js / npm Version
No response
Platform
No response
Checklist
Description
pre-push hook determines whether a remote branch exists using:
This uses substring matching, which can lead to false positives when branch names share prefixes or substrings.
Observed Behavior
In certain cases, the hook reports that a remote branch exists even when the exact branch does not exist.
Prefix collision
Remote branch:
Local branch:
Running:
matches
refactor/stats-base-dists-chi, causing the hook to incorrectly assume that the remote branch exists.This leads to:
which fails with:
Related Issues
NA
Questions
Is this behavior intentional, or would it be preferable to switch to an exact ref check (e.g., using
git rev-parse --verify refs/remotes/<remote>/<branch>) to avoid false positives?Demo
No response
Reproduction
Expected Results
Actual Results
fatal: bad revision 'origin/refactor/stats-base-dists..refactor/stats-base-dists'Version
No response
Environments
N/A
Browser Version
No response
Node.js / npm Version
No response
Platform
No response
Checklist