From 4e4c264fbcb138555b28023c920765fe5ff865d5 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Mon, 15 Jun 2026 09:36:28 +0100 Subject: [PATCH] fix: skip rebase in git/fetch when upstream branch no longer exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After git fetch --prune removes a stale remote tracking ref, an unconditional git rebase fails with "fatal: invalid upstream" when the current branch was tracking that deleted branch. Guard both rebase calls with git rev-parse --verify '@{upstream}' so they are skipped (with an info message) rather than causing a fatal error. Closes #681 Prompt: hey, fetch needs fixing... → No pending changes in working folder. Rebasing... fatal: invalid upstream 'refs/remotes/origin/feature/issue-408-optimise-project-checks' ✗ Could not rebase /home/markr/work/funfair/funfair-build-check --- git/fetch | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/git/fetch b/git/fetch index 84e6e7f4..771b6814 100755 --- a/git/fetch +++ b/git/fetch @@ -40,9 +40,14 @@ do if [ -z "$REPO_STATUS" ] then - info "No pending changes in working folder. Rebasing..." - git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${CURRENT_DIR}" - git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1 + if git -C "$CURRENT_DIR" rev-parse --verify '@{upstream}' > /dev/null 2>&1 + then + info "No pending changes in working folder. Rebasing..." + git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${CURRENT_DIR}" + git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1 + else + info "No valid upstream for current branch. Skipping rebase." + fi else info "Pending changes in working folder. Skipping rebase." fi @@ -63,8 +68,13 @@ do then info "Switching to ${DEFAULT_BRANCH} branch..." git -C "$CURRENT_DIR" checkout "$DEFAULT_BRANCH" 2>&1 || die "Could not switch to ${DEFAULT_BRANCH} in ${CURRENT_DIR}" - git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${DEFAULT_BRANCH} in ${CURRENT_DIR}" - git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1 + if git -C "$CURRENT_DIR" rev-parse --verify '@{upstream}' > /dev/null 2>&1 + then + git -C "$CURRENT_DIR" rebase 2>&1 || die "Could not rebase ${DEFAULT_BRANCH} in ${CURRENT_DIR}" + git -C "$CURRENT_DIR" rebase --abort > /dev/null 2>&1 + else + info "No valid upstream for ${DEFAULT_BRANCH}. Skipping rebase." + fi else info "Pending changes in working folder. Skipping switch to ${DEFAULT_BRANCH}." fi