From 3c95e197e6f01bc87334a89da71479d5aa0616ea Mon Sep 17 00:00:00 2001 From: Alexander Sherikov Date: Mon, 30 Sep 2024 22:21:28 +0400 Subject: [PATCH] Add nolfs policy --- Makefile | 3 ++- README.md | 6 ++--- tests/update/.repos | 8 +++--- wshandler | 59 +++++++++++++++++++++++++++++---------------- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 5bb7f5f..e3542b4 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ test_update: ${WSHANDLER} -t ${TYPE} -r tests/update/ --jobs 2 --policy shallow update ${WSHANDLER} -t ${TYPE} --root tests/update/ status ${WSHANDLER} -t ${TYPE} --root tests/update/ -j 2 clean - ${WSHANDLER} -t ${TYPE} -r tests/update/ --jobs 2 --policy shallow,rebase update + ${WSHANDLER} -t ${TYPE} -r tests/update/ --jobs 2 --policy shallow,rebase,nolfs update ${WSHANDLER} -t ${TYPE} --root tests/update/ status ${WSHANDLER} -t ${TYPE} --root tests/update/ -j 2 clean ${WSHANDLER} -t ${TYPE} -r tests/update/ --jobs 2 --policy rebase update @@ -63,6 +63,7 @@ test_remove: test_init: ${WSHANDLER} -t ${TYPE} --root tests/init_${TYPE} -p shallow init git https://github.com/asherikov/staticoma.git + ${WSHANDLER} -t ${TYPE} --root tests/init_${TYPE}_nolfs -p shallow,nolfs init git https://github.com/asherikov/staticoma.git test_set_version: ${WSHANDLER} -t ${TYPE} --root tests/update/ set_version_by_url https://github.com/asherikov/qpmad.git master diff --git a/README.md b/README.md index 33682a9..9d2908a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Common arguments: -k|--keep-going {false} List commands: status - [-j|--jobs {1}] [-p|--policy {default}|shallow|rebase] update + [-j|--jobs {1}] [-p|--policy policy1[,policy2] ({default}|shallow|nolfs|rebase)] update [-j|--jobs {1}] clean [-p|--policy {ask}|add|show] scrape add git @@ -53,8 +53,8 @@ List commands: remove_by_url [-p|--policy {keep}|replace] merge List initialization commands: - [-p|--policy {default}|shallow|rebase] clone git [] - [-p|--policy {default}|shallow] init [git ...] + [-p|--policy policy1[,policy2] ({default}|shallow|nolfs)] clone git [] + [-p|--policy policy1[,policy2] ({default}|shallow|nolfs)] init [git ...] Repository commands: [-j|--jobs {1}] [-s|-source {git}] foreach '' prune diff --git a/tests/update/.repos b/tests/update/.repos index 514db8e..10c4748 100644 --- a/tests/update/.repos +++ b/tests/update/.repos @@ -2,10 +2,6 @@ repositories: staticoma: type: git url: https://github.com/asherikov/staticoma.git - staticoma_master: - type: git - url: https://github.com/asherikov/staticoma.git - version: master staticoma_commit: type: git url: https://github.com/asherikov/staticoma.git @@ -18,3 +14,7 @@ repositories: type: git url: https://github.com/asherikov/qpmad.git version: 1.3.0 + staticoma_master: + type: git + url: https://github.com/asherikov/staticoma.git + version: master diff --git a/wshandler b/wshandler index 05f6952..43a9497 100755 --- a/wshandler +++ b/wshandler @@ -21,7 +21,7 @@ help() echo "List commands:" echo " status" - echo " [-j|--jobs {1}] [-p|--policy {default}|shallow|rebase] update" + echo " [-j|--jobs {1}] [-p|--policy policy1[,policy2] ({default}|shallow|nolfs|rebase)] update" echo " [-j|--jobs {1}] clean" echo " [-p|--policy {ask}|add|show] scrape" echo " add git " @@ -32,8 +32,8 @@ help() echo " [-p|--policy {keep}|replace] merge " echo "List initialization commands:" - echo " [-p|--policy {default}|shallow|rebase] clone git []" - echo " [-p|--policy {default}|shallow] init [git ...]" + echo " [-p|--policy policy1[,policy2] ({default}|shallow|nolfs)] clone git []" + echo " [-p|--policy policy1[,policy2] ({default}|shallow|nolfs)] init [git ...]" echo "Repository commands:" echo " [-j|--jobs {1}] [-s|-source {git}] foreach ''" @@ -130,15 +130,20 @@ git_update() # if we are on a branch make sure that it is updated if (git branch --show-current | grep "${GIT_VERSION}") then + PULL_ENV=(env) PULL_ARGS=() for POLICY in "${POLICIES[@]}"; do - if [ "${POLICY}" == "rebase" ] - then - PULL_ARGS+=(--rebase) - fi + case ${POLICY} in + rebase) + PULL_ARGS+=(--rebase) + ;; + nolfs) + PULL_ENV+=("GIT_LFS_SKIP_SMUDGE=1") + ;; + esac done - git pull "${PULL_ARGS[@]}" + "${PULL_ENV[@]}" git pull "${PULL_ARGS[@]}" fi fi popd @@ -206,13 +211,20 @@ git_clone() VERSION=$2 DIR=$3 + CLONE_ENV=(env) CLONE_ARGS=(--recurse-submodules) for POLICY in "${POLICIES[@]}"; do - if [ "${POLICY}" == "shallow" ] - then - CLONE_ARGS+=(--depth 1 --shallow-submodules) - fi + case ${POLICY} in + shallow) + # --no-tags -- we need tags + # --single-branch -- implied by --depth + CLONE_ARGS+=(--depth 1 --shallow-submodules) + ;; + nolfs) + CLONE_ENV+=("GIT_LFS_SKIP_SMUDGE=1") + ;; + esac done SOURCE_DESTINATION=("${GIT_REPO}") @@ -223,15 +235,15 @@ git_clone() if [ "${VERSION}" == '-' ] || [ -z "${VERSION}" ] then - git clone "${CLONE_ARGS[@]}" "${SOURCE_DESTINATION[@]}" + "${CLONE_ENV[@]}" git clone "${CLONE_ARGS[@]}" "${SOURCE_DESTINATION[@]}" else - if ! (git clone "${CLONE_ARGS[@]}" --branch "${VERSION}" "${SOURCE_DESTINATION[@]}") + if ! ("${CLONE_ENV[@]}" git clone "${CLONE_ARGS[@]}" --branch "${VERSION}" "${SOURCE_DESTINATION[@]}") then # GIT_VERSION is a hash # clone with history to be able to find it - git clone --recurse-submodules "${SOURCE_DESTINATION[@]}" + "${CLONE_ENV[@]}" git clone --recurse-submodules "${SOURCE_DESTINATION[@]}" pushd "${DIR}" - git checkout "${VERSION}" + "${CLONE_ENV[@]}" git checkout "${VERSION}" popd fi fi @@ -316,15 +328,20 @@ dir_git_update() # if we are on a branch make sure that it is updated if (git branch --show-current | grep "${GIT_VERSION}") then + PULL_ENV=(env) PULL_ARGS=() for POLICY in "${POLICIES[@]}"; do - if [ "${POLICY}" == "rebase" ] - then - PULL_ARGS+=(--rebase) - fi + case ${POLICY} in + rebase) + PULL_ARGS+=(--rebase) + ;; + nolfs) + PULL_ENV+=("GIT_LFS_SKIP_SMUDGE=1") + ;; + esac done - git pull "${PULL_ARGS[@]}" + "${PULL_ENV[@]}" git pull "${PULL_ARGS[@]}" fi fi else