diff --git a/merge/entrypoint.sh b/merge/entrypoint.sh index 08e0dcd..f884070 100755 --- a/merge/entrypoint.sh +++ b/merge/entrypoint.sh @@ -60,11 +60,24 @@ git remote prune origin failures=() function open_and_merge_pull_request() { + local source_branch="${GITHUB_REF#refs/heads/}" + echo "DEBUG: making pull request from ${GITHUB_REF} to $1" - # if $1 branch does not exist origin + # if destination branch does not exist on origin if [[ -z "$(git ls-remote origin "$1")" ]]; then echo "Could not find expected branch '$1' on remote 'origin'" + return 1 + fi + + # Skip no-op merges so identical branches do not fail PR creation with + # "No commits between ..." validation errors. + local ahead_commit + ahead_commit="$(git rev-list --max-count=1 "origin/$1..origin/${source_branch}")" + + if [[ -z "${ahead_commit}" ]]; then + echo "DEBUG: skipping merge of ${GITHUB_REF} into $1; ${source_branch} has no commits ahead of $1" + return 0 fi # subshell with +e so we continue on errors