From 30c7dbc2f3df75de5d75d6cc5b10efdfadd1333d Mon Sep 17 00:00:00 2001 From: davotoula Date: Tue, 28 Jul 2026 20:39:59 +0200 Subject: [PATCH] =?UTF-8?q?Code=20review:=201.=20`title=3D"$(git=20log=20-?= =?UTF-8?q?1=20=E2=80=A6=20|=20cut=20=E2=80=A6)"`=20aborts=20the=20whole?= =?UTF-8?q?=20script=20under=20=20=20=20`set=20-euo=20pipefail`=20when=20t?= =?UTF-8?q?he=20worktree=20has=20no=20commits=202.=20`base=5Fbranch`=20onl?= =?UTF-8?q?y=20fell=20back=20to=20`main`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/src/main/resources/buzz-agent/workflow-ship.sh | 9 +++++++-- tools/buzz-agent/workflow-ship.sh | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cli/src/main/resources/buzz-agent/workflow-ship.sh b/cli/src/main/resources/buzz-agent/workflow-ship.sh index 68e68d32bc..954586dac7 100755 --- a/cli/src/main/resources/buzz-agent/workflow-ship.sh +++ b/cli/src/main/resources/buzz-agent/workflow-ship.sh @@ -25,14 +25,19 @@ die() { printf 'error: %s\n' "$*" >&2; exit 1; } cd "$BUZZ_WORKTREE" || die "cannot cd into worktree $BUZZ_WORKTREE" # The PR base = the repo's default branch. Never operate on it directly. -base_branch="$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || echo main)" +# `gh` can also succeed while printing nothing (or a literal "null") for a repo it can't +# resolve, so fall back on the value, not just on the exit status. +base_branch="$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || true)" +[[ -n "$base_branch" && "$base_branch" != "null" ]] || base_branch="main" case "$BUZZ_BRANCH" in "$base_branch" | main | master) die "refusing to operate on the default branch ($BUZZ_BRANCH)" ;; # Anything else is a per-run branch — the only thing this script is allowed to push. *) : ;; esac -title="$(git log -1 --format='%s' 2>/dev/null | cut -c1-72)" +# `|| true` keeps `set -e` from killing the script when the worktree has no commits yet — +# without it the fallback below is unreachable and the run fails with an empty stderr. +title="$(git log -1 --format='%s' 2>/dev/null | cut -c1-72)" || true [[ -n "$title" ]] || title="Buzz run ${BUZZ_RUN:-}" log "[workflow-ship] pushing $BUZZ_BRANCH" diff --git a/tools/buzz-agent/workflow-ship.sh b/tools/buzz-agent/workflow-ship.sh index 68e68d32bc..954586dac7 100755 --- a/tools/buzz-agent/workflow-ship.sh +++ b/tools/buzz-agent/workflow-ship.sh @@ -25,14 +25,19 @@ die() { printf 'error: %s\n' "$*" >&2; exit 1; } cd "$BUZZ_WORKTREE" || die "cannot cd into worktree $BUZZ_WORKTREE" # The PR base = the repo's default branch. Never operate on it directly. -base_branch="$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || echo main)" +# `gh` can also succeed while printing nothing (or a literal "null") for a repo it can't +# resolve, so fall back on the value, not just on the exit status. +base_branch="$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null || true)" +[[ -n "$base_branch" && "$base_branch" != "null" ]] || base_branch="main" case "$BUZZ_BRANCH" in "$base_branch" | main | master) die "refusing to operate on the default branch ($BUZZ_BRANCH)" ;; # Anything else is a per-run branch — the only thing this script is allowed to push. *) : ;; esac -title="$(git log -1 --format='%s' 2>/dev/null | cut -c1-72)" +# `|| true` keeps `set -e` from killing the script when the worktree has no commits yet — +# without it the fallback below is unreachable and the run fails with an empty stderr. +title="$(git log -1 --format='%s' 2>/dev/null | cut -c1-72)" || true [[ -n "$title" ]] || title="Buzz run ${BUZZ_RUN:-}" log "[workflow-ship] pushing $BUZZ_BRANCH"