Max Gekk created SPARK-57488:
--------------------------------

             Summary: checkout-pr.sh review helper aborts with bash "unbound 
variable" on the no-force checkout path under bash 3.2
                 Key: SPARK-57488
                 URL: https://issues.apache.org/jira/browse/SPARK-57488
             Project: Spark
          Issue Type: Bug
          Components: Project Infra
    Affects Versions: 5.0.0
            Reporter: Max Gekk


h3. Summary

The {{checkout-pr.sh}} helper used by the spark-dev PR-review tooling aborts 
with {{force_args[@]: unbound variable}} whenever it takes the no-force 
checkout path. That path is *always* taken for self-PRs (and for any external 
PR before a force is needed), so self-PR review is consistently broken on 
macOS. The caller misreports the crash as a {{branch-diverged}} stop (exit 11), 
so a clean branch that is already at the PR head looks as if it has diverged.

h3. Environment

* macOS, where {{/usr/bin/env bash}} resolves to {{/bin/bash}} = GNU bash 
*3.2.57* (Apple's stock version).
* Triggered via the PR setup/checkout step of the review tooling.

h3. Steps to reproduce

# On macOS (bash 3.2), check out your own open PR locally so the branch is 
already at the PR head.
# Run the review checkout step against that PR.

h3. Expected

Checkout is a no-op (branch already at head); setup exits 0 and proceeds.

h3. Actual

{noformat}
checkout-pr.sh: line 63: force_args[@]: unbound variable
branch-diverged: local branch <name> could not be fast-forwarded to the PR head 
...
{noformat}

Setup exits 11 (branch-diverged), halting the review even though the working 
tree is clean and HEAD exactly matches the PR head_sha.

h3. Root cause

The helper builds an optional force flag in an array:

{code:bash}
local force_args=()
[[ "$1" == "1" ]] && force_args=(-f)
gh pr checkout ... "${force_args[@]}"
{code}

Under {{set -euo pipefail}}, *bash 3.2 treats expansion of an empty array* 
({{"${force_args[@]}"}}) *as an unbound variable* and aborts -- a bug fixed in 
bash 4.4+. On the no-force path the array is empty, so the command never runs.

h3. Fix

Use the {{set -u}}-safe expansion idiom, which yields nothing when the array is 
empty and the quoted elements otherwise:

{code:bash}
gh pr checkout "${PR_NUMBER}" -R "${OWNER}/${REPO}" 
${force_args[@]+"${force_args[@]}"} 2>&1
{code}

h3. Test gap

The script's self-test stubs out the checkout function entirely, so it never 
exercises the real argv assembly -- which is why this shipped green. A 
regression test should stub the {{gh}} binary instead of the function so the 
empty-array expansion runs under {{set -u}}.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to