Compare commits
5 commits
d1ccf0e1d4
...
f80c534323
Author | SHA1 | Date | |
---|---|---|---|
ptrcnull | f80c534323 | ||
ptrcnull | 4e824d06f5 | ||
ptrcnull | a85bf4c080 | ||
ptrcnull | 833280f1a9 | ||
ptrcnull | 00d7fdace6 |
99
apatch
99
apatch
|
@ -1,12 +1,43 @@
|
|||
#!/bin/sh
|
||||
|
||||
startdir="$PWD"
|
||||
# output functions from abuild/functions.sh
|
||||
NORMAL="\033[1;0m"
|
||||
STRONG="\033[1;1m"
|
||||
RED="\033[1;31m"
|
||||
GREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
BLUE="\033[1;34m"
|
||||
|
||||
[ -f APKBUILD ] || ( echo "please run this in a package directory"; exit 1 )
|
||||
[ "$1" != "" ] || ( echo "usage: apatch <patch name>"; exit 1 )
|
||||
_prefix="${BLUE}${STRONG}apatch${NORMAL}:"
|
||||
|
||||
msg() {
|
||||
local prompt="$GREEN>>> ${_prefix}"
|
||||
printf "${prompt} %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
warning() {
|
||||
local prompt="${YELLOW}>>> WARNING: ${_prefix}"
|
||||
printf "${prompt} %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
error() {
|
||||
local prompt="${RED}>>> ERROR: ${_prefix}"
|
||||
printf "${prompt} %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
if [ ! -f APKBUILD ]; then
|
||||
error "please run this in a package directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
echo "usage: apatch <patch name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
msg "running abuild"
|
||||
abuild clean fetch unpack default_prepare
|
||||
|
||||
# obtain builddir
|
||||
|
@ -23,6 +54,7 @@ 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
|
||||
(
|
||||
msg "reversing $patch"
|
||||
cd "$builddir"
|
||||
patch -R -p1 < "$patchpath"
|
||||
)
|
||||
|
@ -30,33 +62,54 @@ for patch in $source; do
|
|||
fi
|
||||
done
|
||||
|
||||
header=""
|
||||
if [ -f "$patch" ]; then
|
||||
msg "patch exists, trying to extract existing message"
|
||||
# try to extract the original header from the patch
|
||||
patch_start=$(grep -En '^(diff --git|--- )' "$patchpath" | cut -d: -f1 | head -n 1)
|
||||
header="$(head -n $(( patch_start - 1 )) "$patchpath"; echo)"
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$builddir"
|
||||
git init
|
||||
git add .
|
||||
git commit -m "$pkgver" >/dev/null
|
||||
cd "$builddir"
|
||||
git init
|
||||
git add .
|
||||
git commit -m "$pkgver" >/dev/null
|
||||
|
||||
# if file exists, try to apply
|
||||
if [ -e "$patchpath" ]; then
|
||||
git apply --reject --whitespace=fix "$patchpath" || {
|
||||
git status --porcelain | grep '\?\? .*\.rej$' | cut -c4- | while read -r reject; do
|
||||
target="${reject%.rej}"
|
||||
echo "[*] trying to wiggle $target"
|
||||
wiggle --merge --replace "$target" "$reject" || {
|
||||
echo "[!] could not merge $target, fix manually"
|
||||
}
|
||||
rm "$reject"
|
||||
rm "$target.porig" # left by wiggle
|
||||
done
|
||||
rejects="$(git status --porcelain | grep '\?\? .*\.rej$' | cut -c4-)"
|
||||
if [ -n "$rejects" ]; then
|
||||
warning "$patch partially applied with rejects"
|
||||
for reject in $rejects; do
|
||||
target="${reject%.rej}"
|
||||
msg "trying to wiggle $target"
|
||||
wiggle --merge --replace "$target" "$reject" || {
|
||||
warning "could not merge $target, fix manually"
|
||||
}
|
||||
rm "$reject"
|
||||
rm "$target.porig" # left by wiggle
|
||||
done
|
||||
else
|
||||
warning "$patch failed to apply"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
msg "you can edit now!"
|
||||
|
||||
$SHELL
|
||||
$SHELL || true
|
||||
|
||||
git add .
|
||||
git diff --cached > "$patchpath"
|
||||
if [ ! -s "$patchpath" ]; then
|
||||
echo "[*] patch is empty, removing"
|
||||
rm "$patchpath"
|
||||
fi
|
||||
git add .
|
||||
|
||||
msg "saving patch $patch"
|
||||
echo -n "$header" > "$patchpath"
|
||||
git diff --cached >> "$patchpath"
|
||||
|
||||
if [ ! -s "$patchpath" ]; then
|
||||
msg "patch is empty, removing"
|
||||
rm "$patchpath"
|
||||
fi
|
||||
|
||||
rm -rf .git
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue