ci(patch): only fall back when the frappe branch is genuinely absent

The previous `||` treated every fetch failure as a missing branch, so a
transient network or auth error on a base that does exist in frappe would
silently substitute develop and report Patch Test results against the wrong
revision.

Probe with `ls-remote --exit-code` instead: exit 2 means no matching ref, so
fall back; any other non-zero status is a real failure and is re-raised.
This commit is contained in:
Mihir Kandoi
2026-08-02 20:45:05 +05:30
parent 1a83fc516e
commit ccf54b5881

View File

@@ -171,11 +171,17 @@ jobs:
update_to_version 16 3.14
echo "Updating to latest version"
# a stacked PR's base is an erpnext feature branch with no counterpart in frappe,
# so fall back to the repository's default branch
base_ref="${GITHUB_BASE_REF:-${GITHUB_REF##*/}}"
git -C "apps/frappe" fetch --depth 1 upstream "$base_ref" \
|| git -C "apps/frappe" fetch --depth 1 upstream develop
ls_remote_status=0
git -C "apps/frappe" ls-remote --exit-code --heads upstream "$base_ref" >/dev/null \
|| ls_remote_status=$?
if [ "$ls_remote_status" -eq 2 ]; then
echo "frappe has no '$base_ref' branch; falling back to develop"
base_ref=develop
elif [ "$ls_remote_status" -ne 0 ]; then
exit "$ls_remote_status"
fi
git -C "apps/frappe" fetch --depth 1 upstream "$base_ref"
git -C "apps/frappe" checkout -q -f FETCH_HEAD
git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA"