#!/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 " 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