From 8d3571dd9952b5942154c0f8d790c8032789caa1 Mon Sep 17 00:00:00 2001 From: partisan Date: Sat, 20 Jul 2024 11:30:23 +0200 Subject: [PATCH] fix "fatal: couldn't find remote ref master" --- builder.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/builder.sh b/builder.sh index 09913e0..6a9d6a7 100755 --- a/builder.sh +++ b/builder.sh @@ -47,7 +47,26 @@ update_patches() { echo "Patches directory already exists. Cleaning and pulling updates..." cd "$PATCHES_DIR" || { echo "Failed to navigate to patches directory. Exiting."; exit 1; } git clean -xdf || { echo "Failed to clean patches directory. Exiting."; exit 1; } - git pull origin master || { echo "Failed to pull updates from patches repository. Exiting."; exit 1; } + + # Stash any local changes to ensure a clean rebase + git stash push --include-untracked || { echo "Failed to stash local changes. Exiting."; exit 1; } + + # Fetching all branches + git fetch || { echo "Failed to fetch updates from patches repository. Exiting."; exit 1; } + + # Trying to rebase onto 'main' branch + if git show-ref --verify --quiet refs/heads/main; then + git rebase origin/main || { echo "Failed to rebase updates from main branch. Exiting."; exit 1; } + elif git show-ref --verify --quiet refs/heads/master; then + # Fallback to 'master' branch if 'main' does not exist + git rebase origin/master || { echo "Failed to rebase updates from master branch. Exiting."; exit 1; } + else + echo "No valid branch (main or master) found in patches repository. Exiting." + exit 1 + fi + + # Drop stashed changes to discard local modifications + git stash drop || { echo "Failed to drop stashed changes. Exiting."; exit 1; } else echo "Patches directory does not exist. Cloning repository..." git clone "$PATCHES_REPO" "$PATCHES_DIR" || { echo "Failed to clone patches repository. Exiting."; exit 1; }