Skip to content

Commit 6bead0c

Browse files
committed
Merge branch 'sb/format-patch-signature'
* sb/format-patch-signature: completion: Add --signature and format.signature format-patch: Add a signature option (--signature)
2 parents 223a923 + d8e1e5d commit 6bead0c

File tree

6 files changed

+85
-4
lines changed

6 files changed

+85
-4
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,12 @@ format.subjectprefix::
889889
The default for format-patch is to output files with the '[PATCH]'
890890
subject prefix. Use this variable to change that prefix.
891891

892+
format.signature::
893+
The default for format-patch is to output a signature containing
894+
the git version number. Use this variable to change that default.
895+
Set this variable to the empty string ("") to suppress
896+
signature generation.
897+
892898
format.suffix::
893899
The default for format-patch is to output files with the suffix
894900
`.patch`. Use this variable to change that suffix (make sure to

Documentation/git-format-patch.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SYNOPSIS
1313
[--no-thread | --thread[=<style>]]
1414
[(--attach|--inline)[=<boundary>] | --no-attach]
1515
[-s | --signoff]
16+
[--signature=<signature> | --no-signature]
1617
[-n | --numbered | -N | --no-numbered]
1718
[--start-number <n>] [--numbered-files]
1819
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@ -180,6 +181,12 @@ will want to ensure that threading is disabled for `git send-email`.
180181
containing the shortlog and the overall diffstat. You can
181182
fill in a description in the file before sending it out.
182183

184+
--[no]-signature=<signature>::
185+
Add a signature to each message produced. Per RFC 3676 the signature
186+
is separated from the body by a line with '-- ' on it. If the
187+
signature option is omitted the signature defaults to the git version
188+
number.
189+
183190
--suffix=.<sfx>::
184191
Instead of using `.patch` as the suffix for generated
185192
filenames, use specified suffix. A common alternative is

builtin/log.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,9 @@ static void add_header(const char *value)
549549

550550
#define THREAD_SHALLOW 1
551551
#define THREAD_DEEP 2
552-
static int thread = 0;
553-
static int do_signoff = 0;
552+
static int thread;
553+
static int do_signoff;
554+
static const char *signature = git_version_string;
554555

555556
static int git_format_config(const char *var, const char *value, void *cb)
556557
{
@@ -609,6 +610,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
609610
do_signoff = git_config_bool(var, value);
610611
return 0;
611612
}
613+
if (!strcmp(var, "format.signature"))
614+
return git_config_string(&signature, var, value);
612615

613616
return git_log_config(var, value, cb);
614617
}
@@ -703,6 +706,12 @@ static void gen_message_id(struct rev_info *info, char *base)
703706
info->message_id = strbuf_detach(&buf, NULL);
704707
}
705708

709+
static void print_signature(void)
710+
{
711+
if (signature && *signature)
712+
printf("-- \n%s\n\n", signature);
713+
}
714+
706715
static void make_cover_letter(struct rev_info *rev, int use_stdout,
707716
int numbered, int numbered_files,
708717
struct commit *origin,
@@ -796,6 +805,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
796805
diff_flush(&opts);
797806

798807
printf("\n");
808+
print_signature();
799809
}
800810

801811
static const char *clean_message_id(const char *msg_id)
@@ -1035,6 +1045,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
10351045
{ OPTION_CALLBACK, 0, "thread", &thread, "style",
10361046
"enable message threading, styles: shallow, deep",
10371047
PARSE_OPT_OPTARG, thread_callback },
1048+
OPT_STRING(0, "signature", &signature, "signature",
1049+
"add a signature"),
10381050
OPT_END()
10391051
};
10401052

@@ -1313,7 +1325,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
13131325
mime_boundary_leader,
13141326
rev.mime_boundary);
13151327
else
1316-
printf("-- \n%s\n\n", git_version_string);
1328+
print_signature();
13171329
}
13181330
if (!use_stdout)
13191331
fclose(stdout);

contrib/completion/git-completion.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ _git_format_patch ()
10521052
--numbered --start-number
10531053
--numbered-files
10541054
--keep-subject
1055-
--signoff
1055+
--signoff --signature --no-signature
10561056
--in-reply-to= --cc=
10571057
--full-index --binary
10581058
--not --all
@@ -1726,6 +1726,7 @@ _git_config ()
17261726
format.headers
17271727
format.numbered
17281728
format.pretty
1729+
format.signature
17291730
format.signoff
17301731
format.subjectprefix
17311732
format.suffix

t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ A U Thor (2):
1818
create mode 100644 file1
1919
delete mode 100644 file2
2020

21+
--
22+
g-i-t--v-e-r-s-i-o-n
23+
2124
From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001
2225
From: A U Thor <author@example.com>
2326
Date: Mon, 26 Jun 2006 00:01:00 +0000

t/t4014-format-patch.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,56 @@ test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
613613
git format-patch --ignore-if-in-upstream HEAD
614614
'
615615

616+
test_expect_success 'format-patch --signature' '
617+
git format-patch --stdout --signature="my sig" -1 >output &&
618+
grep "my sig" output
619+
'
620+
621+
test_expect_success 'format-patch with format.signature config' '
622+
git config format.signature "config sig" &&
623+
git format-patch --stdout -1 >output &&
624+
grep "config sig" output
625+
'
626+
627+
test_expect_success 'format-patch --signature overrides format.signature' '
628+
git config format.signature "config sig" &&
629+
git format-patch --stdout --signature="overrides" -1 >output &&
630+
! grep "config sig" output &&
631+
grep "overrides" output
632+
'
633+
634+
test_expect_success 'format-patch --no-signature ignores format.signature' '
635+
git config format.signature "config sig" &&
636+
git format-patch --stdout --signature="my sig" --no-signature \
637+
-1 >output &&
638+
! grep "config sig" output &&
639+
! grep "my sig" output &&
640+
! grep "^-- \$" output
641+
'
642+
643+
test_expect_success 'format-patch --signature --cover-letter' '
644+
git config --unset-all format.signature &&
645+
git format-patch --stdout --signature="my sig" --cover-letter \
646+
-1 >output &&
647+
grep "my sig" output &&
648+
test 2 = $(grep "my sig" output | wc -l)
649+
'
650+
651+
test_expect_success 'format.signature="" supresses signatures' '
652+
git config format.signature "" &&
653+
git format-patch --stdout -1 >output &&
654+
! grep "^-- \$" output
655+
'
656+
657+
test_expect_success 'format-patch --no-signature supresses signatures' '
658+
git config --unset-all format.signature &&
659+
git format-patch --stdout --no-signature -1 >output &&
660+
! grep "^-- \$" output
661+
'
662+
663+
test_expect_success 'format-patch --signature="" supresses signatures' '
664+
git format-patch --signature="" -1 >output &&
665+
! grep "^-- \$" output
666+
'
667+
616668
test_done

0 commit comments

Comments
 (0)