File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff 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.
170170has_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
You can’t perform that action at this time.
0 commit comments