diff --git a/access/scripts/break-glass b/access/scripts/break-glass index dd44f6c..3ea3c4e 100755 --- a/access/scripts/break-glass +++ b/access/scripts/break-glass @@ -300,7 +300,19 @@ EOT if [ "$do_open" = true ] && [ "$gh_ready" = true ]; then ( cd "$repo_root" || exit 1 - git switch -c "$branch" >/dev/null 2>&1 || git switch "$branch" >/dev/null 2>&1 + # Drop any branch of this name left over from an earlier sweep, + # then branch from where we are. Reusing a stale one makes a + # pull request whose diff is the inverse of its title, because + # the base has moved on and the old branch reads as adding back + # the very grant this is retiring. It succeeds and it lies. + # + # Deleted rather than checked out from origin/main on purpose. + # A switch with a start point rewrites every file in the tree, + # including this script while bash is still reading it, and the + # edit below then runs against a file nobody chose. + git branch -q -D "$branch" >/dev/null 2>&1 || true + git switch -q -c "$branch" >/dev/null 2>&1 || + git switch -q "$branch" >/dev/null 2>&1 local id for id in $expired_ids; do if blocks | awk -F'\t' -v id="$id" -v f="$f" '$1 == id && $2 == f { found = 1 } END { exit !found }'; then @@ -311,7 +323,15 @@ EOT git commit -q -m "break-glass: sweep expired grants from $principal" \ -m "The cloud already ended these at their expiry. This removes the artifact." \ -m "" - git push -q -u origin "$branch" + # Forced, guarded by the prefix, for the same reason reconcile + # forces its own: the branch is this file's one current + # proposal rather than a history. + if ! push_err="$(git push -u --force origin "$branch" 2>&1)"; then + say " FAIL could not push $branch" + printf ' %s\n' "$push_err" | head -3 + git switch - >/dev/null 2>&1 + exit 1 + fi gh pr create --title "break-glass: sweep expired grants from $principal" \ --body "The cloud already ended these grants at their expiry (layer 1). This PR removes the artifacts (layer 2), and the drift watch stops reporting them once it merges (layer 3).