2022-04-25 19:16:04 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-04-29 06:24:06 +00:00
|
|
|
startdir="$PWD"
|
|
|
|
|
2022-04-25 19:16:04 +00:00
|
|
|
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
|
|
|
|
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 )
|
|
|
|
|
2022-07-25 05:07:38 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
abuild clean fetch unpack default_prepare
|
2022-04-25 19:16:04 +00:00
|
|
|
|
|
|
|
# obtain builddir
|
2022-07-25 05:07:38 +00:00
|
|
|
startdir="$PWD"
|
|
|
|
srcdir="$startdir/src"
|
2022-04-25 19:16:04 +00:00
|
|
|
. APKBUILD
|
2022-07-25 05:07:38 +00:00
|
|
|
test -n "$builddir" || builddir="$srcdir/$pkgname-$pkgver"
|
2022-04-25 19:16:04 +00:00
|
|
|
|
2022-07-25 05:07:38 +00:00
|
|
|
patchpath="$startdir/$1"
|
2022-04-29 06:49:13 +00:00
|
|
|
|
|
|
|
for patch in $source; do
|
|
|
|
if [ "$patch" = "$1" ]; then
|
|
|
|
# if the patch was in source, it was already applied in prepare() above,
|
|
|
|
# but we want the original src to not have it, so we can get a full diff of
|
|
|
|
# its original changes + our new ones
|
|
|
|
(
|
2022-07-25 05:07:38 +00:00
|
|
|
cd "$builddir"
|
|
|
|
patch -R -p1 < "$patchpath"
|
2022-04-29 06:49:13 +00:00
|
|
|
)
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-04-25 19:16:04 +00:00
|
|
|
(
|
2022-07-25 05:07:38 +00:00
|
|
|
cd "$builddir"
|
|
|
|
git init
|
|
|
|
git add .
|
|
|
|
git commit -m "$pkgver" >/dev/null
|
|
|
|
|
|
|
|
# if file exists, try to apply
|
|
|
|
if [ -e "$patchpath" ]; then
|
2022-07-25 05:42:34 +00:00
|
|
|
git apply --reject --whitespace=fix "$patchpath" || {
|
2022-07-25 05:07:38 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
rm "$reject"
|
|
|
|
rm "$target.porig" # left by wiggle
|
|
|
|
done
|
|
|
|
}
|
|
|
|
fi
|
2022-04-29 06:49:13 +00:00
|
|
|
|
2022-07-25 05:07:38 +00:00
|
|
|
$SHELL
|
|
|
|
|
|
|
|
git add .
|
|
|
|
git diff --cached > "$patchpath"
|
|
|
|
if [ ! -s "$patchpath" ]; then
|
|
|
|
echo "[*] patch is empty, removing"
|
|
|
|
rm "$patchpath"
|
|
|
|
fi
|
|
|
|
)
|