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
|
#!/bin/sh
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
rm -rf src-old
|
|
||||||
}
|
|
||||||
|
|
||||||
trap 'cleanup' EXIT INT HUP
|
|
||||||
|
|
||||||
startdir="$PWD"
|
startdir="$PWD"
|
||||||
|
|
||||||
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
|
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
|
||||||
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; 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
|
# obtain builddir
|
||||||
|
startdir="$PWD"
|
||||||
|
srcdir="$startdir/src"
|
||||||
. APKBUILD
|
. 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
|
for patch in $source; do
|
||||||
if [ "$patch" = "$1" ]; then
|
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
|
# but we want the original src to not have it, so we can get a full diff of
|
||||||
# its original changes + our new ones
|
# its original changes + our new ones
|
||||||
(
|
(
|
||||||
cd "src-old/$builddir"
|
cd "$builddir"
|
||||||
patch -R -p1 < "$startdir/$1"
|
patch -R -p1 < "$patchpath"
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
(
|
(
|
||||||
cd "src$builddir"
|
cd "$builddir"
|
||||||
$SHELL
|
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