feat: keep original patch headers

This commit is contained in:
ptrcnull 2022-07-30 02:39:32 +02:00
parent 833280f1a9
commit a85bf4c080

18
apatch
View file

@ -62,6 +62,14 @@ 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
@ -86,9 +94,15 @@ done
$SHELL
git add .
git diff --cached > "$patchpath"
msg "saving patch $patch"
echo -n "$header" > "$patchpath"
git diff --cached >> "$patchpath"
if [ ! -s "$patchpath" ]; then
echo "[*] patch is empty, removing"
msg "patch is empty, removing"
rm "$patchpath"
fi
rm -rf .git
)