fix: previous klipper updates resulted in a detached head state. fixed update routine and other stuff relaying on the read_branch function/GET_BRANCH variable

This commit is contained in:
th33xitus
2020-12-20 18:41:42 +01:00
parent 06eb86efd7
commit 1eda775571
5 changed files with 28 additions and 63 deletions

View File

@@ -3,30 +3,18 @@ save_klipper_state(){
#read current klipper state #read current klipper state
cd $KLIPPER_DIR cd $KLIPPER_DIR
COMMIT_STATE=$(git rev-parse --short HEAD) COMMIT_STATE=$(git rev-parse --short HEAD)
if [ "$GET_BRANCH" = "origin/master" ]; then if [ "$GET_BRANCH" = "master" ]; then
ORI_OLD=$previous_origin_state ORI_OLD=$previous_origin_state
ORI_NEW=$COMMIT_STATE ORI_NEW=$COMMIT_STATE
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "origin" ]; then elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
ORI_OLD=$previous_origin_state
ORI_NEW=$COMMIT_STATE
sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "dmbutyugin/scurve-shaping" ]; then
SHA_OLD=$previous_shaping_state SHA_OLD=$previous_shaping_state
SHA_NEW=$COMMIT_STATE SHA_NEW=$COMMIT_STATE
sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "dmbutyugin/scurve-smoothing" ]; then elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
SMO_OLD=$previous_smoothing_state SMO_OLD=$previous_smoothing_state
SMO_NEW=$COMMIT_STATE SMO_NEW=$COMMIT_STATE
sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "Arksine/work-web_server-20200131" ]; then
WWS_OLD=$previous_moonraker_state
WWS_NEW=$COMMIT_STATE
sed -i "/previous_moonraker_state=/s/$WWS_OLD/$WWS_NEW/" $INI_FILE
elif [ "$GET_BRANCH" = "Arksine/dev-moonraker-testing" ]; then
DMT_OLD=$previous_dev_moonraker_state
DMT_NEW=$COMMIT_STATE
sed -i "/previous_dev_moonraker_state=/s/$DMT_OLD/$DMT_NEW/" $INI_FILE
fi fi
} }
@@ -35,16 +23,12 @@ load_klipper_state(){
print_branch print_branch
cd $KLIPPER_DIR cd $KLIPPER_DIR
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "origin" ]; then if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then
PREVIOUS_COMMIT=$previous_origin_state PREVIOUS_COMMIT=$previous_origin_state
elif [ "$GET_BRANCH" = "dmbutyugin/scurve-shaping" ]; then elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
PREVIOUS_COMMIT=$previous_shaping_state PREVIOUS_COMMIT=$previous_shaping_state
elif [ "$GET_BRANCH" = "dmbutyugin/scurve-smoothing" ]; then elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
PREVIOUS_COMMIT=$previous_smoothing_state PREVIOUS_COMMIT=$previous_smoothing_state
elif [ "$GET_BRANCH" = "Arksine/work-web_server-20200131" ]; then
PREVIOUS_COMMIT=$previous_moonraker_state
elif [ "$GET_BRANCH" = "Arksine/dev-moonraker-testing" ]; then
PREVIOUS_COMMIT=$previous_dev_moonraker_state
fi fi
CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT) CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT)
if [ "$PREVIOUS_COMMIT" != "0" ]; then if [ "$PREVIOUS_COMMIT" != "0" ]; then

View File

