From 7117b328af398afb584f1aec23990a1a0d2fc90e Mon Sep 17 00:00:00 2001 From: Patrick Marie Date: Tue, 8 Oct 2024 20:35:01 +0200 Subject: [PATCH] Enable tracking --- scripts/backup.sh | 20 ++++++++++++++++++-- tests/tests_cases/1/.track | 1 + tests/tests_cases/10/.track | 1 + tests/tests_cases/2/.track | 1 + tests/tests_cases/99/.track | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/tests_cases/1/.track create mode 100644 tests/tests_cases/10/.track create mode 100644 tests/tests_cases/2/.track create mode 100644 tests/tests_cases/99/.track diff --git a/scripts/backup.sh b/scripts/backup.sh index 0256916..461f95e 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -5,10 +5,15 @@ set -e REPOSITORY=https://github.com/descartes-underwriting/devops-technical-test-data.git BRANCH=main DATA_DIR=$(pwd)/data +# max number of commit to backup MAX_NUM=0 +# logs! VERBOSE=0 +# ignore tracking. Can be useful to fill missing commits +# if 0 (and -i not used), will continue where it stopped. +IGNORE_TRACK=0 -while getopts ":r:b:d:vxn:h" opt +while getopts ":r:b:d:vxn:hi" opt do case ${opt} in r) @@ -25,6 +30,9 @@ do DATA_DIR=$(pwd)/${DATA_DIR} fi ;; + i) + IGNORE_TRACK=1 + ;; n) MAX_NUM=${OPTARG} ;; @@ -62,8 +70,14 @@ cd ${TMPDIR} git clone ${REPOSITORY} && cd ./* +CURRENT_COMMIT="" +if test -s ${DATA_DIR}/.track -a ${IGNORE_TRACK} -eq 0 +then + CURRENT_COMMIT=$(cat ${DATA_DIR}/.track).. +fi + # List all commit sha, from older to newer; -COMMIT_SHAS=$($GIT ${GIT_OPTS[@]} log --reverse --pretty=format:"%H" remotes/origin/${BRANCH}) +COMMIT_SHAS=$($GIT ${GIT_OPTS[@]} log --reverse --pretty=format:"%H" remotes/origin/${BRANCH} ${CURRENT_COMMIT}) NUM_ADDED=0 @@ -124,6 +138,8 @@ do NUM_ADDED=$((NUM_ADDED + 1)) + echo -n ${COMMIT_SHA} > ${DATA_DIR}/.track + if test ${NUM_ADDED} -eq ${MAX_NUM} then echo "Max commit to backup reached; stopping." diff --git a/tests/tests_cases/1/.track b/tests/tests_cases/1/.track new file mode 100644 index 0000000..0e92c2b --- /dev/null +++ b/tests/tests_cases/1/.track @@ -0,0 +1 @@ +282180fe7e5d9cbf297f2f0ef813cffe60ce2328 \ No newline at end of file diff --git a/tests/tests_cases/10/.track b/tests/tests_cases/10/.track new file mode 100644 index 0000000..3872986 --- /dev/null +++ b/tests/tests_cases/10/.track @@ -0,0 +1 @@ +729e5d2addf0a3566e454ddccf549041f2e9ab17 \ No newline at end of file diff --git a/tests/tests_cases/2/.track b/tests/tests_cases/2/.track new file mode 100644 index 0000000..e82cc0d --- /dev/null +++ b/tests/tests_cases/2/.track @@ -0,0 +1 @@ +46fe26c9dcf2354a0ed3f304ed6818de9606f7b5 \ No newline at end of file diff --git a/tests/tests_cases/99/.track b/tests/tests_cases/99/.track new file mode 100644 index 0000000..7186375 --- /dev/null +++ b/tests/tests_cases/99/.track @@ -0,0 +1 @@ +13fe0cca86cc6b12592e794c22e26bf4f3c52f9e \ No newline at end of file