format-patch: format.from gives the default for --from
This helps users who would prefer format-patch to default to --from, and makes it easier to change the default in the future. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Josh Triplett committed
Jul 30, 2016 at 02:41 UTC
6bc6b6c0dc0a58874a7a6b9afc3156a5cf9bb10d
4 files changed
+63
-1
Documentation/config.txt
+10
@@ -1227,6 +1227,16 @@ format.attach::
1227
value as the boundary. See the --attach option in
1228
linkgit:git-format-patch[1].
1229
1230
+format.from::
1231
+ Provides the default value for the `--from` option to format-patch.
1232
+ Accepts a boolean value, or a name and email address. If false,
1233
+ format-patch defaults to `--no-from`, using commit authors directly in
1234
+ the "From:" field of patch mails. If true, format-patch defaults to
1235
+ `--from`, using your committer identity in the "From:" field of patch
1236
+ mails and including a "From:" field in the body of the patch mail if
1237
+ different. If set to a non-boolean value, format-patch uses that
1238
+ value instead of your committer identity. Defaults to false.
1239
+
1240
format.numbered::
1241
A boolean which can enable or disable sequence numbers in patch
1242
subjects. It defaults to "auto" which enables it only if there
builtin/log.c
+12
-1
@@ -703,6 +703,7 @@ static void add_header(const char *value)
703
static int thread;
704
static int do_signoff;
705
static int base_auto;
706
+static char *from;
707
static const char *signature = git_version_string;
708
static const char *signature_file;
709
static int config_cover_letter;
@@ -791,6 +792,17 @@ static int git_format_config(const char *var, const char *value, void *cb)
792
base_auto = git_config_bool(var, value);
793
return 0;
794
}
795
+ if (!strcmp(var, "format.from")) {
796
+ int b = git_config_maybe_bool(var, value);
797
+ free(from);
798
+ if (b < 0)
799
+ from = xstrdup(value);
800
+ else if (b)
801
+ from = xstrdup(git_committer_info(IDENT_NO_DATE));
802
+ else
803
+ from = NULL;
804
+ return 0;
805
+ }
806
807
return git_log_config(var, value, cb);
808
}
@@ -1368,7 +1380,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1380
int quiet = 0;
1381
int reroll_count = -1;
1382
char *branch_name = NULL;
1371
- char *from = NULL;
1383
char *base_commit = NULL;
1384
struct base_tree_info bases;
1385
contrib/completion/git-completion.bash
+1
@@ -2085,6 +2085,7 @@ _git_config ()
2085
format.attach
2086
format.cc
2087
format.coverLetter
2088
+ format.from
2089
format.headers
2090
format.numbered
2091
format.pretty
t/t4014-format-patch.sh
+40
@@ -229,6 +229,46 @@ check_patch () {
229
grep -e "^Subject:" "$1"
230
}
231
232
+test_expect_success 'format.from=false' '
233
+
234
+ git -c format.from=false format-patch --stdout master..side |
235
+ sed -e "/^\$/q" >patch &&
236
+ check_patch patch &&
237
+ ! grep "^From: C O Mitter <committer@example.com>\$" patch
238
+'
239
+
240
+test_expect_success 'format.from=true' '
241
+
242
+ git -c format.from=true format-patch --stdout master..side |
243
+ sed -e "/^\$/q" >patch &&
244
+ check_patch patch &&
245
+ grep "^From: C O Mitter <committer@example.com>\$" patch
246
+'
247
+
248
+test_expect_success 'format.from with address' '
249
+
250
+ git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side |
251
+ sed -e "/^\$/q" >patch &&
252
+ check_patch patch &&
253
+ grep "^From: F R Om <from@example.com>\$" patch
254
+'
255
+
256
+test_expect_success '--no-from overrides format.from' '
257
+
258
+ git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side |
259
+ sed -e "/^\$/q" >patch &&
260
+ check_patch patch &&
261
+ ! grep "^From: F R Om <from@example.com>\$" patch
262
+'
263
+
264
+test_expect_success '--from overrides format.from' '
265
+
266
+ git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side |
267
+ sed -e "/^\$/q" >patch &&
268
+ check_patch patch &&
269
+ ! grep "^From: F R Om <from@example.com>\$" patch
270
+'
271
+
272
test_expect_success '--no-to overrides config.to' '
273
274
git config --replace-all format.to \