From 240746e1b61cf967e31c7b1ea3f9533546320803 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Tue, 22 Dec 2020 20:39:12 +0100 Subject: [PATCH] fix: a fix for the detached HEAD issue when updating klipper that was introduced in a past commit. the user now gets a warn message that he needs to force update klipper. behind the scenes he will be brought back onto the branch and head gets reattached. --- scripts/status.sh | 9 +++++++++ scripts/update.sh | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/status.sh b/scripts/status.sh index 415eafa..ddadbc6 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -188,6 +188,11 @@ read_branch(){ if [ -d $KLIPPER_DIR/.git ]; then cd $KLIPPER_DIR GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)" + #try to fix a detached head state and read the correct branch from the output you get + if [ "$(echo $GET_BRANCH | grep "HEAD" )" ]; then + DETACHED_HEAD="true" + GET_BRANCH=$(git branch | grep "HEAD" | rev | cut -d" " -f1 | rev | cut -d")" -f1 | cut -d"/" -f2) + fi else GET_BRANCH="" fi @@ -243,6 +248,10 @@ compare_klipper_versions(){ REMOTE_COMMIT="${green}$(printf "%-12s" "$REMOTE_COMMIT")${default}" KLIPPER_UPDATE_AVAIL="false" fi + #if detached head was found, force the user with warn message to update klipper + if [ "$DETACHED_HEAD" == "true" ]; then + LOCAL_COMMIT="${red}$(printf "%-12s" "Need update!")${default}" + fi } ############################################################# diff --git a/scripts/update.sh b/scripts/update.sh index 2e0b2b5..de9e306 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -66,7 +66,12 @@ update_klipper(){ read_branch save_klipper_state status_msg "Updating $GET_BRANCH" - cd $KLIPPER_DIR && git pull && ok_msg "Update successfull!" + cd $KLIPPER_DIR + if [ "$DETACHED_HEAD" == "true" ]; then + git checkout $GET_BRANCH + unset DETACHED_HEAD + fi + git pull && ok_msg "Update successfull!" #check for possible new dependencies and install them status_msg "Checking for possible new dependencies ..."