Skip to content

Commit 676cead

Browse files
committed
Merge branch 'rs/format-patch-pathspec-fix' into maint
"git format-patch <args> -- <pathspec>" lost the pathspec when showing the second and subsequent commits, which has been corrected. source: <[email protected]> * rs/format-patch-pathspec-fix: 2.36 format-patch regression fix
2 parents 09a2302 + 91f8f7e commit 676cead

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

builtin/log.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18961896
rev.diff = 1;
18971897
rev.max_parents = 1;
18981898
rev.diffopt.flags.recursive = 1;
1899+
rev.diffopt.no_free = 1;
18991900
rev.subject_prefix = fmt_patch_subject_prefix;
19001901
memset(&s_r_opt, 0, sizeof(s_r_opt));
19011902
s_r_opt.def = "HEAD";
@@ -2021,13 +2022,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
20212022

20222023
if (use_stdout) {
20232024
setup_pager();
2024-
} else if (rev.diffopt.close_file) {
2025-
/*
2026-
* The diff code parsed --output; it has already opened the
2027-
* file, but we must instruct it not to close after each diff.
2028-
*/
2029-
rev.diffopt.no_free = 1;
2030-
} else {
2025+
} else if (!rev.diffopt.close_file) {
20312026
int saved;
20322027

20332028
if (!output_directory)

t/t4014-format-patch.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,40 @@ test_expect_success 'format-patch --numstat should produce a patch' '
926926
'
927927

928928
test_expect_success 'format-patch -- <path>' '
929-
git format-patch main..side -- file 2>error &&
930-
! grep "Use .--" error
929+
rm -f *.patch &&
930+
git checkout -b pathspec main &&
931+
932+
echo file_a 1 >file_a &&
933+
echo file_b 1 >file_b &&
934+
git add file_a file_b &&
935+
git commit -m pathspec_initial &&
936+
937+
echo file_a 2 >>file_a &&
938+
git add file_a &&
939+
git commit -m pathspec_a &&
940+
941+
echo file_b 2 >>file_b &&
942+
git add file_b &&
943+
git commit -m pathspec_b &&
944+
945+
echo file_a 3 >>file_a &&
946+
echo file_b 3 >>file_b &&
947+
git add file_a file_b &&
948+
git commit -m pathspec_ab &&
949+
950+
cat >expect <<-\EOF &&
951+
0001-pathspec_initial.patch
952+
0002-pathspec_a.patch
953+
0003-pathspec_ab.patch
954+
EOF
955+
956+
git format-patch main..pathspec -- file_a >output &&
957+
test_cmp expect output &&
958+
! grep file_b *.patch
931959
'
932960

933961
test_expect_success 'format-patch --ignore-if-in-upstream HEAD' '
962+
git checkout side &&
934963
git format-patch --ignore-if-in-upstream HEAD
935964
'
936965

0 commit comments

Comments
 (0)