Skip to content

Commit

Permalink
fix: followup to 240746e. kiauh now also tries to identify the branch…
Browse files Browse the repository at this point in the history
… from the commit SHA if the HEAD was detached at a single commit, if the other method does not give a usefull output.
  • Loading branch information
dw-0 committed Dec 22, 2020
1 parent 240746e commit a44ae4c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scripts/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,26 @@ klipperscreen_status(){
#############################################################
#############################################################

#reading the log for the last branch that got checked out assuming that this is also the currently active branch.
### reading the klipper branch the user is currently on
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
### 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)
### try to identify the branch when the HEAD was detached at a single commit
### will only work if its either master, scurve-shaping or scurve-smoothing branch
if [[ $GET_BRANCH =~ [[:alnum:]] ]]; then
if [ "$(git branch -r --contains $GET_BRANCH | grep "master")" ]; then
GET_BRANCH="master"
elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-shaping")" ]; then
GET_BRANCH="scurve-shaping"
elif [ "$(git branch -r --contains $GET_BRANCH | grep "scurve-smoothing")" ]; then
GET_BRANCH="scurve-smoothing"
fi
fi
fi
else
GET_BRANCH=""
Expand Down

0 comments on commit a44ae4c

Please sign in to comment.