@@ -186,11 +186,8 @@ klipperscreen_status(){
#reading the log for the last branch that got checked out assuming that this is also the currently active branch. #reading the log for the last branch that got checked out assuming that this is also the currently active branch.
read_branch(){ read_branch(){
if [ -d $KLIPPER_DIR/.git ]; then if [ -d $KLIPPER_DIR/.git ]; then
GET_BRANCH=$(cat ~/klipper/.git/logs/HEAD | grep "checkout" | tail -1 | sed "s/^.*to //") cd $KLIPPER_DIR
#if the log file is empty, we can assume that klipper just got cloned and therefore is still on origin/master GET_BRANCH="$(git branch | grep "*" | cut -d"*" -f2 | cut -d" " -f2)"
if [[ -z "$GET_BRANCH" ]]; then
GET_BRANCH="origin/master"
fi
else else
GET_BRANCH="" GET_BRANCH=""
fi fi
@@ -199,18 +196,8 @@ read_branch(){
#prints the current klipper branch in the main menu #prints the current klipper branch in the main menu
print_branch(){ print_branch(){
read_branch read_branch
if [ "$GET_BRANCH" == "origin/master" ]; then if [ ! -z "$GET_BRANCH" ]; then
PRINT_BRANCH="$GET_BRANCH " PRINT_BRANCH="$(printf "%-16s" "$GET_BRANCH")"
elif [ "$GET_BRANCH" == "origin" ]; then
PRINT_BRANCH="origin/master "
elif [ "$GET_BRANCH" == "master" ]; then
PRINT_BRANCH="origin/master "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then
PRINT_BRANCH="scurve-shaping "
elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then
PRINT_BRANCH="scurve-smoothing"
elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then
PRINT_BRANCH="moonraker "
else else
PRINT_BRANCH="${red}--------------${default} " PRINT_BRANCH="${red}--------------${default} "
fi fi
@@ -231,9 +218,12 @@ read_remote_klipper_commit(){
if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "master" ]; then
git fetch origin -q git fetch origin -q
REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2 | cut -d"v" -f2) REMOTE_COMMIT=$(git describe origin/master --always --tags | cut -d "-" -f 1,2 | cut -d"v" -f2)
else elif [ "$GET_BRANCH" = "scurve-shaping" ]; then
git fetch $(echo "$GET_BRANCH" | cut -d"/" -f1) -q git fetch dmbutyugin scurve-shaping -q
REMOTE_COMMIT=$(git describe $GET_BRANCH --always --tags | cut -d "-" -f 1,2 | cut -d"v" -f2) REMOTE_COMMIT=$(git describe dmbutyugin/scurve-shaping --always --tags | cut -d "-" -f 1,2 | cut -d"v" -f2)
elif [ "$GET_BRANCH" = "scurve-smoothing" ]; then
git fetch dmbutyugin scurve-smoothing -q
REMOTE_COMMIT=$(git describe dmbutyugin/scurve-smoothing --always --tags | cut -d "-" -f 1,2 | cut -d"v" -f2)
fi fi
else else
REMOTE_COMMIT=$NONE REMOTE_COMMIT=$NONE

View File

@@ -1,7 +1,7 @@
switch_to_origin(){ switch_to_master(){
cd $KLIPPER_DIR cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo status_msg "Switching...Please wait ..."; echo
git fetch origin -q && git checkout origin/master -q git fetch origin -q && git checkout master; echo
} }
switch_to_scurve_shaping(){ switch_to_scurve_shaping(){
@@ -10,7 +10,7 @@ switch_to_scurve_shaping(){
if ! git remote | grep dmbutyugin -q; then if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO git remote add dmbutyugin $DMBUTYUGIN_REPO
fi fi
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SHAPING -q git fetch dmbutyugin -q && git checkout scurve-shaping; echo
} }
switch_to_scurve_smoothing(){ switch_to_scurve_smoothing(){
@@ -19,5 +19,5 @@ switch_to_scurve_smoothing(){
if ! git remote | grep dmbutyugin -q; then if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO git remote add dmbutyugin $DMBUTYUGIN_REPO
fi fi
git fetch dmbutyugin -q && git checkout $BRANCH_SCURVE_SMOOTHING -q git fetch dmbutyugin -q && git checkout scurve-smoothing; echo
} }

View File

@@ -104,12 +104,13 @@ switch_ui(){
echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}"
echo echo
top_border top_border
echo -e "| 1) [--> origin/master] | "
echo -e "| | " echo -e "| | "
echo -e "| KevinOConnor: | "
echo -e "| 1) [--> master] | "
echo -e "| | "
echo -e "| dmbutyugin: | "
echo -e "| 2) [--> scurve-shaping] | " echo -e "| 2) [--> scurve-shaping] | "
echo -e "| 3) [--> scurve-smoothing] | " echo -e "| 3) [--> scurve-smoothing] | "
echo -e "| | "
echo -e "| 4) [--> moonraker] | "
quit_footer quit_footer
} }
@@ -124,7 +125,7 @@ switch_menu(){
1) 1)
clear clear
print_header print_header
switch_to_origin switch_to_master
read_branch read_branch
print_msg && clear_msg print_msg && clear_msg
switch_ui;; switch_ui;;
@@ -176,7 +177,7 @@ rollback_ui(){
echo -e "| used commit from which you have updated. | " echo -e "| used commit from which you have updated. | "
bottom_border bottom_border
top_border top_border
echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | "
hr hr
echo -e "| Currently on commit: | " echo -e "| Currently on commit: | "
echo -e "| $CURR_UI | " echo -e "| $CURR_UI | "

View File

@@ -66,18 +66,8 @@ update_klipper(){
read_branch read_branch
save_klipper_state save_klipper_state
status_msg "Updating $GET_BRANCH" status_msg "Updating $GET_BRANCH"
#fetching origin/master -> error cd $KLIPPER_DIR && git pull && ok_msg "Update successfull!"
#rewriting origin/master to origin
if [ "$GET_BRANCH" = "origin/master" ]; then
FETCH_BRANCH="origin"
else
FETCH_BRANCH=$(echo "$GET_BRANCH" | cut -d "/" -f1)
fi
status_msg "Fetching from $FETCH_BRANCH"
cd $KLIPPER_DIR
git fetch $FETCH_BRANCH -q && ok_msg "Fetch successfull!"
status_msg "Checking out $GET_BRANCH"
git checkout $GET_BRANCH -q && ok_msg "Checkout successfull!"
#check for possible new dependencies and install them #check for possible new dependencies and install them
status_msg "Checking for possible new dependencies ..." status_msg "Checking for possible new dependencies ..."
PKGLIST=$(grep "PKGLIST=" ~/klipper/scripts/install-octopi.sh | cut -d'"' -f2- | cut -d'"' -f1 | cut -d"}" -f2) PKGLIST=$(grep "PKGLIST=" ~/klipper/scripts/install-octopi.sh | cut -d'"' -f2- | cut -d'"' -f1 | cut -d"}" -f2)