Skip to content

Commit 945dc55

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 700e006 commit 945dc55

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Documentation/git-format-patch.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
333333
Output an all-zero hash in each patch's From header instead
334334
of the hash of the commit.
335335

336-
--base=<commit>::
336+
--[no-]base[=<commit>]::
337337
Record the base tree information to identify the state the
338338
patch series applies to. See the BASE TREE INFORMATION section
339339
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.
341342

342343
--root::
343344
Treat the revision argument as a <revision range>, even if it

builtin/log.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static struct commit *get_base_commit(const char *base_commit,
14061406
base = lookup_commit_reference_by_name(base_commit);
14071407
if (!base)
14081408
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"))) {
14101410
struct branch *curr_branch = branch_get(NULL);
14111411
const char *upstream = branch_get_upstream(curr_branch, NULL);
14121412
if (upstream) {
@@ -1710,6 +1710,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17101710
s_r_opt.def = "HEAD";
17111711
s_r_opt.revarg_opt = REVARG_COMMITTISH;
17121712

1713+
if (base_auto)
1714+
base_commit = "auto";
1715+
17131716
if (default_attach) {
17141717
rev.mime_boundary = default_attach;
17151718
rev.no_inline = 1;
@@ -1973,7 +1976,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19731976
}
19741977

19751978
memset(&bases, 0, sizeof(bases));
1976-
if (base_commit || base_auto) {
1979+
if (base_commit) {
19771980
struct commit *base = get_base_commit(base_commit, list, nr);
19781981
reset_revision_walk();
19791982
clear_object_flags(UNINTERESTING);

t/t4014-format-patch.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '
19581958
test_cmp expect actual
19591959
'
19601960

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+
19611967
test_expect_success 'format-patch --base with --attach' '
19621968
git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
19631969
sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \

0 commit comments

Comments
 (0)