From 736f90402dd1d3fc98c8d0c5f5201c8b87d45f6e Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 29 Oct 2025 19:28:18 +0400 Subject: [PATCH] tools/semver_git_tag with --no-verify --- tools/semver_git_tag | 118 ++++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/tools/semver_git_tag b/tools/semver_git_tag index 258963b..4ccdc96 100755 --- a/tools/semver_git_tag +++ b/tools/semver_git_tag @@ -8,8 +8,7 @@ NOVERIFY=false # FUNCTIONS function usage { - echo 'usage: < --major | -M | --minor | -m | --patch | -p > [--no-verify]' - exit 1 + echo "$(dirname $0)/$(basename $0) < --major|-M | --minor|-m | --patch|-p > [--no-verify]" } function parse_options { @@ -32,13 +31,11 @@ function parse_options { NOVERIFY=true ;; --help | -h) - usage - exit 0 + usage && exit 0 ;; *) echo "Unknown option: $1" - usage - exit 2 + usage && exit 2 ;; esac @@ -46,6 +43,28 @@ function parse_options { done } +function ask_for_tag { + echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? " + read -rn1 input + echo + case "$input" in + M) + COMMAND='major' + ;; + m) + COMMAND='minor' + ;; + p) + COMMAND='patch' + ;; + *) + echo >&2 "Unknown option: $input" + exit 3 + ;; + esac + echo COMMAND=$COMMAND && exit 5 +} + function extra_options { extra="" [[ $NOVERIFY == true ]] && extra="$extra --no-verify" @@ -61,46 +80,50 @@ function assert_git_covered { } function assert_git_clean { - changed=$(git status -s | wc -l) - if [[ ! $changed -eq 0 ]]; then - echo "git commit required, please do so before processing further" + [[ -n $(git status -s) ]] && + echo >&2 "git commit required, please do so before processing further" && exit 2 +} + +function assert_git_pull { + git remote update + [[ -n $(git status -su no) ]] && + echo >&2 "git pull required, please do so before processing further" && + exit 3 +} + +function git_push { + current_branch=$(git rev-parse --abbrev-ref HEAD) + push_needed=$(git rev-list --branches --not --remotes | wc -l) + if [[ $push_needed -ne 0 ]]; then + echo 'git push needed' + git push --set-upstream origin "$current_branch" $(extra_options) + echo 'git push done' + echo '-------------' fi } -############# main +function latest_tagged_version { + LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null) + if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then + echo "LAST=${LAST_TAG}" + VERSION=$(git describe --tags $LAST_TAG) + else + echo 'not yet tagged!' + VERSION=0.0.0 + fi +} -parse_options $* +############# main assert_git_covered assert_git_clean +assert_git_pull -git remote update -pulled_needed=$(git status -s -u no | wc -l) -if [[ ! $changed -eq 0 ]]; then - echo "git pull required, please do so before processing further" - exit 3 -fi - -current_branch=$(git rev-parse --abbrev-ref HEAD) -# check if push needed before tagging -push_needed=$(git rev-list --branches --not --remotes | wc -l) -if [[ $push_needed -ne 0 ]]; then - echo 'git push needed' - git push --set-upstream origin "$current_branch" $(extra_options) - echo 'git push done' - echo '-------------' -fi - -# check latest tagged version -LAST_TAG=$(git rev-list --tags --max-count=1 2>/dev/null) -if [[ $? -eq 0 && -n "$LAST_TAG" ]]; then - echo "LAST=${LAST_TAG}" - VERSION=$(git describe --tags $LAST_TAG) -else - echo 'not yet tagged!' - VERSION=0.0.0 -fi +parse_options $* +[[ -z $COMMAND ]] && ask_for_tag +git_push +latest_tagged_version # split into array VERSION_BITS=(${VERSION//./ }) @@ -119,27 +142,6 @@ if [[ $VERSION != '0.0.0' ]]; then fi fi -if [[ -z $COMMAND ]]; then - echo -n "Press 'M' for Major, 'm' for minor, 'p' for patch ? " - read -rn1 input - echo - case "$input" in - M) - COMMAND='major' - ;; - m) - COMMAND='minor' - ;; - p) - COMMAND='patch' - ;; - *) - echo >&2 "Unknown option: $input" - exit 3 - ;; - esac -fi - case $COMMAND in "major") let "MAJOR++"