Merge branch 'dl/rebase-with-autobase'

"git rebase" did not work well when format.useAutoBase
configuration variable is set, which has been corrected.

* dl/rebase-with-autobase:
  rebase: fix format.useAutoBase breakage
  format-patch: teach --no-base
  t4014: use test_config()
  format-patch: fix indentation
  t3400: demonstrate failure with format.useAutoBase
This commit is contained in:
Junio C Hamano
2019-12-16 13:08:32 -08:00
5 changed files with 26 additions and 11 deletions

View File

@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
Output an all-zero hash in each patch's From header instead Output an all-zero hash in each patch's From header instead
of the hash of the commit. of the hash of the commit.
--base=<commit>:: --[no-]base[=<commit>]::
Record the base tree information to identify the state the Record the base tree information to identify the state the
patch series applies to. See the BASE TREE INFORMATION section patch series applies to. See the BASE TREE INFORMATION section
below for details. If <commit> is "auto", a base commit is below for details. If <commit> is "auto", a base commit is
automatically chosen. automatically chosen. The `--no-base` option overrides a
`format.useAutoBase` configuration.
--root:: --root::
Treat the revision argument as a <revision range>, even if it Treat the revision argument as a <revision range>, even if it

View File

@ -1372,7 +1372,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
string_list_clear(&extra_to, 0); string_list_clear(&extra_to, 0);
string_list_clear(&extra_cc, 0); string_list_clear(&extra_cc, 0);
} else { } else {
add_header(arg); add_header(arg);
} }
return 0; return 0;
} }
@ -1428,7 +1428,7 @@ static struct commit *get_base_commit(const char *base_commit,
base = lookup_commit_reference_by_name(base_commit); base = lookup_commit_reference_by_name(base_commit);
if (!base) if (!base)
die(_("unknown commit %s"), base_commit); die(_("unknown commit %s"), base_commit);
} else if ((base_commit && !strcmp(base_commit, "auto")) || base_auto) { } else if ((base_commit && !strcmp(base_commit, "auto"))) {
struct branch *curr_branch = branch_get(NULL); struct branch *curr_branch = branch_get(NULL);
const char *upstream = branch_get_upstream(curr_branch, NULL); const char *upstream = branch_get_upstream(curr_branch, NULL);
if (upstream) { if (upstream) {
@ -1732,6 +1732,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
s_r_opt.def = "HEAD"; s_r_opt.def = "HEAD";
s_r_opt.revarg_opt = REVARG_COMMITTISH; s_r_opt.revarg_opt = REVARG_COMMITTISH;
if (base_auto)
base_commit = "auto";
if (default_attach) { if (default_attach) {
rev.mime_boundary = default_attach; rev.mime_boundary = default_attach;
rev.no_inline = 1; rev.no_inline = 1;
@ -1995,7 +1998,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
} }
memset(&bases, 0, sizeof(bases)); memset(&bases, 0, sizeof(bases));
if (base_commit || base_auto) { if (base_commit) {
struct commit *base = get_base_commit(base_commit, list, nr); struct commit *base = get_base_commit(base_commit, list, nr);
reset_revision_walk(); reset_revision_walk();
clear_object_flags(UNINTERESTING); clear_object_flags(UNINTERESTING);

View File

@ -1039,7 +1039,8 @@ static int run_am(struct rebase_options *opts)
argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout", argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
"--full-index", "--cherry-pick", "--right-only", "--full-index", "--cherry-pick", "--right-only",
"--src-prefix=a/", "--dst-prefix=b/", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/", "--no-renames",
"--no-cover-letter", "--pretty=mboxrd", "--topo-order", NULL); "--no-cover-letter", "--pretty=mboxrd", "--topo-order",
"--no-base", NULL);
if (opts->git_format_patch_opt.len) if (opts->git_format_patch_opt.len)
argv_array_split(&format_patch.args, argv_array_split(&format_patch.args,
opts->git_format_patch_opt.buf); opts->git_format_patch_opt.buf);

View File

@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
test_must_fail git rebase test_must_fail git rebase
' '
test_expect_success 'rebase works with format.useAutoBase' '
test_config format.useAutoBase true &&
git checkout topic &&
git rebase master
'
test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' ' test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
git checkout -b default-base master && git checkout -b default-base master &&
git checkout -b default topic && git checkout -b default topic &&

View File

@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'
test_must_fail git format-patch --base=auto -1 test_must_fail git format-patch --base=auto -1
' '
test_expect_success 'format-patch format.useAutoBaseoption' ' test_expect_success 'format-patch format.useAutoBase option' '
test_when_finished "git config --unset format.useAutoBase" &&
git checkout local && git checkout local &&
git config format.useAutoBase true && test_config format.useAutoBase true &&
git format-patch --stdout -1 >patch && git format-patch --stdout -1 >patch &&
grep "^base-commit:" patch >actual && grep "^base-commit:" patch >actual &&
git rev-parse upstream >commit-id-base && git rev-parse upstream >commit-id-base &&
@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '
' '
test_expect_success 'format-patch --base overrides format.useAutoBase' ' test_expect_success 'format-patch --base overrides format.useAutoBase' '
test_when_finished "git config --unset format.useAutoBase" && test_config format.useAutoBase true &&
git config format.useAutoBase true &&
git format-patch --stdout --base=HEAD~1 -1 >patch && git format-patch --stdout --base=HEAD~1 -1 >patch &&
grep "^base-commit:" patch >actual && grep "^base-commit:" patch >actual &&
git rev-parse HEAD~1 >commit-id-base && git rev-parse HEAD~1 >commit-id-base &&
@ -1960,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
test_config format.useAutoBase true &&
git format-patch --stdout --no-base -1 >patch &&
! grep "^base-commit:" patch
'
test_expect_success 'format-patch --base with --attach' ' test_expect_success 'format-patch --base with --attach' '
git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch && git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \ sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \