aboutsummaryrefslogtreecommitdiffstats
path: root/git-format-named-patches.sh
blob: e311f5f289a4324ce8758dcae5d8a156eec51af3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

set -eu

fail() {
    printf "%s\n" "$1" >>/dev/stderr
    exit 32
}

[ "$#" -lt 1 ] && exit 64

IDSstr="$(git log --format="%H" "$1" 2>/dev/null)"
mapfile -t IDS <<< "$IDSstr"
for id in "${IDS[@]}" ; do
    PATCH="$(git format-patch -1 --stdout "${id}")"
    FN="$(echo "$PATCH" | awk '/^Patch: / {print $2}')"
    [ -z "$FN" ] && fail "Patch filename not defined"
    printf "%s" "$PATCH" > "$FN"
done