aboutsummaryrefslogtreecommitdiffstats
path: root/git-format-named-patches.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-04-04 09:42:21 +0200
committerMatěj Cepl <mcepl@cepl.eu>2024-10-07 11:02:08 +0200
commitb199083197af6d404f9cab31658ae243caedea65 (patch)
tree71fe62e14c5e5036ddb5475eb997ce07adce5842 /git-format-named-patches.sh
parent8d6e7bbc72f245aa51c966178f60dd5d5e3d4091 (diff)
downloadgosc-b199083197af6d404f9cab31658ae243caedea65.tar.gz
feat(git-format-named-patches): POC for the script.
Just runs individual commits through `git format-patch(1)` and saves them in the named patch files.
Diffstat (limited to 'git-format-named-patches.sh')
-rwxr-xr-xgit-format-named-patches.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/git-format-named-patches.sh b/git-format-named-patches.sh
new file mode 100755
index 0000000..e311f5f
--- /dev/null
+++ b/git-format-named-patches.sh
@@ -0,0 +1,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