feat: use git repo instead of arbitrary directories and busybox diff #9
1 changed files with 36 additions and 15 deletions
51
apatch
51
apatch
|
@ -1,23 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
cleanup() {
|
||||
rm -rf src-old
|
||||
}
|
||||
|
||||
trap 'cleanup' EXIT INT HUP
|
||||
|
||||
startdir="$PWD"
|
||||
|
||||
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
|
||||
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 )
|
||||
|
||||
abuild clean fetch unpack prepare || exit 1
|
||||
set -e
|
||||
|
||||
abuild clean fetch unpack default_prepare
|
||||
|
||||
# obtain builddir
|
||||
startdir="$PWD"
|
||||
srcdir="$startdir/src"
|
||||
. APKBUILD
|
||||
[ -z "$builddir" ] && builddir="/$pkgname-$pkgver"
|
||||
test -n "$builddir" || builddir="$srcdir/$pkgname-$pkgver"
|
||||
|
||||
cp -r src src-old
|
||||
patchpath="$startdir/$1"
|
||||
|
||||
for patch in $source; do
|
||||
if [ "$patch" = "$1" ]; then
|
||||
|
@ -25,16 +23,39 @@ for patch in $source; do
|
|||
# but we want the original src to not have it, so we can get a full diff of
|
||||
# its original changes + our new ones
|
||||
(
|
||||
cd "src-old/$builddir"
|
||||
patch -R -p1 < "$startdir/$1"
|
||||
cd "$builddir"
|
||||
patch -R -p1 < "$patchpath"
|
||||
)
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
(
|
||||
cd "src$builddir"
|
||||
$SHELL
|
||||
)
|
||||
cd "$builddir"
|
||||
git init
|
||||
git add .
|
||||
git commit -m "$pkgver" >/dev/null
|
||||
|
||||
busybox diff -N -U3 -r "src-old$builddir" "src$builddir" | sed "s|src-old$builddir|a|g;s|src$builddir|b|g" > $1
|
||||
# if file exists, try to apply
|
||||
if [ -e "$patchpath" ]; then
|
||||
git apply --reject --quiet --whitespace=fix "$patchpath" || {
|
||||
git status --porcelain | grep '\?\? .*\.rej$' | cut -c4- | while read -r reject; do
|
||||
target="${reject%.rej}"
|
||||
wiggle --merge --replace "$target" "$reject" || {
|
||||
echo "[!] could not merge $target, fix manually"
|
||||
ptrcnull marked this conversation as resolved
|
||||
}
|
||||
rm "$reject"
|
||||
rm "$target.porig" # left by wiggle
|
||||
done
|
||||
}
|
||||
ptrcnull marked this conversation as resolved
Outdated
psykose
commented
wat wat
|
||||
fi
|
||||
|
||||
$SHELL
|
||||
|
||||
git add .
|
||||
git diff --cached > "$patchpath"
|
||||
if [ ! -s "$patchpath" ]; then
|
||||
echo "[*] patch is empty, removing"
|
||||
rm "$patchpath"
|
||||
fi
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue
spaces are evil, use tabs
yes i love you too darling