#!/bin/sh patch_name_from_fname() { echo $1 | cut -d- -f2 } apply_patch() { branch="$1" echo "" git checkout -b $branch cd .. > /dev/null patch -p1 < patches/$1 || exit 1 # git apply --reject patches/$1 || exit 1 git add *.c *.h *.mk *.1 cd - > /dev/null git commit -m "Applied $1" return 0 } git switch "patches" || exit git reset --hard "patches" -- || exit git clean -fd "../" # branches for individually applied patches branches=$(git for-each-ref --format='%(refname:short)' refs/heads/ | grep diff) for branch in $branches; do git branch -D $branch || exit done # branc with merged patches git branch -D patched git status for patchfile in *.diff; do git switch -q "patches" apply_patch "$patchfile" || (git switch "patches" && exit) done git checkout -b "patched" echo "Merge patch branches manually now"