No behaviour change. Explicit `cd || die` (set -e already covered it), split declare/assign for PROTOC, if-blocks instead of `A && B || C`, and array-length instead of a counter loop in count_patches. The lib.sh constants get disable=SC2034 since they are consumed by the scripts that source it, which shellcheck cannot see per-file. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
50 lines
1.6 KiB
Bash
Executable File
50 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Export every commit in work/ above the `base` tag back into patches/.
|
|
#
|
|
# This is the CraftBukkit/Spigot `rebuildPatches.sh` step and the only way
|
|
# changes leave work/. Run it after every commit you make in work/.
|
|
|
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
|
|
|
assert_work_ready
|
|
cd "$WORK_DIR" || die "cannot enter $WORK_DIR"
|
|
|
|
if [[ -n "$(git status --porcelain)" ]]; then
|
|
warn "work/ has uncommitted changes -- they will NOT be exported."
|
|
warn "Commit them first: cd work && git add -A && git commit"
|
|
fi
|
|
|
|
n="$(git rev-list --count "$BASE_TAG..HEAD")"
|
|
info "Exporting $n commit(s) above $BASE_TAG -> patches/"
|
|
|
|
mkdir -p "$PATCHES_DIR"
|
|
# Clear first: dropping or reordering commits in work/ must not leave orphaned
|
|
# patch files behind, and format-patch only ever writes, never deletes.
|
|
rm -f "$PATCHES_DIR"/*.patch
|
|
|
|
if [[ "$n" -eq 0 ]]; then
|
|
info "No commits above $BASE_TAG -- patches/ is now empty."
|
|
exit 0
|
|
fi
|
|
|
|
# --zero-commit the "From <sha>" line would otherwise change on every single
|
|
# rebase, producing a diff in every patch file for no reason
|
|
# --full-index full blob hashes give `git am --3way` something to fall back
|
|
# on when context has drifted
|
|
# --no-signature drops the trailing "-- \n2.47.3" git version banner
|
|
# --no-stat / -N match Spigot's output shape (no diffstat, no "[PATCH n/m]")
|
|
git format-patch \
|
|
--quiet \
|
|
--no-stat \
|
|
-N \
|
|
--zero-commit \
|
|
--full-index \
|
|
--no-signature \
|
|
--output-directory "$PATCHES_DIR" \
|
|
"$BASE_TAG"
|
|
|
|
info "patches/ now holds $(count_patches) patch file(s):"
|
|
for f in "$PATCHES_DIR"/*.patch; do
|
|
printf ' %s\n' "$(basename "$f")"
|
|
done
|