android_merge_from_upstream: fix up naming

This replaces `master` with `main` where possible, per the linked bug.

It also switches to a more concise way of making sure we're never on the
local branch.

BUG=chromium:1099035
TEST=Ran the script in android-llvm

Change-Id: I0e656057acec857a2c91480cbd822a5bc6778563
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2265045
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
diff --git a/android_merge_from_upstream.sh b/android_merge_from_upstream.sh
index cf07d4b..b63eb6e 100755
--- a/android_merge_from_upstream.sh
+++ b/android_merge_from_upstream.sh
@@ -18,11 +18,11 @@
 my_dir="$(dirname "$(readlink -m "$0")")"
 cd "${my_dir}"
 
-ensure_head_is_upstream_master() {
-  local current_rev master_rev
+ensure_head_is_upstream_main() {
+  local current_rev main_rev
   current_rev="$(git rev-parse HEAD)"
-  master_rev="$(git rev-parse ${local_upstream})"
-  if [[ "${current_rev}" != "${master_rev}" ]]; then
+  main_rev="$(git rev-parse ${local_upstream})"
+  if [[ "${current_rev}" != "${main_rev}" ]]; then
     echo "Please checkout ${local_upstream} and rerun this" >&2
     exit
   fi
@@ -42,16 +42,8 @@
     exit 1
   fi
 
-  # If we're *on* that branch, deleting it is difficult.
-  local current_branch
-  current_branch="$(git branch --show-current)"
-  if [[ "${current_branch}" == "${local_branch_name}" ]]; then
-    local rev
-    rev="$(git rev-parse HEAD)"
-    # This is fine, since we assume HEAD == upstream-mirror-master anyway
-    # (e.g., the existing branch was pointless.)
-    git checkout "${rev}"
-  fi
+  # If we're *on* that branch, deleting it is difficult. Always detach.
+  git checkout --detach || return
   git branch -D "${local_branch_name}"
 }
 
@@ -61,7 +53,7 @@
   git log --oneline "${merge_base}..${remote_branch}"
 }
 
-ensure_head_is_upstream_master
+ensure_head_is_upstream_main
 ensure_no_local_branch_present
 
 echo "Ensuring repository is up-to-date..."