summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2020-11-18 13:32:52 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-11-18 13:32:52 -0800
commit5edc8bdc06db3893ceea52a48edd9b2c34fb64e6 (patch)
treed792d1a4fab39ac97f20bf1b831526cfb5ae6807
parentMerge branch 'jc/line-log-takes-no-pathspec' (diff)
parentformat-patch: support --output option (diff)
downloadtgif-5edc8bdc06db3893ceea52a48edd9b2c34fb64e6.tar.xz
Merge branch 'jk/format-patch-output'
"git format-patch --output=there" did not work as expected and instead crashed. The option is now supported. * jk/format-patch-output: format-patch: support --output option format-patch: tie file-opening logic to output_directory format-patch: refactor output selection
-rw-r--r--builtin/log.c37
-rwxr-xr-xt/t4014-format-patch.sh33
2 files changed, 55 insertions, 15 deletions
diff --git a/builtin/log.c b/builtin/log.c
index 9fd49fa914..6619e10abc 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1156,7 +1156,7 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
}
}
-static void make_cover_letter(struct rev_info *rev, int use_stdout,
+static void make_cover_letter(struct rev_info *rev, int use_separate_file,
struct commit *origin,
int nr, struct commit **list,
const char *branch_name,
@@ -1176,7 +1176,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
committer = git_committer_info(0);
- if (!use_stdout &&
+ if (use_separate_file &&
open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
die(_("failed to create cover-letter file"));
@@ -1945,20 +1945,27 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (rev.show_notes)
load_display_notes(&rev.notes_opt);
- if (!output_directory && !use_stdout)
- output_directory = config_output_directory;
+ if (use_stdout + rev.diffopt.close_file + !!output_directory > 1)
+ die(_("--stdout, --output, and --output-directory are mutually exclusive"));
- if (!use_stdout)
- output_directory = set_outdir(prefix, output_directory);
- else
+ if (use_stdout) {
setup_pager();
-
- if (output_directory) {
+ } 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;
+
+ if (!output_directory)
+ output_directory = config_output_directory;
+ output_directory = set_outdir(prefix, output_directory);
+
if (rev.diffopt.use_color != GIT_COLOR_ALWAYS)
rev.diffopt.use_color = GIT_COLOR_NEVER;
- if (use_stdout)
- die(_("standard output, or directory, which one?"));
/*
* We consider <outdir> as 'outside of gitdir', therefore avoid
* applying adjust_shared_perm in s-c-l-d.
@@ -2120,7 +2127,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (cover_letter) {
if (thread)
gen_message_id(&rev, "cover");
- make_cover_letter(&rev, use_stdout,
+ make_cover_letter(&rev, !!output_directory,
origin, nr, list, branch_name, quiet);
print_bases(&bases, rev.diffopt.file);
print_signature(rev.diffopt.file);
@@ -2175,7 +2182,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
gen_message_id(&rev, oid_to_hex(&commit->object.oid));
}
- if (!use_stdout &&
+ if (output_directory &&
open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet))
die(_("failed to create output files"));
shown = log_tree_commit(&rev, commit);
@@ -2188,7 +2195,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
* the log; when using one file per patch, we do
* not want the extra blank line.
*/
- if (!use_stdout)
+ if (output_directory)
rev.shown_one = 0;
if (shown) {
print_bases(&bases, rev.diffopt.file);
@@ -2199,7 +2206,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
else
print_signature(rev.diffopt.file);
}
- if (!use_stdout)
+ if (output_directory)
fclose(rev.diffopt.file);
}
stop_progress(&progress);
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 294e76c860..42588bf6e1 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1919,6 +1919,39 @@ test_expect_success 'format-patch -o overrides format.outputDirectory' '
test_path_is_dir patchset
'
+test_expect_success 'format-patch forbids multiple outputs' '
+ rm -fr outfile outdir &&
+ test_must_fail \
+ 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 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 &&