From 3bcc0126657775c8bb5d069287cb9f25ecd2e279 Mon Sep 17 00:00:00 2001 From: "Claus Schneider(Eficode)" Date: Fri, 1 Aug 2025 23:42:31 +0200 Subject: [PATCH] gh-17 adding list and summary and prune function Breaking: - option regex replaced with glob as was implemented as glob. regex might come later using grep as filter New features: - added: function "list" artifacts command with glob pattern - added: function "summary" using delimiter (default: /) . it finds all first fields and then counts number of artifacts given the pattern - added: function "prune". given a pattern find all artifacts and then keep the last amount given (default: 20). It is supporting --dryrun option Tests: - refactor tests to functions and enable single test case execution - it is still defaulting to * if not given - tests for new functions --- .test/7/git-reference.log | 10 + .test/8/git-reference.log | 34 +++ .test/9/git-reference.log | 44 ++++ _tests.sh | 470 ++++++++++++++++++++++++++++---------- git-artifact | 139 +++++++++-- 5 files changed, 556 insertions(+), 141 deletions(-) create mode 100644 .test/7/git-reference.log create mode 100644 .test/8/git-reference.log create mode 100644 .test/9/git-reference.log diff --git a/.test/7/git-reference.log b/.test/7/git-reference.log new file mode 100644 index 0000000..5b84a0c --- /dev/null +++ b/.test/7/git-reference.log @@ -0,0 +1,10 @@ +* (tag: v7.1) v7.1 +| * (tag: v2.0) v2.0 +|/ +| * (tag: v1.0) v1.0 +|/ +* (HEAD -> main, origin/main) First commit of git artifact +v1.0 +v2.0 +v7.1 +Tags found: v*.* : 3 diff --git a/.test/8/git-reference.log b/.test/8/git-reference.log new file mode 100644 index 0000000..f2b01f4 --- /dev/null +++ b/.test/8/git-reference.log @@ -0,0 +1,34 @@ +* (tag: test2/v8.7) test2/v8.7 +| * (tag: test2/v8.6) test2/v8.6 +|/ +| * (tag: test2/v8.5) test2/v8.5 +|/ +| * (tag: test2/v8.4) test2/v8.4 +|/ +| * (tag: test2/v8.3) test2/v8.3 +|/ +| * (tag: test2/v8.2) test2/v8.2 +|/ +| * (tag: test2/v8.1) test2/v8.1 +|/ +| * (tag: test1/v8.5) test1/v8.5 +|/ +| * (tag: test1/v8.4) test1/v8.4 +|/ +| * (tag: test1/v8.3) test1/v8.3 +|/ +| * (tag: test1/v8.2) test1/v8.2 +|/ +| * (tag: test1/v8.1) test1/v8.1 +|/ +| * (tag: v2.0) v2.0 +|/ +| * (tag: v1.0) v1.0 +|/ +* (HEAD -> main, origin/main) First commit of git artifact +Summary of of amount of tags in using delimiter: / and filter on first column +---------------------------------------------------------------------------------------- +v1.0 : 1 +test2 : 7 +test1 : 5 +v2.0 : 1 diff --git a/.test/9/git-reference.log b/.test/9/git-reference.log new file mode 100644 index 0000000..f917d14 --- /dev/null +++ b/.test/9/git-reference.log @@ -0,0 +1,44 @@ +* (tag: v9.10) v9.10 +| * (tag: v9.9) v9.9 +|/ +| * (tag: v9.8) v9.8 +|/ +| * (tag: v9.7) v9.7 +|/ +| * (tag: v9.6) v9.6 +|/ +| * (tag: v9.5) v9.5 +|/ +| * (tag: v9.4) v9.4 +|/ +| * (tag: v9.3) v9.3 +|/ +| * (tag: v9.2) v9.2 +|/ +| * (tag: v9.1) v9.1 +|/ +| * (tag: v2.0) v2.0 +|/ +| * (tag: v1.0) v1.0 +|/ +* (HEAD -> main, origin/main) First commit of git artifact +Amount of tags total: 12 +Amount of tags to be pruned: 7 +Amount of tags to be kept: 5 +Dry run - not executing prune command +* (tag: v9.10) v9.10 +| * (tag: v9.9) v9.9 +|/ +| * (tag: v9.8) v9.8 +|/ +| * (tag: v9.7) v9.7 +|/ +| * (tag: v9.6) v9.6 +|/ +* (HEAD -> main, origin/main) First commit of git artifact +v9.6 +v9.7 +v9.8 +v9.9 +v9.10 +Tags found: v*.* : 5 diff --git a/_tests.sh b/_tests.sh index 1f82482..a0dbd79 100755 --- a/_tests.sh +++ b/_tests.sh @@ -1,15 +1,82 @@ #!/usr/bin/env bash + +function usage() { + cat <&2 + exit 1 + } + arg_testcase="$2" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + --debug|-d) + arg_debug=true + shift + ;; + --verbose) + verbose=true + shift + ;; + *) + echo "Unknown option: $1" + usage + exit 1 + ;; + esac +done + clear set -euo pipefail -[[ ${debug:-} == true ]] && { - echo "debug: ${debug}" - set -x -} PATH=$(pwd):$PATH source "$(dirname "$0")/git-artifact" +[[ ${arg_debug:-} == true ]] && { + export debug=true + export arg_debug=true + debug "arg_debug: ${arg_debug}" + debug "debug: ${debug}" + set -x +} check_environment cd .test @@ -22,7 +89,13 @@ remote_tester_repo=.remote clone_tester_repo=.clone global_exit_code=0 +# shellcheck disable=SC2317 function testcase_header() { + [[ ! -d "${test}" ]] && { + echo "Creating test directory: ${test} and empty git-reference.log" + mkdir -p "${test}" + touch "${test}/git-reference.log" + } [[ ${verbose:-} == true ]] || return 0 echo echo "--------------------------------------------------------------------------------" @@ -30,15 +103,21 @@ function testcase_header() { echo "--------------------------------------------------------------------------------" } +# shellcheck disable=SC2317 +function generate_git_test_log() { + rm -rf .git/refs/remotes/origin/HEAD + git log --graph --all --oneline --format="%d %s" >> "${root_folder}/${test}/git-test.log" +} + +# shellcheck disable=SC2317 function eval_testcase() { # expect to be in repo to test against # In git 2.48 changes the way HEAD is handled and for some reason it is not set # in order to be backward compatible we remove the HEAD reference - rm -rf .git/refs/remotes/origin/HEAD - if ! [[ -s "${root_folder}/${test}/git-test.log" ]]; then - git log --graph --all --oneline --format="%d %s" > "${root_folder}/${test}/git-test.log" + if ! [[ -s "${root_folder}/${test}/git-test.log" ]]; then + generate_git_test_log else [[ ${debug:-} == true ]] && echo "Test $test : INFO: ${root_folder}/${test}/git-test.log is already available - use it" fi @@ -62,6 +141,7 @@ function eval_testcase() { echo } +# shellcheck disable=SC2317 function generate_base_repo() { rm -rf "${local_tester_repo:?}/" "${remote_tester_repo:?}/" "${clone_tester_repo:?}/" git init --bare -b "${default_branch:-main}" $remote_tester_repo || { @@ -87,131 +167,269 @@ echo " - /ok.log(all good)" echo " - /nok.log(failed tests)" echo -export test="1" -testcase_synopsis="base-repo default-branch; clone" -testcase_header -{ - cd $test - generate_base_repo - cd $local_tester_repo -} > ${test}/run.log 2>&1 -eval_testcase - -export test="1.1" -testcase_synopsis="base-repo master-branch; clone" -testcase_header -{ - cd $test - export default_branch=master - generate_base_repo - cd $local_tester_repo - unset default_branch -} > ${test}/run.log 2>&1 -eval_testcase - - - -export test="2" -testcase_synopsis="base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out" -testcase_header -{ - cd $test - generate_base_repo - git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo - cd $clone_tester_repo - git artifact fetch-co -t v1.0 - git artifact fetch-co -t v2.0 -} > ${test}/run.log 2>&1 -eval_testcase - -export test="3" -testcase_synopsis="base-repo ; clone - gives a repo without any artifacts" -testcase_header -{ - cd $test - generate_base_repo "latest" - git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo - cd $clone_tester_repo -} > ${test}/run.log 2>&1 -eval_testcase - -test="4" -testcase_synopsis="base-repo ; clone; add-n-push with branch" -testcase_header -{ - cd $test - generate_base_repo - git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo - cd $clone_tester_repo - touch test$test.txt - git artifact add-n-push -t v${test}.0 -b latest - touch test$test.1.txt - git artifact add-n-push -t v${test}.1 -b latest -} > ${test}/run.log 2>&1 -eval_testcase - -test="5" -testcase_synopsis="base-repo ; clone; fetch-co-latest pattern" -testcase_header -{ - cd $test - generate_base_repo - sleep 1 - git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo - cd $clone_tester_repo - git artifact fetch-co-latest -r 'v*.*' - git artifact reset +# shellcheck disable=SC2317 +function 1 { + export test="1" + testcase_synopsis="base-repo default-branch; clone" + testcase_header + { + cd $test + generate_base_repo + cd $local_tester_repo + } > ${test}/run.log 2>&1 + eval_testcase +} + +# shellcheck disable=SC2317 +function 1.1 { + export test="1.1" + testcase_synopsis="base-repo master-branch; clone" + testcase_header + { + cd $test + export default_branch=master + generate_base_repo + cd $local_tester_repo + unset default_branch + } > ${test}/run.log 2>&1 + eval_testcase +} + +# shellcheck disable=SC2317 +function 2 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out" + testcase_header + { + cd $test + generate_base_repo + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co -t v1.0 + git artifact fetch-co -t v2.0 + } > ${test}/run.log 2>&1 + eval_testcase +} + +# shellcheck disable=SC2317 +function 3 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone - gives a repo without any artifacts" + testcase_header + { + cd $test + generate_base_repo "latest" + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + } > ${test}/run.log 2>&1 + eval_testcase +} + +# shellcheck disable=SC2317 +function 4 { + export test="4" + testcase_synopsis="base-repo ; clone; add-n-push with branch" + testcase_header + { + cd $test + generate_base_repo + git artifact clone --url "$(pwd)/$remote_tester_repo" -b latest --path "$clone_tester_repo" + cd $clone_tester_repo + touch test$test.txt + git artifact add-n-push -t v${test}.0 -b latest + touch test$test.1.txt + git artifact add-n-push -t v${test}.1 -b latest + } > ${test}/run.log 2>&1 + eval_testcase +} + +# shellcheck disable=SC2317 +function 5 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; fetch-co-latest pattern" + testcase_header + { + cd $test + generate_base_repo + sleep 1 + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co-latest -g 'v*.*' + git artifact reset + + cd ../$local_tester_repo + touch test$test.txt + git artifact add-n-push -t v${test}.0 + sleep 1 + + cd ../$clone_tester_repo + git artifact fetch-co-latest -g 'v*.*' + git artifact reset + sleep 1 + + cd ../$local_tester_repo + touch test$test.1.txt + git artifact add-n-push -t v${test}.1 + sleep 1 + + cd ../$clone_tester_repo + git artifact fetch-co-latest --glob 'v*.*' + + } > ${test}/run.log 2>&1 || { echo "ERROR_CODE: $?"; pwd && cat ../run.log; } + eval_testcase +} + +# shellcheck disable=SC2317 +function 5.1 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; find-latest pattern" + testcase_header + { + cd $test + generate_base_repo + sleep 1 + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git ls-remote origin --tags + git artifact find-latest -g 'v*.*' > ${root_folder}/${test}/git-test.log + } > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; } + eval_testcase +} + + +# shellcheck disable=SC2317 +function 6 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; fetch-tags" + testcase_header + { + cd $test + generate_base_repo + git artifact clone --url "$(pwd)/$remote_tester_repo" -b latest --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co --tag v1.0 + sha1=$(git rev-parse HEAD) + git tag -d v1.0 + git artifact fetch-tags --sha1 "$sha1" + } > ${test}/run.log 2>&1 || cat ../${test}/run.log + eval_testcase +} + +# shellcheck disable=SC2317 +function 7 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; list" + testcase_header + { + cd $test + generate_base_repo + sleep 1 + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co-latest -g 'v*.*' + git artifact reset + + cd ../$local_tester_repo + + touch test${test}_1.txt + git artifact add-n-push -t v${test}.1 + + generate_git_test_log + git artifact list --glob 'v*.*' >> ${root_folder}/${test}/git-test.log - cd ../$local_tester_repo - touch test$test.txt - git artifact add-n-push -t v${test}.0 - sleep 1 + + } > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; } + eval_testcase +} + +# shellcheck disable=SC2317 +function 8 { + test="${FUNCNAME[0]}" + testcase_synopsis="base-repo ; clone; summary" + testcase_header + { + cd $test + generate_base_repo + sleep 1 + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co-latest -g 'v*.*' + git artifact reset + + cd ../$local_tester_repo + + for i in {1..5}; do + touch test${test}_$i.txt + git artifact add-n-push -t test1/v${test}.$i + sleep 1 + done + + for i in {1..7}; do + touch test${test}_$i.txt + git artifact add-n-push -t test2/v${test}.$i + sleep 1 + done + + generate_git_test_log + git artifact summary >> ${root_folder}/${test}/git-test.log + + } > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; } + eval_testcase +} + +# shellcheck disable=SC2317 +function 9 { + test="${FUNCNAME[0]}" - cd ../$clone_tester_repo - git artifact fetch-co-latest -r 'v*.*' - git artifact reset - sleep 1 + testcase_synopsis="base-repo ; clone; prune dryrun and prune and list" + testcase_header + { + cd $test + generate_base_repo + sleep 1 + git artifact clone --url "$(pwd)/$remote_tester_repo" --path "$clone_tester_repo" + cd $clone_tester_repo + git artifact fetch-co-latest -g 'v*.*' + git artifact reset + + cd ../$local_tester_repo + + for i in {1..10}; do + touch test${test}_$i.txt + git artifact add-n-push -t v${test}.$i + sleep 1 + done - cd ../$local_tester_repo - touch test$test.1.txt - git artifact add-n-push -t v${test}.1 - sleep 1 + generate_git_test_log + git artifact prune --glob 'v*.*' --keep 5 --dryrun >> ${root_folder}/${test}/git-test.log + git artifact prune --glob 'v*.*' --keep 5 + git fetch origin -pP - cd ../$clone_tester_repo - git artifact fetch-co-latest --regex 'v*.*' + generate_git_test_log -} > ${test}/run.log 2>&1 || { echo "ERROR_CODE: $?"; pwd && cat ../run.log; } -eval_testcase + git artifact list --glob 'v*.*' >> ${root_folder}/${test}/git-test.log + -test="5.1" -testcase_synopsis="base-repo ; clone; find-latest pattern" -testcase_header -{ - cd $test - generate_base_repo - sleep 1 - git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo - cd $clone_tester_repo - git ls-remote origin --tags - git artifact find-latest -r 'v*.*' > ${root_folder}/${test}/git-test.log -} > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; } -eval_testcase - -test="6" -testcase_synopsis="base-repo ; clone; fetch-tags" -testcase_header -{ - cd $test - generate_base_repo - git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo - cd $clone_tester_repo - git artifact fetch-co --tag v1.0 - sha1=$(git rev-parse HEAD) - git tag -d v1.0 - git artifact fetch-tags --sha1 "$sha1" -} > ${test}/run.log 2>&1 || cat ../${test}/run.log -eval_testcase + } > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; } + eval_testcase +} +if [[ ${arg_testcase:-} == "" ]]; then + # Dynamically list and call test functions + mapfile -t test_functions < <(declare -F | awk '{print $3}' | grep -E '^[0-9]+(\.[0-9]+)?$') + + for fn in "${test_functions[@]}"; do + "$fn" + done +else + # Run a specific test case if provided + if declare -F "$arg_testcase" > /dev/null; then + "$arg_testcase" + else + echo "Test case '$arg_testcase' not found." + exit 1 + fi +fi echo echo "########################################" echo "All tests completed. Checking results..." @@ -227,7 +445,7 @@ else for log in $( find . -name run.log -o -name nok.log | sort ); do echo echo "--- $log start ------------------------" - cat $log + cat "$log" echo "--- $log end ------------------------" echo done diff --git a/git-artifact b/git-artifact index 2817dea..d9618d3 100755 --- a/git-artifact +++ b/git-artifact @@ -76,15 +76,21 @@ push push a tag add-n-push add and commit files to repo and then push them fetch-co fetch tag from remote and checkout it out reset reset workspace and branches +list list all tags in the repo given a glob pattern +summary print a summary of the tags in the repo +prune prune tags in the repo given a glob pattern and keep amount of tags find-latest Find the latest tags from reqex and print it fetch-co-latest Get latest tag form remote using grep reg-ex and reset hard to it fetch-tags Fetch all tags that points to a sha1 or HEAD - Useful in relation to detached HEAD and submodules - -- -h,help show the help +h show the help q quiet +v,verbose verbose d show debug messages + option for 'prune' +dryrun dry run - do not execute any commands ( optional for prune) + options for 'init' and 'clone' u,url= the remote url p,path= the optional path for init and clone @@ -95,11 +101,17 @@ b,branch= use branch for local changes and pushes options for 'add-n-tag', 'push', 'add-n-push', 'fetch-co' t,tag= the tag to be created - options for 'fetch-co-latest', 'find-latest' -r,regex= the reg-ex pattern to latest of + options for 'fetch-co-latest', 'find-latest', 'list', 'prune' +g,glob= the glob pattern search remote for tags options for 'fetch-tags' s,sha1= The sha1 of which to get tags from from + + options for 'prune' +k,keep= The amount of tags to keep - default is 20 + + options for 'summary' +delimiter= The delimiter to use for the summary - default is '/' " } @@ -329,10 +341,74 @@ cmd_fetch-co() { git log -1 --oneline --decorate } +cmd_prune() { + + mapfile -t tag_array < <(git ls-remote --tags --ref --sort=v:refname origin "refs/tags/${arg_glob:-*}" | cut -d / -f 3-) + + if [[ ${#tag_array[@]} -eq 0 ]]; then + echo "No tags found matching glob: ${arg_glob}" + exit 0 + fi + + tags_to_be_pruned="" + tags_amount_to_prune=$(( ${#tag_array[@]} - arg_keep )) + for ((i = 0; i < ${#tag_array[@]}; i++)); do + tag="${tag_array[$i]}" + if [[ $i -lt $tags_amount_to_prune ]]; then + [[ ${arg_verbose:-} ]] && echo "Would prune tag: $tag" + # Uncomment the next line to actually delete the tag + tags_to_be_pruned+="$tag " + else + true + #echo "Keeping tag: $tag" + fi + done + printf "Amount of tags total: %s\n" "${#tag_array[@]}" + printf "Amount of tags to be pruned: %s\n" "${tags_amount_to_prune}" + printf "Amount of tags to be kept: %s\n" "${arg_keep}" + if [[ ${arg_dryrun:-} == 1 ]] ; then + echo "Dry run - not executing prune command" + else + echo "$tags_to_be_pruned" | xargs --no-run-if-empty git push origin --delete + fi +} + +cmd_list() { + if [[ ${arg_quiet:-} -ne 1 ]]; then + git ls-remote --tags --ref --sort=v:refname origin "refs/tags/${arg_glob:-*}" | cut -d / -f 3- + fi + printf "Tags found: %s : %s\n" "${arg_glob}" "$(git ls-remote --tags --ref --sort=v:refname origin "refs/tags/${arg_glob:-*}" | wc -l)" +} + +cmd_summary() { + declare -A tags + read_remote_tags_to_map tags + echo "Summary of of amount of tags in using delimiter: ${arg_delimiter} and filter on first column" + echo "----------------------------------------------------------------------------------------" + + # print the hash map with a count of tags of each key + for k in "${!tags[@]}"; do + amount=$(echo -n "${tags[$k]}" | wc -l) + echo "$k : ${amount}" + done +} + +read_remote_tags_to_map() { + local -n _tags=${1} + + while read -r line; do + # Extract the tag name from the line + key="${line#*refs/tags/}" + key="${key%%"$arg_delimiter"*}" + info="${line#*"$arg_delimiter"}" + _tags["$key"]+="$info"$'\n' + done < <(git ls-remote --tags --ref --sort=v:refname origin refs/tags/*) +} + find-latest() { local -n _latest_tag=${1} # https://stackoverflow.com/questions/10649814/get-last-git-tag-from-a-remote-repo-without-cloning - _latest_tag=$(git ls-remote --tags --refs --sort='-version:refname' origin "refs/tags/${arg_regex}" | head -n 1 | cut -f2 | cut -d / -f3-) || { + _latest_tag=$(git ls-remote --tags --refs --sort='-version:refname' origin "refs/tags/${arg_glob}" | head -n 1 | cut -f2 | cut -d / -f3-) || { local exit_code=$? if [[ $exit_code -ne 141 ]]; then #https://unix.stackexchange.com/questions/580117/debugging-sporadic-141-shell-script-errors @@ -341,7 +417,7 @@ find-latest() { fi } if [ -z "${_latest_tag:-}" ]; then - echo "ERROR: No tag found using regex: ${arg_regex} " + echo "ERROR: No tag found using glob pattern: ${arg_glob} " exit 1 fi } @@ -376,7 +452,7 @@ cmd_fetch-tags() { main () { [[ ${debug:-} == true ]] && { - echo "debug: ${debug}" + debug "debug: ${debug}" set -x } if [[ $# -eq 0 ]] ; then @@ -390,6 +466,7 @@ main () { arg_artifacttag= arg_branch= arg_path= + arg_delimiter="/" while test $# -gt 1 do opt="$1" # command @@ -397,11 +474,17 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1 ;; + --dryrun|-dr) + arg_dryrun=1 + ;; + --verbose|-v) + arg_verbose=1 + ;; --url|-u) arg_remoteurl="$1" shift @@ -418,14 +501,26 @@ main () { arg_path="$1" shift ;; - --regex|-r) - arg_regex="$1" + --glob|-g) + arg_glob="$1" shift ;; --sha1|-s) arg_sha1="$1" shift ;; + --keep|-k) + arg_keep="$1" + if ! [[ "$arg_keep" =~ ^[0-9]+$ ]]; then + echo "INFO: --keep is not a number" + exit 1 + fi + shift + ;; + --delimiter) + arg_delimiter="$1" + shift + ;; --) ;; *) @@ -493,13 +588,27 @@ main () { . git-sh-setup require_work_tree ;; - fetch-co-latest|find-latest) + fetch-co-latest|find-latest|list) + # shellcheck source=/dev/null + . git-sh-setup + require_work_tree + if test -z "${arg_glob:-}" ; then + echo "INFO: -g|--glob is not set: Defaulting to '*' (all tags)." + arg_glob="*" + fi + ;; + summary) + # shellcheck source=/dev/null + . git-sh-setup + require_work_tree + ;; + prune) # shellcheck source=/dev/null . git-sh-setup require_work_tree - if test -z "${arg_regex:-}" ; then - echo "INFO: -r|--regex is not set: Defaulting to '*' (all tags)." - arg_regex="*" + if [[ -z "$arg_keep" ]]; then + echo "INFO: --keep is not set: Defaulting to 20" + arg_keep=20 fi ;; fetch-tags) @@ -517,7 +626,7 @@ main () { ;; esac debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {${arg_quiet:-0}}" debug "opts: {$*}" debug