Enhance git-release script to support force flag and clarify usage instructions

This commit is contained in:
2026-01-18 13:45:20 +01:00
parent 80852cf843
commit 4bcb79a413

View File

@@ -2,20 +2,29 @@
# git-release # git-release
# https://github.com/obnitram/git-release # https://github.com/obnitram/git-release
# ------------------------------------------------- # -------------------------------------------------
# Usage: git-release [<projectname>] # Usage: git-release [<projectname>] [-f]
# Accepts tags of the form vX.Y.Z or <projectname>-vX.Y.Z (no prerelease/build). # Accepts tags of the form vX.Y.Z or <projectname>-vX.Y.Z (no prerelease/build).
# Interactively bumps patch/minor/major, creates an annotated tag, # Interactively bumps patch/minor/major, creates an annotated tag,
# and pushes it to origin. # and pushes it to origin.
# #
# Requirements: # Requirements:
# - The last tag MUST match ^v[0-9]+\.[0-9]+\.[0-9]+$ or ^<projectname>-v[0-9]+\.[0-9]+\.[0-9]+$ (or none => starts from v0.0.0) # - The last tag MUST match ^v[0-9]+\.[0-9]+\.[0-9]+$ or ^<projectname>-v[0-9]+\.[0-9]+\.[0-9]+$ (or none => starts from v0.0.0)
# - Working tree must be clean. # - Working tree must be clean (unless -f is used).
set -euo pipefail set -euo pipefail
trap 'echo "❌ ${0##*/} failed at line $LINENO." >&2; exit 1' ERR trap 'echo "❌ ${0##*/} failed at line $LINENO." >&2; exit 1' ERR
# --- Parse optional project name argument --- # --- Parse arguments ---
PROJECT_NAME="${1:-}" FORCE_FLAG=false
PROJECT_NAME=""
for arg in "$@"; do
if [[ "$arg" == "-f" ]]; then
FORCE_FLAG=true
else
PROJECT_NAME="$arg"
fi
done
if [[ -n "$PROJECT_NAME" ]]; then if [[ -n "$PROJECT_NAME" ]]; then
TAG_PREFIX="${PROJECT_NAME}-v" TAG_PREFIX="${PROJECT_NAME}-v"
TAG_PATTERN="${PROJECT_NAME}-v[0-9]*.[0-9]*.[0-9]*" TAG_PATTERN="${PROJECT_NAME}-v[0-9]*.[0-9]*.[0-9]*"
@@ -31,10 +40,13 @@ fi
# --- Safety: ensure we are inside a Git repository --- # --- Safety: ensure we are inside a Git repository ---
git rev-parse --is-inside-work-tree >/dev/null 2>&1 git rev-parse --is-inside-work-tree >/dev/null 2>&1
# --- Safety: require a clean working tree --- # --- Safety: require a clean working tree (unless -f flag is used) ---
if ! git diff-index --quiet HEAD --; then if [[ "$FORCE_FLAG" == false ]]; then
echo "⚠️ Uncommitted changes detected. Please commit or stash before releasing." if ! git diff-index --quiet HEAD --; then
exit 1 echo "⚠️ Uncommitted changes detected. Please commit or stash before releasing."
echo " Or use -f flag to force the release anyway."
exit 1
fi
fi fi
# --- Get strictly matching tags and pick the highest (lexicographic by version) --- # --- Get strictly matching tags and pick the highest (lexicographic by version) ---