Skip to content

Commit d7d9c2d

Browse files
mndrixgitster
authored andcommitted
format-patch: add arbitrary email headers
format-patch supports the format.headers configuration for adding arbitrary email headers to the patches it outputs. This patch adds support for an --add-header argument which makes the same feature available from the command line. This is useful when the content of custom email headers must change from branch to branch. This patch has been sponsored by Grant Street Group Signed-off-by: Michael Hendricks <michael@ndrix.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent eed1fcd commit d7d9c2d

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Documentation/git-format-patch.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ if that is not set.
161161
Add a "Cc:" header to the email headers. This is in addition
162162
to any configured headers, and may be used multiple times.
163163

164+
--add-header=<header>::
165+
Add an arbitrary header to the email headers. This is in addition
166+
to any configured headers, and may be used multiple times.
167+
For example, --add-header="Organization: git-foo"
168+
164169
--cover-letter::
165170
In addition to the patches, generate a cover letter file
166171
containing the shortlog and the overall diffstat. You can

builtin-log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
918918
cover_letter = 1;
919919
else if (!strcmp(argv[i], "--no-binary"))
920920
no_binary_diff = 1;
921+
else if (!prefixcmp(argv[i], "--add-header="))
922+
add_header(argv[i] + 13);
921923
else
922924
argv[j++] = argv[i];
923925
}

t/t4014-format-patch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ test_expect_success 'additional command line cc' '
128128
grep "^ *S. E. Cipient <scipient@example.com>$" patch5
129129
'
130130

131+
test_expect_success 'command line headers' '
132+
133+
git config --unset-all format.headers &&
134+
git format-patch --add-header="Cc: R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^$/q" >patch6 &&
135+
grep "^Cc: R. E. Cipient <rcipient@example.com>$" patch6
136+
'
137+
138+
test_expect_success 'configuration headers and command line headers' '
139+
140+
git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" &&
141+
git format-patch --add-header="Cc: S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^$/q" >patch7 &&
142+
grep "^Cc: R. E. Cipient <rcipient@example.com>,$" patch7 &&
143+
grep "^ *S. E. Cipient <scipient@example.com>$" patch7
144+
'
145+
131146
test_expect_success 'multiple files' '
132147
133148
rm -rf patches/ &&

0 commit comments

Comments
 (0)