github-merge-pr: fix loading .config if symbolic link is used
[maintainer-tools.git] / sob2from.sh
1 #!/bin/bash
2
3 git filter-branch -f --tag-name-filter cat --commit-filter '
4 MESSAGE="$(git show --format=%B "$GIT_COMMIT")"
5 SOB_LINE="$(echo "$MESSAGE" | sed -ne "s|^ *Signed-off-by: *||p" | head -n1)"
6 SOB_AUTHOR="$(echo "$SOB_LINE" | sed -e "s|^\(.*\) <.*>\$|\\1|")"
7 SOB_EMAIL="$(echo "$SOB_LINE" | sed -e "s|^.* <\(.*\)>\$|\\1|")"
8
9 if [ -n "$SOB_AUTHOR" -a -n "$SOB_EMAIL" ] && \
10 [ "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" != "$SOB_AUTHOR <$SOB_EMAIL>" ] && \
11 ! echo "$MESSAGE" | grep -sqE "^ *Signed-off-by: *$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"; then
12 printf "\nRewrite $GIT_COMMIT: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> => $SOB_AUTHOR <$SOB_EMAIL>\n" >&2
13 export GIT_AUTHOR_NAME="$SOB_AUTHOR"
14 export GIT_AUTHOR_EMAIL="$SOB_EMAIL"
15 fi
16
17 git commit-tree "$@"
18
19 ' -- "${1:-HEAD~1..HEAD}"
20
21 git for-each-ref --format="%(refname)" refs/original/ | xargs -r -n 1 git update-ref -d