Skip to content

Commit 0068491

Browse files
committed
working dbwebb test check if need pull
1 parent 5e74fa6 commit 0068491

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

.dbwebb/test/functions.bash

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,28 @@ execute_with_timeout () {
6262
# Check if git local is behind remote
6363
#
6464
check_if_need_pull () {
65-
if ! git diff --quiet remotes/origin/HEAD; then
66-
# Difference found
67-
return 1
68-
fi
65+
66+
LOCAL_REVSPEC=HEAD
67+
BRANCH=$(git rev-parse --abbrev-ref ${LOCAL_REVSPEC})
68+
69+
REMOTE_NAME=$(git config branch.${BRANCH}.remote)
70+
71+
72+
REMOTE_REVSPEC=remotes/${REMOTE_NAME}/${BRANCH}
73+
74+
if ! git fetch ${REMOTE_NAME}
75+
then
76+
echo "git fetch ${REMOTE_NAME} failed"
77+
exit 1
78+
fi
79+
80+
LOCAL_SHA1=$(git rev-parse ${LOCAL_REVSPEC})
81+
REMOTE_SHA1=$(git rev-parse ${REMOTE_REVSPEC})
82+
BASE_SHA1=$(git merge-base ${LOCAL_REVSPEC} ${REMOTE_REVSPEC})
83+
84+
if [ ${LOCAL_SHA1} = ${BASE_SHA1} ]; then
85+
# Found change in remote
6986
return 0
87+
fi
88+
return 1
7089
}

0 commit comments

Comments
 (0)