commit: b08a5fc8224008e1ccbe78c987864f4f340cce23 Author: Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz> AuthorDate: Sat Dec 13 07:31:34 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=b08a5fc8
Replace add_trailer() with git-interpret-trailers(1) Use git-interpret-trailers(1) for all the trailer manipulation. This has the benefit of deduplicating all trailers. Signed-off-by: Thomas Bracht Laumann Jespersen <t <AT> laumann.xyz> Part-of: https://github.com/gentoo/pram/pull/17 Closes: https://github.com/gentoo/pram/pull/17 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> pram | 52 ++++++++++++++++++++++++++-------------------- test/01signoff-multiple.sh | 9 +++++++- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/pram b/pram index 7ceb710..7253fec 100755 --- a/pram +++ b/pram @@ -57,15 +57,6 @@ print_help() { echo " boolean options: pram.gpgsign, pram.interactive, pram.signoff, pram.partof" } -# add_trailer <file> <line-to-add> -add_trailer() { - local file=${1} - local line=${2} - - sed -i -e "1,/^---$/s@^---\$@${line}\n\0@" "${file}" || - die "Appending trailer via sed failed" -} - main() { # make sure files are sorted ascending local -x LC_COLLATE=C @@ -374,7 +365,7 @@ main() { fi local patches=( "${tempdir}"/[0-9]* ) - if [[ ${signoff} || ${partof} ]]; then + if [[ ${signoff} ]]; then local f for f in "${patches[@]}"; do if [[ ${signoff} ]]; then @@ -382,32 +373,49 @@ main() { die "Commit no. ${f##*/} was not signed off by the author!" fi fi - - if [[ ${partof} ]]; then - add_trailer "${f}" "Part-of: ${to_close}" - fi done fi - + if [[ ${partof} ]]; then + local partof_conf=( + -c trailer.partof.key="Part-of: " + -c trailer.partof.ifmissing=add + ) + git "${partof_conf[@]}" interpret-trailers --in-place --trailer="partof: ${to_close}" "${patches[@]}" || + die "git interpret-trailers failed" + fi + local git_conf=( + -c trailer.bug.key="Bug: " + -c trailer.bug.ifexists=addIfDifferent + -c trailer.closes.key="Closes: " + -c trailer.closes.ifexists=addIfDifferent + -c trailer.merges.key="Merges: " + -c trailer.merges.ifexists=addIfDifferent + ) + local git_trailers=() # append bug references local b for b in "${bug[@]}"; do [[ ${b} != *://* ]] && b=https://bugs.gentoo.org/${b} - add_trailer "${patches[-1]}" "Bug: ${b}" + git_trailers+=( --trailer="bug: ${b}" ) done for b in "${closes[@]}"; do [[ ${b} != *://* ]] && b=https://bugs.gentoo.org/${b} - add_trailer "${patches[-1]}" "Closes: ${b}" + git_trailers+=( --trailer="closes: ${b}" ) done # append Closes: (or Merges:) to the final commit if missing if [[ -n ${to_close} ]]; then - local trailer=Closes - [[ ${merge} == 1 ]] && trailer=Merges + local trailer=closes + [[ ${merge} == 1 ]] && trailer=merges + git_trailers+=( --trailer="${trailer}: ${to_close}" ) + fi - if ! grep -q "^${trailer}: ${to_close}" "${patches[-1]}"; then - add_trailer "${patches[-1]}" "${trailer}: ${to_close}" - fi + # Add Bug: and Closes/Merges: tags to the last patch + if [[ "${#git_trailers[@]}" -gt 0 ]]; then + git "${git_conf[@]}" interpret-trailers --in-place \ + "${git_trailers[@]}" "${patches[-1]}" || + die "git interpret-trailers failed" fi + # Append committer signed-off-by (only if missing) if [[ -n ${signoff} ]]; then local username="$(git config user.name)" diff --git a/test/01signoff-multiple.sh b/test/01signoff-multiple.sh index 0e7e6ea..51c487c 100755 --- a/test/01signoff-multiple.sh +++ b/test/01signoff-multiple.sh @@ -88,7 +88,7 @@ cat > three-commits.patch <<-EOF 2.49.0 EOF -bash "${INITDIR}"/../pram --no-gitconfig -e true -G -I -s -P ./three-commits.patch +bash "${INITDIR}"/../pram --no-gitconfig -e true -G -I -s -b 314152 -b 314156 -c 314154 --link-to https://codeberg.org/gentoo/gentoo/pull/123 ./three-commits.patch git log --format='%ae%n%an%n%aI%n%B' -3 > git-log.txt diff -u - git-log.txt <<-EOF @@ -98,6 +98,11 @@ diff -u - git-log.txt <<-EOF Third patch Signed-off-by: Other person <[email protected]> + Part-of: https://codeberg.org/gentoo/gentoo/pull/123 + Bug: https://bugs.gentoo.org/314152 + Bug: https://bugs.gentoo.org/314156 + Closes: https://bugs.gentoo.org/314154 + Closes: https://codeberg.org/gentoo/gentoo/pull/123 Signed-off-by: PRam test <[email protected]> [email protected] @@ -107,6 +112,7 @@ diff -u - git-log.txt <<-EOF Signed-off-by: Other person <[email protected]> Signed-off-by: PRam test <[email protected]> + Part-of: https://codeberg.org/gentoo/gentoo/pull/123 [email protected] Other person @@ -114,6 +120,7 @@ diff -u - git-log.txt <<-EOF First patch Signed-off-by: Other person <[email protected]> + Part-of: https://codeberg.org/gentoo/gentoo/pull/123 Signed-off-by: PRam test <[email protected]> EOF
