config/.mutt/bin/patch_apply.sh

37 lines
803 B
Bash
Raw Normal View History

2021-11-22 14:13:25 +01:00
#!/usr/bin/env bash
# store patch
file="$(mktemp ${TMPDIR-/tmp}/mutt-patch-apply-XXXXXXXX)"
trap "rm -f $file" EXIT
cat > "$file"
# find project
#source ~/.mutt/bin/patch-find-project.sh
#if test "$project" = ""; then
# echo "ERROR: can't figure project"
# exit 1
#fi
#
## go!
#clear
#cd $HOME/projects/$project
project=$(pwd)
branch=$(git rev-parse --abbrev-ref HEAD)
clear
echo "#"
echo "# try applying patch to $project, branch $branch"
echo "#"
if git am --message-id --3way --ignore-whitespace --whitespace=fix "$file"; then
echo "#"
echo "# OK"
echo "#"
else
echo "# FAILED, cleaning up"
cp -v .git/rebase-apply/patch patch-apply-failed.diff
cp -v "$file" patch-apply-failed.mail
git am --abort
git reset --hard
fi