diff options
| author | Danilo M. <danix@danix.xyz> | 2026-03-31 12:19:56 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-03-31 12:19:56 +0200 |
| commit | 59d70bd5f0418205f97426dd6d400adc68e91082 (patch) | |
| tree | 8a3268615cdc0630f8999c769dd576b2f0640799 /hooks/post-commit | |
| parent | d3b865ccf522114746b51ac483cd5c856512310a (diff) | |
| download | my-slackbuilds-59d70bd5f0418205f97426dd6d400adc68e91082.tar.gz my-slackbuilds-59d70bd5f0418205f97426dd6d400adc68e91082.zip | |
hooks: add pre-commit and post-commit hooks to version control
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'hooks/post-commit')
| -rwxr-xr-x | hooks/post-commit | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/hooks/post-commit b/hooks/post-commit new file mode 100755 index 0000000..9f92e3c --- /dev/null +++ b/hooks/post-commit @@ -0,0 +1,51 @@ +#!/bin/bash +# post-commit hook: create SBo submission archive for added/updated packages +set -u + +REPO_ROOT=$(git rev-parse --show-toplevel) +SBO_DIR="$REPO_ROOT/SBo" + +# Find packages whose .SlackBuild was added (A) or modified (M) in this commit. +# git diff-tree output format: <status>\t<file> +# We only want files exactly one directory deep, e.g. hugo/hugo.SlackBuild. +PACKAGES=() +while IFS=$'\t' read -r status file; do + [[ "$status" != "A" && "$status" != "M" ]] && continue + dir=$(dirname "$file") + base=$(basename "$file") + [[ "$dir" == "." ]] && continue # skip root-level files + [[ "$dir" == *"/"* ]] && continue # skip files deeper than one level + [[ "$base" == *.SlackBuild ]] || continue + PACKAGES+=("$dir") +done < <(git diff-tree --no-commit-id -r --name-status HEAD) + +[[ ${#PACKAGES[@]} -eq 0 ]] && exit 0 + +for pkg in "${PACKAGES[@]}"; do + echo "" + echo "==> Package: $pkg" + echo "" + echo "Files to be archived:" + echo "---------------------" + while IFS= read -r f; do + printf '%s\n' "${f#"$REPO_ROOT/"}" + done < <(find "$REPO_ROOT/$pkg" -type f | sort) + echo "" + printf "Create SBo archive for '%s'? [y/N] " "$pkg" + read -r answer </dev/tty + case "$answer" in + [yY]|[yY][eE][sS]) + mkdir -p "$SBO_DIR" + if tar -czf "$SBO_DIR/$pkg.tar.gz" -C "$REPO_ROOT" "$pkg"; then + echo " -> Archive created: SBo/$pkg.tar.gz" + else + echo " -> Archive FAILED." >&2 + fi + ;; + *) + echo " -> Skipped." + ;; + esac +done + +exit 0 |
