Release script: if master branch does not exist, fall back on origin/master

On ci.bazel.io local branch names are not set, so the release script
was not finding information about the master branch. If the master ref
does not exist, this change fall backs to looking at origin/master instead.

Fixes #2263.
To be cherry-picked for #2246.

--
Change-Id: Ibe4f3533e529d79917233d89951f88cb58d14ce3
Reviewed-on: https://cr.bazel.build/8033
PiperOrigin-RevId: 142524954
MOS_MIGRATED_REVID=142524954
diff --git a/scripts/release/common.sh b/scripts/release/common.sh
index de3ccd0..33b2c38 100755
--- a/scripts/release/common.sh
+++ b/scripts/release/common.sh
@@ -128,10 +128,16 @@
   done
 }
 
+# Get the master commit
+# Some machine might not have a "master" branch, use "origin/master" in that case
+function get_master_ref() {
+  git rev-parse --verify master 2>/dev/null || git rev-parse --verify origin/master
+}
+
 # Get the baseline of master.
 # Args: $1: release branch, default to HEAD
 function get_release_baseline() {
-  git merge-base master "${1:-HEAD}"
+  git merge-base $(get_master_ref) "${1:-HEAD}"
 }
 
 # Get the list of cherry-picks since master
@@ -140,11 +146,12 @@
 #   $2: baseline change, default to $(get_release_baseline $1)
 function get_cherrypicks() {
   local branch="${1:-HEAD}"
+  local master=$(get_master_ref)
   local baseline="${2:-$(get_release_baseline "${branch}")}"
   # List of changes since the baseline on the release branch
   local changes="$(git_log_hash "${baseline}" "${branch}" --reverse)"
   # List of changes since the baseline on the master branch, and their patch-id
-  local master_changes="$(git_log_hash "${baseline}" master | xargs git show | git patch-id)"
+  local master_changes="$(git_log_hash "${baseline}" "${master}" | xargs git show | git patch-id)"
   # Now for each changes on the release branch
   for i in ${changes}; do
     # Find the change with the same patch-id on the master branch