From e3c1fcd2c610bffcfa365b84e0dabfc57457c715 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 5 Jan 2017 13:10:19 +0100 Subject: [PATCH] NEW LOGIC FOR THE UPDATER Compare local and remote hashes. Update is available if current remote hash is different from current local hash since we assume that local should never be newer than remote for user --- advanced/Scripts/update.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index a2a5e8dc..df71e9a9 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -91,12 +91,37 @@ GitCheckUpdateAvail() { # Fetch latest changes in this repo git fetch --quiet origin - status="$(git status -sb)" + + # @ alone is a shortcut for HEAD. Older versions of git + # need @{0} + LOCAL="$(git rev-parse @{0})" + + # The suffix @{upstream} to a branchname + # (short form @{u}) refers + # to the branch that the branch specified + # by branchname is set to build on top of# + # (configured with branch..remote and + # branch..merge). A missing branchname + # defaults to the current one. + REMOTE="$(git rev-parse @{upstream})" # Change back to original directory cd "${curdir}" - if [[ $status == *"behind"* ]]; then + if [[ ${#LOCAL} == 0 ]]; then + echo "::: Error: Local revision could not be optained, ask Pi-hole support." + echo "::: Additional debugging output:" + git status + exit + fi + if [[ ${#REMOTE} == 0 ]]; then + echo "::: Error: Remote revision could not be optained, ask Pi-hole support." + echo "::: Additional debugging output:" + git status + exit + fi + + if [[ "${LOCAL}" != "${REMOTE}" ]]; then # Local branch is behind remote branch -> Update return 0 else