sob2from.sh: don't fail on author names with single quotes
authorJo-Philipp Wich <jo@mein.io>
Sun, 4 Nov 2018 14:02:45 +0000 (15:02 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 6 Mar 2020 11:28:41 +0000 (12:28 +0100)
Also only rewrite the author if the existing commit author does not appear
in any Signed-off-by line.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
sob2from.sh

index 66063447e76a46630c58f2202dccb36182a17a5d..12cca27f48f9bccbd2d0e6cb7fcb539d6bddaa82 100755 (executable)
@@ -1,11 +1,15 @@
 #!/bin/bash
 
 git filter-branch -f --tag-name-filter cat --commit-filter '
+       MESSAGE="$(git show --format=%B "$GIT_COMMIT")"
+       SOB_LINE="$(echo "$MESSAGE" | sed -ne "s|^ *Signed-off-by: *||p" | head -n1)"
+       SOB_AUTHOR="$(echo "$SOB_LINE" | sed -e "s|^\(.*\) <.*>\$|\\1|")"
+       SOB_EMAIL="$(echo "$SOB_LINE" | sed -e "s|^.* <\(.*\)>\$|\\1|")"
 
-       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
+       if [ -n "$SOB_AUTHOR" -a -n "$SOB_EMAIL" ] && \
+          [ "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" != "$SOB_AUTHOR <$SOB_EMAIL>" ] && \
+          ! echo "$MESSAGE" | grep -sqE "^ *Signed-off-by: *$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"; then
+               printf "\nRewrite $GIT_COMMIT: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> => $SOB_AUTHOR <$SOB_EMAIL>\n" >&2
                export GIT_AUTHOR_NAME="$SOB_AUTHOR"
                export GIT_AUTHOR_EMAIL="$SOB_EMAIL"
        fi