aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgit-format-named-patches.sh17
1 files changed, 13 insertions, 4 deletions
diff --git a/git-format-named-patches.sh b/git-format-named-patches.sh
index 4cdcb4e..db34943 100755
--- a/git-format-named-patches.sh
+++ b/git-format-named-patches.sh
@@ -32,16 +32,25 @@ done
# Shift past the last option parsed by getopts
shift $((OPTIND-1))
-[ "$#" -lt 1 ] && exit 64
+if [ "$#" -lt 1 ] ; then
+ INTEREST="HEAD~..HEAD"
+else
+ INTEREST="$1"
+fi
[ $CLEAN -eq 1 ] && [ -n "$SUBDIR" ] && rm -fv "$SUBDIR/*.patch"
-IDSstr="$(git log --format="%H" "$1" 2>/dev/null)"
+IDSstr="$(git log --format="%H" "$INTEREST" 2>/dev/null | tac)"
mapfile -t IDS <<< "$IDSstr"
for id in "${IDS[@]}" ; do
PATCH="$(git format-patch -1 --stdout "${id}")"
FN="$(echo "$PATCH" | git interpret-trailers --parse | awk '/^Patch: / {print $2}')"
[ -z "$FN" ] && fail "Patch filename not defined"
- [ -n "$SUBDIR" ] && FN="$(readlink -f "$SUBDIR"/"$FN")"
- printf "%s" "$PATCH" > "$FN"
+ if [ -n "$SUBDIR" ] ; then
+ FFN="$(readlink -f "$SUBDIR"/"$FN")"
+ else
+ FFN="$FN"
+ fi
+ printf "%s\n" "$PATCH" > "$FFN"
+ printf "%s\n" "$FN"
done