fix: work around trailing newlines in headers

ugh
This commit is contained in:
ptrcnull 2022-07-30 06:18:01 +02:00
parent 4c668b6c04
commit aeae707886

8
apatch
View file

@ -67,7 +67,8 @@ if [ -f "$patchpath" ]; then
msg "patch exists, trying to extract existing message" msg "patch exists, trying to extract existing message"
# try to extract the original header from the patch # try to extract the original header from the patch
patch_start=$(grep -En '^(diff --git|--- )' "$patchpath" | cut -d: -f1 | head -n 1) patch_start=$(grep -En '^(diff --git|--- )' "$patchpath" | cut -d: -f1 | head -n 1)
header="$(head -n $(( patch_start - 1 )) "$patchpath"; echo)" header_file="$(mktemp -t apatch.XXXXXX)"
head -n $(( patch_start - 1 )) "$patchpath" > "$header_file"
fi fi
( (
@ -103,7 +104,10 @@ fi
git add . git add .
msg "saving patch $1" msg "saving patch $1"
echo -n "$header" > "$patchpath" echo -n > "$patchpath" # empty the file first
if [ -n "$header_file" ]; then
mv "$header_file" "$patchpath"
fi
git diff --cached >> "$patchpath" git diff --cached >> "$patchpath"
if [ ! -s "$patchpath" ]; then if [ ! -s "$patchpath" ]; then