allow to chose upgrade branch

This commit is contained in:
fatalerrors
2026-04-15 13:44:44 +02:00
parent 9a006883b8
commit 89e20993da
2 changed files with 49 additions and 38 deletions

View File

@@ -217,6 +217,12 @@ MATRIX_DEFAULT_CHARSET=kana
[updates]
# Section used by updates.sh
#
# UPDT_DEFAULT_BRANCH — Git branch used for update checks and upgrades.
# Defaults to 'master' when unset. Changing this value will cause
# profile_upgrade to automatically switch the local checkout to the new
# branch on the next upgrade and display a warning.
#UPDT_DEFAULT_BRANCH=master
[general]
# General section allow to set any variable that can be used by the user.

View File

@@ -35,8 +35,14 @@
# ------------------------------------------------------------------------------
export BASE_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
export UPDT_URL="$BASE_URL/raw/branch/master"
export ARCH_URL="$BASE_URL/archive/master.tar.gz"
# Load [updates] configuration before building the URLs so that
# UPDT_DEFAULT_BRANCH (if set in profile.conf) is already available.
load_conf "updates"
export UPDT_DEFAULT_BRANCH="${UPDT_DEFAULT_BRANCH:-master}"
export UPDT_URL="$BASE_URL/raw/branch/$UPDT_DEFAULT_BRANCH"
export ARCH_URL="$BASE_URL/archive/$UPDT_DEFAULT_BRANCH.tar.gz"
# ------------------------------------------------------------------------------
# Check whether a newer profile version is available
@@ -251,6 +257,35 @@ profile_upgrade()
popd >/dev/null || return 1
return 3
}
# Resolve the target branch: explicit -b flag > config default > master
local target_branch="${branch:-${UPDT_DEFAULT_BRANCH:-master}}"
branch="$target_branch"
# Detect current local branch and warn+switch when it differs
local current_branch
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -n "$current_branch" && "$current_branch" != "$branch" ]]; then
disp W "Branch mismatch: currently on '$current_branch', configured branch is '$branch'."
if (( dry_run )); then
disp I "[dry-run] git fetch origin $branch"
disp I "[dry-run] git checkout $branch"
disp W "[dry-run] Branch would be changed from '$current_branch' to '$branch'."
else
git fetch origin "$branch" || {
disp E "Git fetch failed for branch $branch."
popd >/dev/null || return 1
return 2
}
git checkout "$branch" || {
disp E "Git checkout failed for branch $branch."
popd >/dev/null || return 1
return 2
}
disp W "Branch has been changed from '$current_branch' to '$branch'."
fi
fi
if ! git diff --quiet || ! git diff --cached --quiet || [[ -n $(git ls-files --others --exclude-standard) ]]; then
if (( force_git )); then
disp W "Force mode: local Git changes and untracked files will be lost."
@@ -281,44 +316,14 @@ profile_upgrade()
disp W "Upgrade may fail if the changes conflict with the upgrade."
fi
fi
if [[ -n "$branch" ]]; then
if (( dry_run )); then
disp I "[dry-run] git fetch origin $branch"
disp I "[dry-run] git checkout $branch"
else
git fetch origin "$branch" || {
disp E "Git fetch failed for branch $branch."
popd >/dev/null || return 1
return 2
}
git checkout "$branch" || {
disp E "Git checkout failed for branch $branch."
popd >/dev/null || return 1
return 2
}
fi
fi
if (( dry_run )); then
if [[ -n "$branch" ]]; then
disp I "[dry-run] git pull origin $branch"
else
disp I "[dry-run] git pull"
fi
else
if [[ -n "$branch" ]]; then
git pull origin "$branch" || {
disp E "Git pull failed, upgrade not applied."
popd >/dev/null || return 1
return 2
}
else
git pull || {
disp E "Git pull failed, upgrade not applied."
popd >/dev/null || return 1
return 2
}
fi
disp I "Successfully upgraded using git."
fi
popd >/dev/null || return 1