add a script to rewrite the commit author to reflect whats in Signed-off-by
authorJo-Philipp Wich <jo@mein.io>
Sat, 23 Dec 2017 11:03:19 +0000 (12:03 +0100)
committerJonas Gorski <jonas.gorski@gmail.com>
Sat, 23 Dec 2017 11:13:48 +0000 (12:13 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
sob2from.sh [new file with mode: 0755]

diff --git a/sob2from.sh b/sob2from.sh
new file mode 100755 (executable)
index 0000000..6606344
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+git filter-branch -f --tag-name-filter cat --commit-filter '
+
+       eval $(git show --format=%B "$GIT_COMMIT" | sed -ne "s|Signed-off-by: \(.*\) <\(.*\)>$|SOB_AUTHOR='"'"'\\1'"'"'; SOB_EMAIL='"'"'\\2'"'"'|p" | head -n1)
+
+       if [ -n "$SOB_AUTHOR" -a -n "$SOB_EMAIL" -a "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" != "$SOB_AUTHOR <$SOB_EMAIL>" ]; then
+               echo -e "\nRewrite $GIT_COMMIT: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> => $SOB_AUTHOR <$SOB_EMAIL>" >&2
+               export GIT_AUTHOR_NAME="$SOB_AUTHOR"
+               export GIT_AUTHOR_EMAIL="$SOB_EMAIL"
+       fi
+
+       git commit-tree "$@"
+
+' -- "${1:-HEAD~1..HEAD}"
+
+git for-each-ref --format="%(refname)" refs/original/ | xargs -r -n 1 git update-ref -d