From 40e9c9c08c171d51d31c464eae9f835dfe7a60f4 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Tue, 8 Jun 2021 18:02:19 +0200 Subject: [PATCH] update: fix branch update (cherry picked from commit dc1c7a8e423e0f42a3621199c43a6a1640b720a2) --- scripts/bash/update.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/bash/update.sh b/scripts/bash/update.sh index 4298198..dc993e8 100755 --- a/scripts/bash/update.sh +++ b/scripts/bash/update.sh @@ -9,6 +9,16 @@ fi ${log} "Updating the main repository to branch $BRANCH" +function auto_update(){ + git fetch + UPDATE=$(git diff --numstat origin/$BRANCH scripts/bash/update.sh | awk '/update.sh/ {print $NF}') + if [[ -n "${UPDATE}" ]]; then + # Update the file and restart the script + git checkout origin/$BRANCH scripts/bash/update.sh + exec scripts/bash/update.sh $BRANCH + fi +} + function restart(){ sudo nginx -t && sudo systemctl reload nginx sudo systemctl restart nodered.service @@ -19,7 +29,13 @@ function update(){ sudo killall -15 raspimjpeg sudo killall -15 python3 git stash - git checkout --force $BRANCH + # TODO detect branch change and use git pull on same branch and checkout on diff branch + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + if [ "$CURRENT_BRANCH" -eq $BRANCH ]; then + git merge + else + git checkout --force $BRANCH + fi git checkout stash@'{0}' -- config.json hardware.json # TODO we need to change this to drop stash@{1} if changes made to the flow are to be restored by the user git stash drop @@ -50,13 +66,7 @@ if [[ "$local" == "$remote" ]]; then ${log} "nothing to do!" else ${log} "Local and Remote are different, we have to update!" - git fetch - UPDATE=$(git diff --numstat origin/$BRANCH scripts/bash/update.sh | awk '/update.sh/ {print $NF}') - if [[ -n "${UPDATE}" ]]; then - # Update the file and restart the script - git checkout origin/$BRANCH scripts/bash/update.sh - exec scripts/bash/update.sh $BRANCH - fi + auto_update special_before update special_after