From 920cf6de144b02950277b3b509a71c0adbad93a0 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Wed, 22 Dec 2021 19:21:44 +0100 Subject: [PATCH] Check for updates on master based on tags not commits (#4475) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check for updates on master based on tags not commits Signed-off-by: Christian König * Fix stickler Signed-off-by: Christian König * Address reviewer's comments Signed-off-by: Christian König * Fix stickler again Signed-off-by: Christian König * Use local git instead of relying on github Signed-off-by: Christian König * Add --tags Co-authored-by: DL6ER Co-authored-by: DL6ER --- advanced/Scripts/update.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 3fab9a95..d18d2e78 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -35,25 +35,37 @@ source "/opt/pihole/COL_TABLE" GitCheckUpdateAvail() { local directory + local curBranch directory="${1}" curdir=$PWD cd "${directory}" || return # Fetch latest changes in this repo - git fetch --quiet origin + git fetch --tags --quiet origin - # @ alone is a shortcut for HEAD. Older versions of git - # need @{0} - LOCAL="$(git rev-parse "@{0}")" + # Check current branch. If it is master, then check for the latest available tag instead of latest commit. + curBranch=$(git rev-parse --abbrev-ref HEAD) + if [[ "${curBranch}" == "master" ]]; then + # get the latest local tag + LOCAL=$(git describe --abbrev=0 --tags master) + # get the latest tag from remote + REMOTE=$(git describe --abbrev=0 --tags origin/master) + + else + # @ 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}")" + fi - # 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}")" if [[ "${#LOCAL}" == 0 ]]; then echo -e "\\n ${COL_LIGHT_RED}Error: Local revision could not be obtained, please contact Pi-hole Support"