Skip to content

Commit c169af8

Browse files
peffgitster
authored andcommitted
format-patch: do not respect diff.noprefix
The output of format-patch respects diff.noprefix, but this usually ends up being a hassle for people receiving the patch, as they have to manually specify "-p0" in order to apply it. I don't think there was any specific intention for it to behave this way. The noprefix option is handled by git_diff_ui_config(), and format-patch exists in a gray area between plumbing and porcelain. People do look at the output, and we'd expect it to colorize things, respect their choice of algorithm, and so on. But this particular option creates problems for the receiver (in theory so does diff.mnemonicprefix, but since we are always formatting commits, the mnemonic prefixes will always be "a/" and "b/"). So let's disable it. The slight downsides are: - people who have set diff.noprefix presumably like to see their patches without prefixes. If they use format-patch to review their series, they'll see prefixes. On the other hand, it is probably a good idea for them to look at what will actually get sent out. We could try to play games here with "is stdout a tty", as we do for color. But that's not a completely reliable signal, and it's probably not worth the trouble. If you want to see the patch with the usual bells and whistles, then you are better off using "git log" or "git show". - if a project really does have a workflow that likes prefix-less patches, and the receiver is prepared to use "-p0", then the sender now has to manually say "--no-prefix" for each format-patch invocation. That doesn't seem _too_ terrible given that the receiver has to manually say "-p0" for each git-am invocation. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b39a569 commit c169af8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

builtin/log.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,15 @@ static int git_format_config(const char *var, const char *value, void *cb)
10851085
return 0;
10861086
}
10871087

1088+
/*
1089+
* ignore some porcelain config which would otherwise be parsed by
1090+
* git_diff_ui_config(), via git_log_config(); we can't just avoid
1091+
* diff_ui_config completely, because we do care about some ui options
1092+
* like color.
1093+
*/
1094+
if (!strcmp(var, "diff.noprefix"))
1095+
return 0;
1096+
10881097
return git_log_config(var, value, cb);
10891098
}
10901099

t/t4014-format-patch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,4 +2386,9 @@ test_expect_success 'interdiff: solo-patch' '
23862386
test_cmp expect actual
23872387
'
23882388

2389+
test_expect_success 'format-patch does not respect diff.noprefix' '
2390+
git -c diff.noprefix format-patch -1 --stdout >actual &&
2391+
grep "^--- a/blorp" actual
2392+
'
2393+
23892394
test_done

0 commit comments

Comments
 (0)