summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/log.c11
-rwxr-xr-xt/t4014-format-patch.sh26
2 files changed, 32 insertions, 5 deletions
diff --git a/builtin/log.c b/builtin/log.c
index dd85459d74..963821a5f5 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1942,11 +1942,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (rev.show_notes)
load_display_notes(&rev.notes_opt);
- if (use_stdout + !!output_directory > 1)
- die(_("--stdout and --output-directory are mutually exclusive"));
+ if (use_stdout + rev.diffopt.close_file + !!output_directory > 1)
+ die(_("--stdout, --output, and --output-directory are mutually exclusive"));
if (use_stdout) {
setup_pager();
+ } else if (rev.diffopt.close_file) {
+ /*
+ * The diff code parsed --output; it has already opened the
+ * file, but but we must instruct it not to close after each
+ * diff.
+ */
+ rev.diffopt.close_file = 0;
} else {
int saved;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index e8d6156a6a..42588bf6e1 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1920,18 +1920,38 @@ test_expect_success 'format-patch -o overrides format.outputDirectory' '
'
test_expect_success 'format-patch forbids multiple outputs' '
- rm -fr outdir &&
+ rm -fr outfile outdir &&
test_must_fail \
- git format-patch --stdout --output-directory=outdir
+ git format-patch --stdout --output-directory=outdir &&
+ test_must_fail \
+ git format-patch --stdout --output=outfile &&
+ test_must_fail \
+ git format-patch --output=outfile --output-directory=outdir
'
test_expect_success 'configured outdir does not conflict with output options' '
- rm -fr outdir &&
+ rm -fr outfile outdir &&
test_config format.outputDirectory outdir &&
git format-patch --stdout &&
+ test_path_is_missing outdir &&
+ git format-patch --output=outfile &&
test_path_is_missing outdir
'
+test_expect_success 'format-patch --output' '
+ rm -fr outfile &&
+ git format-patch -3 --stdout HEAD >expect &&
+ git format-patch -3 --output=outfile HEAD &&
+ test_cmp expect outfile
+'
+
+test_expect_success 'format-patch --cover-letter --output' '
+ rm -fr outfile &&
+ git format-patch --cover-letter -3 --stdout HEAD >expect &&
+ git format-patch --cover-letter -3 --output=outfile HEAD &&
+ test_cmp expect outfile
+'
+
test_expect_success 'format-patch --base' '
git checkout patchid &&