diff --git a/profile.conf b/profile.conf index 4de128f..ca4b1d2 100755 --- a/profile.conf +++ b/profile.conf @@ -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. diff --git a/profile.d/updates.sh b/profile.d/updates.sh index 26a5076..5ad112c 100644 --- a/profile.d/updates.sh +++ b/profile.d/updates.sh @@ -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 + disp I "[dry-run] git pull origin $branch" 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 + git pull origin "$branch" || { + disp E "Git pull failed, upgrade not applied." + popd >/dev/null || return 1 + return 2 + } disp I "Successfully upgraded using git." fi popd >/dev/null || return 1