]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tools: improve git-version-bump with validation and help
authorKarel Zak <kzak@redhat.com>
Mon, 22 Sep 2025 13:51:06 +0000 (15:51 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Sep 2025 13:51:24 +0000 (15:51 +0200)
- 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 <kzak@redhat.com>
tools/git-version-bump

index 3ff235552b43f5c29819520c4d319b4c4d383b1d..5cd75eff55e20718c8adee7d3b8b9a5b22e037e8 100755 (executable)
 # 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") <new-version>"
-       exit 1
-fi
+function show_help() {
+       cat <<EOF
+$(basename "$0") - update util-linux versions and release dates
+
+Usage: $(basename "$0") [OPTIONS] <new-version>
+
+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:
+  <new-version>    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") <new-version>" >&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")