From: Karel Zak Date: Mon, 22 Sep 2025 13:51:06 +0000 (+0200) Subject: tools: improve git-version-bump with validation and help X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=53a8e762fc58574d453c07edc262e9f613cabf9d;p=thirdparty%2Futil-linux.git tools: improve git-version-bump with validation and help - Add --help option with usage information - Validate script runs only on stable/vX.Y branches - Validate version format (X.Y, X.Y.Z, X.Y-rcN, X.Y.Z-rcN) Signed-off-by: Karel Zak --- diff --git a/tools/git-version-bump b/tools/git-version-bump index 3ff235552..5cd75eff5 100755 --- a/tools/git-version-bump +++ b/tools/git-version-bump @@ -12,18 +12,83 @@ # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -VERSION="$1" -if [ -z "$VERSION" ]; then - echo "$(basename "$0") " - exit 1 -fi +function show_help() { + cat < + +This script updates NEWS file and release dates in configure.ac and meson.build +for a new util-linux release. It must be run from a stable/vX.Y branch. + +Arguments: + Version in format X.Y, X.Y.Z, X.Y-rcN, or X.Y.Z-rcN + +Options: + -h, --help Show this help message + +EOF +} + +function validate_version() { + local version="$1" + # Valid formats: X.Y, X.Y.Z, X.Y-rcN, X.Y.Z-rcN + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?(-rc[0-9]+)?$ ]]; then + echo "Error: Invalid version format '$version'" >&2 + echo "Valid formats: X.Y, X.Y.Z, X.Y-rcN, X.Y.Z-rcN" >&2 + return 1 + fi + return 0 +} + +function validate_branch() { + local current_branch + current_branch=$(git branch --show-current) + + if [[ ! "$current_branch" =~ ^stable/v[0-9]+\.[0-9]+$ ]]; then + echo "Error: This script must be run from a stable/vX.Y branch" >&2 + echo "Current branch: $current_branch" >&2 + return 1 + fi + return 0 +} + +# Parse arguments +case "$1" in + -h|--help) + show_help + exit 0 + ;; + -*) + echo "Error: Unknown option '$1'" >&2 + echo "Use --help for usage information." >&2 + exit 1 + ;; + "") + echo "Error: Missing version argument" >&2 + echo "Usage: $(basename "$0") " >&2 + echo "Use --help for more information." >&2 + exit 1 + ;; + *) + VERSION="$1" + ;; +esac + +# Verify we're in a Git repository git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { echo "Error: Not inside a Git repository." >&2 exit 1 } +# Validate version format +validate_version "$VERSION" || exit 1 + +# Validate branch +validate_branch || exit 1 + function bump_news_version { local version="$1" local date=$(date +"%b %d %Y")