Skip to content

Commit 314b918

Browse files
Om-A-osckgryte
andauthored
build: use exact ref lookup in tools/git/hooks/pre-push
PR-URL: #11373 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 4fe7fa2 commit 314b918

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tools/git/hooks/pre-push

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,16 @@ amend_commit() {
168168

169169
# Checks if commits exist to push, as `git push` will execute regardless of whether commits exist to push or not.
170170
has_commits() {
171+
local remote_ref="${remote}/${GIT_CURRENT_BRANCH}"
171172
local commits
172173

173174
echo 'Checking if remote branch exists...' >&2
174-
if git branch -r | grep "${GIT_CURRENT_BRANCH}" > /dev/null; then
175+
176+
# We use rev-parse to test the actual ref. Directing to /dev/null makes it silent on failure; the exit code is what matters...
177+
if git rev-parse --verify "refs/remotes/${remote_ref}" > /dev/null 2>&1; then
175178
echo 'Remote branch exists.' >&2
176179
echo 'Checking for commits to push...' >&2
177-
commits=$(git log "${remote}/${GIT_CURRENT_BRANCH}..${GIT_CURRENT_BRANCH}" --oneline --)
180+
commits=$(git log "${remote_ref}..${GIT_CURRENT_BRANCH}" --oneline --)
178181
else
179182
echo 'Remote branch does not exist.' >&2
180183
echo 'Checking for commits to push...' >&2

0 commit comments

Comments
 (0)