format-patch: teach --no-base
If `format.useAutoBase = true`, there was no way to override this from the command-line. Teach the `--no-base` option in format-patch to override `format.useAutoBase`. Helped-by: René Scharfe <l.s.r@web.de> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Dec 4, 2019 at 13:25 UTC
945dc55dda595a3e5449017797cb90599ed9ecb5
3 files changed
+14
-4
Documentation/git-format-patch.txt
+3
-2
@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
333
Output an all-zero hash in each patch's From header instead
334
of the hash of the commit.
335
336
---base=<commit>::
336
+--[no-]base[=<commit>]::
337
Record the base tree information to identify the state the
338
patch series applies to. See the BASE TREE INFORMATION section
339
below for details. If <commit> is "auto", a base commit is
340
- automatically chosen.
340
+ automatically chosen. The `--no-base` option overrides a
341
+ `format.useAutoBase` configuration.
342
343
--root::
344
Treat the revision argument as a <revision range>, even if it
builtin/log.c
+5
-2
@@ -1406,7 +1406,7 @@ static struct commit *get_base_commit(const char *base_commit,
1406
base = lookup_commit_reference_by_name(base_commit);
1407
if (!base)
1408
die(_("unknown commit %s"), base_commit);
1409
- } else if ((base_commit && !strcmp(base_commit, "auto")) || base_auto) {
1409
+ } else if ((base_commit && !strcmp(base_commit, "auto"))) {
1410
struct branch *curr_branch = branch_get(NULL);
1411
const char *upstream = branch_get_upstream(curr_branch, NULL);
1412
if (upstream) {
@@ -1710,6 +1710,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1710
s_r_opt.def = "HEAD";
1711
s_r_opt.revarg_opt = REVARG_COMMITTISH;
1712
1713
+ if (base_auto)
1714
+ base_commit = "auto";
1715
+
1716
if (default_attach) {
1717
rev.mime_boundary = default_attach;
1718
rev.no_inline = 1;
@@ -1973,7 +1976,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1976
}
1977
1978
memset(&bases, 0, sizeof(bases));
1976
- if (base_commit || base_auto) {
1979
+ if (base_commit) {
1980
struct commit *base = get_base_commit(base_commit, list, nr);
1981
reset_revision_walk();
1982
clear_object_flags(UNINTERESTING);
t/t4014-format-patch.sh
+6
@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '
1958
test_cmp expect actual
1959
'
1960
1961
+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
1962
+ test_config format.useAutoBase true &&
1963
+ git format-patch --stdout --no-base -1 >patch &&
1964
+ ! grep "^base-commit:" patch
1965
+'
1966
+
1967
test_expect_success 'format-patch --base with --attach' '
1968
git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
1969
sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \