This commit is contained in:
2026-07-25 16:47:09 -05:00
parent b324d31273
commit bd005495ce
5 changed files with 250 additions and 51 deletions
+78 -19
View File
@@ -5,6 +5,7 @@
[ "${2:-}" != "q" ] && source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
source /opt/idssys/ta-proxmenu/defaults.inc
source /opt/idssys/ta-proxmenu/inc/git-update.inc
ACTION_REQUESTED=0
[[ -n "${action:-}" ]] && ACTION_REQUESTED=1
@@ -744,16 +745,18 @@ UPDATE_CHECK_WORKER() {
WRITE_UPDATE_CACHE "unavailable" "$branch" "$local_commit" ""
return
fi
remote_commit="$(git -C "$FOLDER" ls-remote origin "refs/heads/${branch}" 2>/dev/null | cut -f1)"
if [[ -z "$remote_commit" ]]; then
status="unavailable"
elif [[ "$local_commit" == "$remote_commit" ]]; then
status="current"
else
status="available"
if TAPM_GIT_WORKTREE_DIRTY "$FOLDER"; then
WRITE_UPDATE_CACHE "dirty" "$branch" "$local_commit" ""
return
fi
if ! TAPM_GIT_FETCH_BRANCH "$FOLDER" "$branch" 30 >/dev/null 2>&1; then
WRITE_UPDATE_CACHE "unavailable" "$branch" "$local_commit" ""
return
fi
remote_commit="$(git -C "$FOLDER" rev-parse "refs/remotes/origin/${branch}" 2>/dev/null)"
status="$(TAPM_GIT_BRANCH_STATE "$FOLDER" "$branch")"
WRITE_UPDATE_CACHE "$status" "$branch" "$local_commit" "$remote_commit"
}
@@ -774,12 +777,14 @@ LOAD_UPDATE_STATUS() {
local cached_status
local current_branch
local current_commit
local current_dirty=0
local now
UPDATE_STATUS='unknown'
UPDATE_REMOTE_COMMIT=''
current_branch="$(git -C "$FOLDER" branch --show-current 2>/dev/null)"
current_commit="$(git -C "$FOLDER" rev-parse HEAD 2>/dev/null)"
TAPM_GIT_WORKTREE_DIRTY "$FOLDER" && current_dirty=1
now="$(date +%s)"
if [[ -r "$UPDATE_CACHE_FILE" ]]; then
@@ -789,7 +794,9 @@ LOAD_UPDATE_STATUS() {
(( now - checked_at < UPDATE_CACHE_SECONDS )) &&
[[ "$cached_branch" == "$current_branch" ]] &&
[[ "$cached_local" == "$current_commit" ]] &&
[[ "$cached_status" =~ ^(current|available|unavailable)$ ]]; then
[[ "$cached_status" =~ ^(current|behind|ahead|diverged|dirty|unavailable)$ ]] &&
{ [[ "$cached_status" == "dirty" && "$current_dirty" -eq 1 ]] ||
[[ "$cached_status" != "dirty" && "$current_dirty" -eq 0 ]]; }; then
UPDATE_STATUS="$cached_status"
UPDATE_REMOTE_COMMIT="$cached_remote"
return
@@ -818,12 +825,21 @@ FORCE_UPDATE_CHECK() {
echo -e "${idsCL[Default]}"
case "$UPDATE_STATUS" in
available)
behind)
echo -e "${idsCL[LightYellow]}An update is available for the current branch.${idsCL[Default]}"
;;
current)
echo -e "${idsCL[Green]}TA-ProxMenu is current.${idsCL[Default]}"
;;
ahead)
echo -e "${idsCL[LightYellow]}The current branch has local commits not on origin.${idsCL[Default]}"
;;
diverged)
echo -e "${idsCL[LightRed]}The current branch has diverged from origin; automatic update is disabled.${idsCL[Default]}"
;;
dirty)
echo -e "${idsCL[LightYellow]}The TA-ProxMenu repository has local file changes.${idsCL[Default]}"
;;
*)
echo -e "${idsCL[Red]}The update status could not be determined.${idsCL[Default]}"
;;
@@ -839,9 +855,18 @@ MENU_HEADER() {
LOAD_UPDATE_STATUS
case "$UPDATE_STATUS" in
available)
behind)
version_display="${idsCL[LightYellow]}${VERS} ** UPDATE AVAILABLE **${idsCL[Default]}"
;;
ahead)
version_display="${idsCL[LightYellow]}${VERS} ** LOCAL COMMITS **${idsCL[Default]}"
;;
diverged)
version_display="${idsCL[LightRed]}${VERS} ** BRANCH DIVERGED **${idsCL[Default]}"
;;
dirty)
version_display="${idsCL[LightYellow]}${VERS} ** LOCAL CHANGES **${idsCL[Default]}"
;;
checking)
version_display="${idsCL[LightCyan]}${VERS} (checking for updates)${idsCL[Default]}"
;;
@@ -1114,6 +1139,7 @@ SWITCH_SCRIPT_BRANCH() {
local target_branch="$1"
local current_branch
local choice
local target_state=''
current_branch="$(git -C "$FOLDER" branch --show-current 2>/dev/null)"
if [[ "$target_branch" == "$current_branch" ]]; then
@@ -1136,14 +1162,36 @@ SWITCH_SCRIPT_BRANCH() {
echo
[[ "$choice" =~ ^[Yy]$ ]] || return
if ! timeout 30 git -C "$FOLDER" fetch origin \
"refs/heads/${target_branch}:refs/remotes/origin/${target_branch}"; then
if ! TAPM_GIT_FETCH_BRANCH "$FOLDER" "$target_branch" 30; 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
target_state="$(
TAPM_GIT_RELATION "$FOLDER" "refs/heads/${target_branch}" \
"refs/remotes/origin/${target_branch}"
)" || {
echo -e "${idsCL[Red]}Could not compare local and remote '${target_branch}'.${idsCL[Default]}"
ENTER2CONTINUE
return
}
case "$target_state" in
ahead)
echo -e "${idsCL[LightYellow]}The local '${target_branch}' branch has commits not on origin.${idsCL[Default]}"
echo "Branch switching was refused to preserve those commits."
ENTER2CONTINUE
return
;;
diverged)
echo -e "${idsCL[LightRed]}The local '${target_branch}' branch has diverged from origin.${idsCL[Default]}"
echo "Branch switching was refused; manual Git review is required."
ENTER2CONTINUE
return
;;
esac
git -C "$FOLDER" switch "$target_branch" || {
ENTER2CONTINUE
return
@@ -1156,10 +1204,12 @@ SWITCH_SCRIPT_BRANCH() {
}
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
if [[ "$target_state" == "behind" ]]; then
if ! TAPM_GIT_FAST_FORWARD "$FOLDER" "$target_branch"; then
echo -e "${idsCL[Red]}Failed to fast-forward '${target_branch}'; no commits were discarded.${idsCL[Default]}"
ENTER2CONTINUE
return
fi
fi
rm -f "$UPDATE_CACHE_FILE"
@@ -1233,12 +1283,21 @@ UTILITIES_MENU() {
while true; do
LOAD_UPDATE_STATUS
case "$UPDATE_STATUS" in
available)
behind)
labels=("Install available update")
;;
current)
labels=("TA-ProxMenu is current")
;;
ahead)
labels=("Local branch is ahead of origin")
;;
diverged)
labels=("Local branch has diverged from origin")
;;
dirty)
labels=("Local repository has uncommitted changes")
;;
checking)
labels=("Update check in progress")
;;
@@ -1255,7 +1314,7 @@ UTILITIES_MENU() {
SELECT_MENU "Utilities" labels values
case "$MENU_SELECTION" in
install_update)
if [[ "$UPDATE_STATUS" != "available" ]]; then
if [[ "$UPDATE_STATUS" != "behind" ]]; then
echo -e "\n${idsCL[LightCyan]}No available update is currently detected.${idsCL[Default]}"
ENTER2CONTINUE
continue