Files
Modrinth-Enhanced/scripts/export-patches.sh
T

34 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerate patches/ from the commits in build/upstream.
#
# Run this after changing anything in the patched checkout: every commit on top
# of the upstream tag becomes one patch file, and patch files that no longer
# have a commit behind them are deleted.
. "$(dirname "${BASH_SOURCE[0]}")/common.sh"
require_worktree
if [ -n "$(git -C "$WORKTREE" status --porcelain)" ]; then
die "$WORKTREE has uncommitted changes. Commit them first: each commit becomes one patch."
fi
count="$(git -C "$WORKTREE" rev-list --count "$UPSTREAM_REF..HEAD")"
[ "$count" -gt 0 ] || die "No commits on top of $UPSTREAM_REF to export."
log "Exporting $count patches"
rm -f "$PATCH_DIR"/*.patch
git -C "$WORKTREE" format-patch \
--binary \
--zero-commit \
--no-signature \
--no-numbered \
--output-directory "$PATCH_DIR" \
"$UPSTREAM_REF..HEAD"
# So that prepare.sh applies them where they fit and rebases from there.
printf '%s\n' "$UPSTREAM_REF" >"$PATCH_DIR/base.txt"
log "patches/ now contains:"
ls -1 "$PATCH_DIR"