summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2016-07-30 02:41:56 -0700
committerJunio C Hamano <gitster@pobox.com>2016-08-01 13:13:02 -0700
commit6bc6b6c0dc0a58874a7a6b9afc3156a5cf9bb10d (patch)
tree05343b68df9de90923ea0fc2d3088f86321d2816
parent08df31eeccfe1576971ea4ba42570a424c3cfc41 (diff)
downloadgit-jt/format-patch-from-config.tar.gz
format-patch: format.from gives the default for --fromjt/format-patch-from-config
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>
-rw-r--r--Documentation/config.txt10
-rw-r--r--builtin/log.c13
-rw-r--r--contrib/completion/git-completion.bash1
-rwxr-xr-xt/t4014-format-patch.sh40
4 files changed, 63 insertions, 1 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6ad3eb66df..cdc99dca26 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1227,6 +1227,16 @@ format.attach::
value as the boundary. See the --attach option in
linkgit:git-format-patch[1].
+format.from::
+ Provides the default value for the `--from` option to format-patch.
+ Accepts a boolean value, or a name and email address. If false,
+ format-patch defaults to `--no-from`, using commit authors directly in
+ the "From:" field of patch mails. If true, format-patch defaults to
+ `--from`, using your committer identity in the "From:" field of patch
+ mails and including a "From:" field in the body of the patch mail if
+ different. If set to a non-boolean value, format-patch uses that
+ value instead of your committer identity. Defaults to false.
+
format.numbered::
A boolean which can enable or disable sequence numbers in patch
subjects. It defaults to "auto" which enables it only if there
diff --git a/builtin/log.c b/builtin/log.c
index 099f4f7be9..13ebe7a757 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -703,6 +703,7 @@ static void add_header(const char *value)
static int thread;
static int do_signoff;
static int base_auto;
+static char *from;
static const char *signature = git_version_string;
static const char *signature_file;
static int config_cover_letter;
@@ -791,6 +792,17 @@ static int git_format_config(const char *var, const char *value, void *cb)
base_auto = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "format.from")) {
+ int b = git_config_maybe_bool(var, value);
+ free(from);
+ if (b < 0)
+ from = xstrdup(value);
+ else if (b)
+ from = xstrdup(git_committer_info(IDENT_NO_DATE));
+ else
+ from = NULL;
+ return 0;
+ }
return git_log_config(var, value, cb);
}
@@ -1368,7 +1380,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
int quiet = 0;
int reroll_count = -1;
char *branch_name = NULL;
- char *from = NULL;
char *base_commit = NULL;
struct base_tree_info bases;
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 34024754d9..2bd600fff1 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2085,6 +2085,7 @@ _git_config ()
format.attach
format.cc
format.coverLetter
+ format.from
format.headers
format.numbered
format.pretty
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 805dc9012d..8109e46dc7 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -229,6 +229,46 @@ check_patch () {
grep -e "^Subject:" "$1"
}
+test_expect_success 'format.from=false' '
+
+ git -c format.from=false format-patch --stdout master..side |
+ sed -e "/^\$/q" >patch &&
+ check_patch patch &&
+ ! grep "^From: C O Mitter <committer@example.com>\$" patch
+'
+
+test_expect_success 'format.from=true' '
+
+ git -c format.from=true format-patch --stdout master..side |
+ sed -e "/^\$/q" >patch &&
+ check_patch patch &&
+ grep "^From: C O Mitter <committer@example.com>\$" patch
+'
+
+test_expect_success 'format.from with address' '
+
+ git -c format.from="F R Om <from@example.com>" format-patch --stdout master..side |
+ sed -e "/^\$/q" >patch &&
+ check_patch patch &&
+ grep "^From: F R Om <from@example.com>\$" patch
+'
+
+test_expect_success '--no-from overrides format.from' '
+
+ git -c format.from="F R Om <from@example.com>" format-patch --no-from --stdout master..side |
+ sed -e "/^\$/q" >patch &&
+ check_patch patch &&
+ ! grep "^From: F R Om <from@example.com>\$" patch
+'
+
+test_expect_success '--from overrides format.from' '
+
+ git -c format.from="F R Om <from@example.com>" format-patch --from --stdout master..side |
+ sed -e "/^\$/q" >patch &&
+ check_patch patch &&
+ ! grep "^From: F R Om <from@example.com>\$" patch
+'
+
test_expect_success '--no-to overrides config.to' '
git config --replace-all format.to \