commit:     9f3ab7cf9c54ad3f582e55a21abee80910f89c1f
Author:     Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz>
AuthorDate: Wed Dec 10 15:42:46 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jan  8 10:49:45 2026 +0000
URL:        https://gitweb.gentoo.org/proj/pram.git/commit/?id=9f3ab7cf

Deduplicate signed-off-by trailers

Instead of having "git am" add signoffs, use git-intepret-trailers(1)
to add them as it can figure out not to duplicate the trailers.

Closes: https://github.com/gentoo/pram/issues/6
Signed-off-by: Thomas Bracht Laumann Jespersen <t <AT> laumann.xyz>
Part-of: https://github.com/gentoo/pram/pull/17
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 meson.build                |   2 +
 pram                       |  16 +++++-
 test/01signoff-multiple.sh | 123 +++++++++++++++++++++++++++++++++++++++++++++
 test/12signoff-dedup.sh    |  67 ++++++++++++++++++++++++
 4 files changed, 207 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 04c7adf..dbc9f2d 100644
--- a/meson.build
+++ b/meson.build
@@ -14,6 +14,7 @@ tests = [
   '01signoff-missing',
   '01signoff-partial',
   '01signoff-present',
+  '01signoff-multiple',
   '02bug-number',
   '02bug-url',
   '02closes-number',
@@ -31,6 +32,7 @@ tests = [
   '10threeway-disabled',
   '11combined-partof-signoff-bug',
   '11partof',
+  '12signoff-dedup',
 ]
 
 foreach t : tests

diff --git a/pram b/pram
index 2547862..7ceb710 100755
--- a/pram
+++ b/pram
@@ -408,6 +408,20 @@ main() {
                        add_trailer "${patches[-1]}" "${trailer}: ${to_close}"
                fi
        fi
+       # Append committer signed-off-by (only if missing)
+       if [[ -n ${signoff} ]]; then
+               local username="$(git config user.name)"
+               local useremail="$(git config user.email)"
+               local my_gitconf=(
+                       -c trailer.sign.key="Signed-off-by: "
+                       -c trailer.sign.ifmissing=add
+                       -c trailer.sign.ifexists=addIfDifferent
+               )
+
+               git "${my_gitconf[@]}" interpret-trailers --in-place \
+                       --trailer="sign: $username <$useremail>" 
"${patches[@]}" ||
+                               die "Adding Signed-off-by trailers failed"
+       fi
 
        # concatenate the patches back
        cat "${patches[@]}" > "${tempdir}/all.patch" ||
@@ -438,7 +452,7 @@ main() {
                        esac
                done
        fi
-       git am --keep-cr -3 ${signoff:+-s} ${gpgsign:+-S} "${am_options[@]}" \
+       git am --keep-cr -3 ${gpgsign:+-S} "${am_options[@]}" \
                        "${tempdir}/all.patch" || die "git am failed"
 }
 

diff --git a/test/01signoff-multiple.sh b/test/01signoff-multiple.sh
new file mode 100755
index 0000000..0e7e6ea
--- /dev/null
+++ b/test/01signoff-multiple.sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+# Test whether multiple commits are signed-off properly. One of them
+# already has the trailer, so it shouldn't be duplicated.
+
+set -e -x
+
+. ./common-setup.sh
+
+cat > three-commits.patch <<-EOF
+       From 243f5779c2ae9b0d117829b60fe7dbc466e968c0 Mon Sep 17 00:00:00 2001
+       From: Other person <[email protected]>
+       Date: Sat, 1 Jan 2000 00:00:00 +0000
+       Subject: [PATCH 1/3] First patch
+
+       Signed-off-by: Other person <[email protected]>
+
+       ---
+        data.txt | 2 +-
+        1 file changed, 1 insertion(+), 1 deletion(-)
+
+       diff --git a/data.txt b/data.txt
+       index 5baade6..a9a301d 100644
+       --- a/data.txt
+       +++ b/data.txt
+       @@ -1,6 +1,6 @@
+        This is some initial data.
+
+       -001100
+       +001101
+        010010
+        011110
+        100001
+       --
+       2.49.0
+
+       From 7aab19414dd17546985fd7c0091e779944e8f0df Mon Sep 17 00:00:00 2001
+       From: Other person <[email protected]>
+       Date: Sat, 1 Jan 2000 00:00:00 +0000
+       Subject: [PATCH 2/3] Second patch
+
+       Signed-off-by: Other person <[email protected]>
+       Signed-off-by: PRam test <[email protected]>
+
+       ---
+        data.txt | 2 +-
+        1 file changed, 1 insertion(+), 1 deletion(-)
+
+       diff --git a/data.txt b/data.txt
+       index a9a301d..237b5ef 100644
+       --- a/data.txt
+       +++ b/data.txt
+       @@ -1,7 +1,7 @@
+        This is some initial data.
+
+        001101
+       -010010
+       +010011
+        011110
+        100001
+        101101
+       --
+       2.49.0
+
+       From 8be43d8aa258fd2c2cf25ec540d19ab6a25d4038 Mon Sep 17 00:00:00 2001
+       From: Other person <[email protected]>
+       Date: Sat, 1 Jan 2000 00:00:00 +0000
+       Subject: [PATCH 3/3] Third patch
+
+       Signed-off-by: Other person <[email protected]>
+
+       ---
+        data.txt | 2 +-
+        1 file changed, 1 insertion(+), 1 deletion(-)
+
+       diff --git a/data.txt b/data.txt
+       index 237b5ef..6ba7c31 100644
+       --- a/data.txt
+       +++ b/data.txt
+       @@ -3,6 +3,6 @@ This is some initial data.
+        001101
+        010011
+        011110
+       -100001
+       +101101
+        101101
+        110011
+       --
+       2.49.0
+EOF
+
+bash "${INITDIR}"/../pram --no-gitconfig -e true -G -I -s -P 
./three-commits.patch
+
+git log --format='%ae%n%an%n%aI%n%B' -3 > git-log.txt
+diff -u - git-log.txt <<-EOF
+       [email protected]
+       Other person
+       2000-01-01T00:00:00Z
+       Third patch
+
+       Signed-off-by: Other person <[email protected]>
+       Signed-off-by: PRam test <[email protected]>
+
+       [email protected]
+       Other person
+       2000-01-01T00:00:00Z
+       Second patch
+
+       Signed-off-by: Other person <[email protected]>
+       Signed-off-by: PRam test <[email protected]>
+
+       [email protected]
+       Other person
+       2000-01-01T00:00:00Z
+       First patch
+
+       Signed-off-by: Other person <[email protected]>
+       Signed-off-by: PRam test <[email protected]>
+
+EOF
+
+sha1sum -c <<EOF
+1d0dac1918223c41f4d08973e460bf82508a19ba  data.txt
+EOF

diff --git a/test/12signoff-dedup.sh b/test/12signoff-dedup.sh
new file mode 100755
index 0000000..f6f8165
--- /dev/null
+++ b/test/12signoff-dedup.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+# Test that signed-off-by trailers are not duplicated. The patch
+# already has the line that pram will add, so it shouldn't add another
+# one.
+
+set -e -x
+
+. ./common-setup.sh
+
+cat > trivial.patch <<-EOF
+       From 88460bc61f56546da478dc6fd4682e7c62cc6c80 Mon Sep 17 00:00:00 2001
+       From: PRam test <[email protected]>
+       Date: Sat, 1 Jan 2000 00:00:00 +0000
+       Subject: [PATCH] A trivial patch
+
+       Signed-off-by: PRam test <[email protected]>
+       ---
+        data.txt    | 4 ++--
+        newfile.txt | 1 +
+        2 files changed, 3 insertions(+), 2 deletions(-)
+        create mode 100644 newfile.txt
+
+       diff --git a/data.txt b/data.txt
+       index 5baade6..0139962 100644
+       --- a/data.txt
+       +++ b/data.txt
+       @@ -1,8 +1,8 @@
+        This is some initial data.
+
+        001100
+       -010010
+       -011110
+        100001
+       +011110
+       +010010
+        101101
+        110011
+       diff --git a/newfile.txt b/newfile.txt
+       new file mode 100644
+       index 0000000..6d8bf33
+       --- /dev/null
+       +++ b/newfile.txt
+       @@ -0,0 +1 @@
+       +Also, a new file with CRLF line ending.
+       --
+       2.21.0
+EOF
+
+bash "${INITDIR}"/../pram --no-gitconfig -e true -s -G -I --link-to 123 
./trivial.patch
+
+git log --format='%ae%n%an%n%aI%n%B' -1 > git-log.txt
+diff -u - git-log.txt <<-EOF
+       [email protected]
+       PRam test
+       2000-01-01T00:00:00Z
+       A trivial patch
+
+       Signed-off-by: PRam test <[email protected]>
+       Part-of: https://github.com/gentoo/gentoo/pull/123
+       Closes: https://github.com/gentoo/gentoo/pull/123
+
+EOF
+
+sha1sum -c <<EOF
+8054584c7b1fa9b5bdd7ee1177e78c99ea2cce04  data.txt
+3f6e6d8b9efc370f5cb1bf6273b1ca1eeee958e0  newfile.txt
+EOF

Reply via email to