update
This commit is contained in:
+122
-2
@@ -761,9 +761,124 @@ SERVICE_RECOVERY_MENU() {
|
||||
done
|
||||
}
|
||||
|
||||
SWITCH_SCRIPT_BRANCH() {
|
||||
local target_branch="$1"
|
||||
local current_branch
|
||||
local choice
|
||||
|
||||
current_branch="$(git -C "$FOLDER" branch --show-current 2>/dev/null)"
|
||||
if [[ "$target_branch" == "$current_branch" ]]; then
|
||||
echo -e "\n${idsCL[Green]}TA-ProxMenu is already using '${target_branch}'.${idsCL[Default]}"
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -n "$(git -C "$FOLDER" status --porcelain --untracked-files=normal)" ]]; then
|
||||
echo -e "\n${idsCL[Red]}The installed TA-ProxMenu repository has local changes.${idsCL[Default]}"
|
||||
echo "Branch switching was refused to protect those files."
|
||||
echo
|
||||
git -C "$FOLDER" status --short
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
echo -en "\n${idsCL[LightCyan]}Switch TA-ProxMenu from '${current_branch}' to '${target_branch}' (y/N)?${idsCL[Default]} "
|
||||
read -n 1 choice
|
||||
echo
|
||||
[[ "$choice" =~ ^[Yy]$ ]] || return
|
||||
|
||||
if ! timeout 30 git -C "$FOLDER" fetch origin \
|
||||
"refs/heads/${target_branch}:refs/remotes/origin/${target_branch}"; then
|
||||
echo -e "${idsCL[Red]}Failed to fetch '${target_branch}' from origin.${idsCL[Default]}"
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
if git -C "$FOLDER" show-ref --verify --quiet "refs/heads/${target_branch}"; then
|
||||
git -C "$FOLDER" switch "$target_branch" || {
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
}
|
||||
else
|
||||
git -C "$FOLDER" switch --create "$target_branch" \
|
||||
--track "origin/${target_branch}" || {
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
}
|
||||
fi
|
||||
|
||||
if ! git -C "$FOLDER" reset --hard "origin/${target_branch}"; then
|
||||
echo -e "${idsCL[Red]}Failed to synchronize '${target_branch}' with origin.${idsCL[Default]}"
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
rm -f "$UPDATE_CACHE_FILE"
|
||||
echo -e "\n${idsCL[Green]}Now using TA-ProxMenu branch '${target_branch}'.${idsCL[Default]}"
|
||||
sleep 1
|
||||
exec /opt/idssys/ta-proxmenu/run.sh
|
||||
}
|
||||
|
||||
BRANCH_MANAGEMENT_MENU() {
|
||||
local -a labels=()
|
||||
local -a values=()
|
||||
local branch
|
||||
local branch_version
|
||||
local current_branch
|
||||
|
||||
MENU_HEADER
|
||||
echo
|
||||
echo -e " ${idsCL[LightCyan]}Refreshing remote branch list...${idsCL[Default]}"
|
||||
|
||||
if ! timeout 30 git -C "$FOLDER" fetch origin \
|
||||
'+refs/heads/*:refs/remotes/origin/*' --prune >/dev/null 2>&1; then
|
||||
echo -e "\n${idsCL[Red]}Could not retrieve branches from origin.${idsCL[Default]}"
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
current_branch="$(git -C "$FOLDER" branch --show-current 2>/dev/null)"
|
||||
while IFS= read -r branch; do
|
||||
[[ -n "$branch" && "$branch" != "HEAD" ]] || continue
|
||||
branch_version="$(
|
||||
git -C "$FOLDER" show "refs/remotes/origin/${branch}:defaults.inc" \
|
||||
2>/dev/null |
|
||||
awk -F"'" '/^VERS=/{ print $2; exit }'
|
||||
)"
|
||||
|
||||
if [[ "$branch" == "$current_branch" ]]; then
|
||||
labels+=("${branch} (current, version ${branch_version:-unknown})")
|
||||
else
|
||||
labels+=("${branch} (version ${branch_version:-unknown})")
|
||||
fi
|
||||
values+=("branch:${branch}")
|
||||
done < <(
|
||||
git -C "$FOLDER" for-each-ref \
|
||||
--format='%(refname:strip=3)' refs/remotes/origin |
|
||||
sort -V
|
||||
)
|
||||
|
||||
if (( ${#labels[@]} == 0 )); then
|
||||
echo -e "\n${idsCL[Red]}No remote branches were found.${idsCL[Default]}"
|
||||
ENTER2CONTINUE
|
||||
return
|
||||
fi
|
||||
|
||||
while true; do
|
||||
SELECT_MENU "Git Branch Management" labels values
|
||||
case "$MENU_SELECTION" in
|
||||
branch:*)
|
||||
SWITCH_SCRIPT_BRANCH "${MENU_SELECTION#branch:}"
|
||||
;;
|
||||
back) return;;
|
||||
quit) EXIT1; exit 0;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
UTILITIES_MENU() {
|
||||
local -a labels
|
||||
local -a values=("install_update" "check_update" "about")
|
||||
local -a values=("install_update" "check_update" "branches" "about")
|
||||
local choice
|
||||
|
||||
while true; do
|
||||
@@ -782,7 +897,11 @@ UTILITIES_MENU() {
|
||||
labels=("Update status unavailable")
|
||||
;;
|
||||
esac
|
||||
labels+=("Check again now" "Version and installation information")
|
||||
labels+=(
|
||||
"Check again now"
|
||||
"Git branch management"
|
||||
"Version and installation information"
|
||||
)
|
||||
|
||||
SELECT_MENU "Utilities" labels values
|
||||
case "$MENU_SELECTION" in
|
||||
@@ -802,6 +921,7 @@ UTILITIES_MENU() {
|
||||
ENTER2CONTINUE
|
||||
;;
|
||||
check_update) FORCE_UPDATE_CHECK;;
|
||||
branches) BRANCH_MANAGEMENT_MENU;;
|
||||
about) SHOW_ABOUT;;
|
||||
back) return;;
|
||||
quit) EXIT1; exit 0;;
|
||||
|
||||
Reference in New Issue
Block a user