From 006849106ad55d7295b92d2ccc44ac4c40ed44d4 Mon Sep 17 00:00:00 2001 From: Andreas Arnesson Date: Mon, 26 Jun 2023 14:13:05 +0200 Subject: [PATCH] working dbwebb test check if need pull --- .dbwebb/test/functions.bash | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.dbwebb/test/functions.bash b/.dbwebb/test/functions.bash index 7b49c74..d989cd4 100644 --- a/.dbwebb/test/functions.bash +++ b/.dbwebb/test/functions.bash @@ -62,9 +62,28 @@ execute_with_timeout () { # Check if git local is behind remote # check_if_need_pull () { - if ! git diff --quiet remotes/origin/HEAD; then - # Difference found - return 1 - fi + +LOCAL_REVSPEC=HEAD +BRANCH=$(git rev-parse --abbrev-ref ${LOCAL_REVSPEC}) + +REMOTE_NAME=$(git config branch.${BRANCH}.remote) + + +REMOTE_REVSPEC=remotes/${REMOTE_NAME}/${BRANCH} + +if ! git fetch ${REMOTE_NAME} +then + echo "git fetch ${REMOTE_NAME} failed" + exit 1 +fi + +LOCAL_SHA1=$(git rev-parse ${LOCAL_REVSPEC}) +REMOTE_SHA1=$(git rev-parse ${REMOTE_REVSPEC}) +BASE_SHA1=$(git merge-base ${LOCAL_REVSPEC} ${REMOTE_REVSPEC}) + +if [ ${LOCAL_SHA1} = ${BASE_SHA1} ]; then + # Found change in remote return 0 +fi +return 1 } \ No newline at end of file