Skip to content

Commit 312da29

Browse files
committed
git-reauthor: add a mode to handle SIGNOFF=true
1 parent b6002d1 commit 312da29

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ commits in your branch, changing to `$COMMIT_USER_NAME <$COMMIT_USER_EMAIL>`
5858
and optionally filtering to only change commits originally owned by matches
5959
to regex `$COMMIT_USER_FILTER`. Intended to fix up code initially developed
6060
and tested "in vivo" on final deployments without proper git setup attributing
61-
changes to certain persons.
61+
changes to certain persons. With a `SIGNOFF=true` can also be used to add
62+
(or replace in case of filter) a `Signed-off-by: User Name <email@domain>`
63+
to the commit message (for stating the DCO compliance).
6264

6365
# Other related automation scripts
6466

git-reauthor

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PREV=1
1010
[ -n "$COMMIT_USER_NAME" ] || { echo "COMMIT_USER_NAME or proper git config is required" >&2 ; exit 1; }
1111
[ -n "$COMMIT_USER_EMAIL" ] || COMMIT_USER_EMAIL="`git config user.email || git config --global user.email`"
1212
[ -n "$COMMIT_USER_EMAIL" ] || { echo "COMMIT_USER_EMAIL or proper git config is required" >&2 ; exit 1; }
13+
[ "$SIGNOFF" = true ] || SIGNOFF=false
1314
INITLOG="`git log -1`"
1415

1516
[ -n "$GSED" ] || {
@@ -56,6 +57,21 @@ while [ "$PREV" -le "$BACK" ] ; do
5657
if $DO_AMEND ; then
5758
echo "=== NEW USER: $ANEW"
5859
git commit --amend --no-edit --author "$ANEW"
60+
61+
62+
if $SIGNOFF ; then
63+
if git log -1 | grep "Signed-off-by: $ANEW" > /dev/null ; then
64+
echo "===== ALREADY Signed-off-by: $ANEW" # no-op
65+
else
66+
echo "===== NEW SIGNATURE: Signed-off-by: $ANEW"
67+
if [ -n "$COMMIT_USER_FILTER" ]; then (
68+
GIT_EDITOR="$GSED -e '/^Signed-off-by: '"$COMMIT_USER_FILTER"'\$/d' < \$1 > \$1.tmp && mv \$1.tmp \$1 ; : " \
69+
git commit --amend --author "$ANEW" -s
70+
) ; else
71+
git commit --amend --no-edit --author "$ANEW" -s
72+
fi
73+
fi
74+
fi
5975
fi
6076

6177
echo "=== RESULT LOG:"

0 commit comments

Comments
 (0)