git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] format-patch: generate valid patch with diff.noprefix config

From
Laurent Arnoud <laurent@spkdev.net>
Date
Jun 2, 2020, 20:49 UTC
Message-ID
<20200602204924.GA1853335@spk-laptop>

With diff.noprefix enabled the patch generated with format-patch does not include prefix a/ and b/ so not applicable with `git am`. Solution is to force a_prefix and b_prefix on diffopt.

Signed-off-by: Laurent Arnoud <laurent@spkdev.net>
---
 builtin/log.c           | 2 ++
 t/t4014-format-patch.sh | 8 ++++++++
 2 files changed, 10 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index d104d5c688..ca63f8ceda 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1744,6 +1744,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	rev.diff = 1;
 	rev.max_parents = 1;
 	rev.diffopt.flags.recursive = 1;
+	rev.diffopt.a_prefix = "a/";
+	rev.diffopt.b_prefix = "b/";
 	rev.subject_prefix = fmt_patch_subject_prefix;
 	memset(&s_r_opt, 0, sizeof(s_r_opt));
 	s_r_opt.def = "HEAD";
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index db7e733af9..5d7930e106 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1602,6 +1602,14 @@ test_expect_success 'format patch ignores color.ui' '
 	test_cmp expect actual
 '
 
+test_expect_success 'format patch ignores diff.noprefix' '
+	test_unconfig diff.noprefix &&
+	git format-patch --stdout -1 >expect &&
+	test_config diff.noprefix true &&
+	git format-patch --stdout -1 >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'cover letter with invalid --cover-from-description and config' '
 	test_config branch.rebuild-1.description "config subject
 
-- 
2.27.0.rc2.129.g29f2dd231a
Next: Junio C Hamano
Message 1 of 7 in “format-patch: generate valid patch with diff.noprefix config”
  1. format-patch: generate valid patch with diff.noprefix configLaurent Arnoud, Jun 2, 2020
  2. Junio C HamanoJun 2, 2020
  3. Laurent ArnoudJun 2, 2020
  4. Junio C HamanoJun 2, 2020
  5. Laurent ArnoudJun 4, 2020
  6. Junio C HamanoJun 4, 2020
  7. Đoàn Trần Công DanhJun 4, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.