From 0c47e061768d6c3b575ff623d11d9ecb7162a90f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 13:24:50 -0800 Subject: t3400: demonstrate failure with format.useAutoBase Ever since bb52995f3e (format-patch: introduce format.useAutoBase configuration, 2016-04-26), `git rebase` has been broken when `format.useAutoBase = true`. It fails when rebasing a branch: fatal: failed to get upstream, if you want to record base commit automatically, please use git branch --set-upstream-to to track a remote branch. Or you could specify base commit by --base= manually error: git encountered an error while preparing the patches to replay these revisions: ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12 As a result, git cannot rebase them. Demonstrate that failure here. Reported-by: Christian Biesinger Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index ab18ac5..ca99e8c 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' ' test_must_fail git rebase ' +test_expect_failure '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' ' git checkout -b default-base master && git checkout -b default topic && -- cgit v0.10.2-6-g49f6 From a749d01e1d9a91b96b00f4eee411c20e20e662b5 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 13:24:55 -0800 Subject: format-patch: fix indentation Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/builtin/log.c b/builtin/log.c index a26f223..9c44682 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1350,7 +1350,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset) string_list_clear(&extra_to, 0); string_list_clear(&extra_cc, 0); } else { - add_header(arg); + add_header(arg); } return 0; } -- cgit v0.10.2-6-g49f6 From 700e006c5d69990fc1167355e9fa7a55e9166581 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 13:25:00 -0800 Subject: t4014: use test_config() Instead of manually unsetting the config after the test case is done, use test_config() to do it automatically. While we're at it, fix a typo in a test case name. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 69267b1..c7cc643 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -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_expect_success 'format-patch format.useAutoBaseoption' ' - test_when_finished "git config --unset format.useAutoBase" && +test_expect_success 'format-patch format.useAutoBase option' ' git checkout local && - git config format.useAutoBase true && + test_config format.useAutoBase true && git format-patch --stdout -1 >patch && grep "^base-commit:" patch >actual && 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_when_finished "git config --unset format.useAutoBase" && - git config format.useAutoBase true && + test_config format.useAutoBase true && git format-patch --stdout --base=HEAD~1 -1 >patch && grep "^base-commit:" patch >actual && git rev-parse HEAD~1 >commit-id-base && -- cgit v0.10.2-6-g49f6 From 945dc55dda595a3e5449017797cb90599ed9ecb5 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 13:25:06 -0800 Subject: format-patch: teach --no-base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 00bdf9b..0d4f895 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -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 of the hash of the commit. ---base=:: +--[no-]base[=]:: Record the base tree information to identify the state the patch series applies to. See the BASE TREE INFORMATION section below for details. If is "auto", a base commit is - automatically chosen. + automatically chosen. The `--no-base` option overrides a + `format.useAutoBase` configuration. --root:: Treat the revision argument as a , even if it diff --git a/builtin/log.c b/builtin/log.c index 9c44682..bf904e8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1406,7 +1406,7 @@ static struct commit *get_base_commit(const char *base_commit, base = lookup_commit_reference_by_name(base_commit); if (!base) 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); const char *upstream = branch_get_upstream(curr_branch, NULL); if (upstream) { @@ -1710,6 +1710,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) s_r_opt.def = "HEAD"; s_r_opt.revarg_opt = REVARG_COMMITTISH; + if (base_auto) + base_commit = "auto"; + if (default_attach) { rev.mime_boundary = default_attach; rev.no_inline = 1; @@ -1973,7 +1976,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) } memset(&bases, 0, sizeof(bases)); - if (base_commit || base_auto) { + if (base_commit) { struct commit *base = get_base_commit(base_commit, list, nr); reset_revision_walk(); clear_object_flags(UNINTERESTING); diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index c7cc643..a5b6302 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' ' 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' ' git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch && sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \ -- cgit v0.10.2-6-g49f6 From cae0bc09abcb12aff79f1aea85d578df7856de4a Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 13:25:11 -0800 Subject: rebase: fix format.useAutoBase breakage With `format.useAutoBase = true`, running rebase resulted in an error: fatal: failed to get upstream, if you want to record base commit automatically, please use git branch --set-upstream-to to track a remote branch. Or you could specify base commit by --base= manually error: git encountered an error while preparing the patches to replay these revisions: ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12 As a result, git cannot rebase them. Fix this by always passing `--no-base` to format-patch from rebase so that the effect of `format.useAutoBase` is negated. Reported-by: Christian Biesinger Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/builtin/rebase.c b/builtin/rebase.c index e755087..51980ab 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1012,7 +1012,8 @@ static int run_am(struct rebase_options *opts) argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout", "--full-index", "--cherry-pick", "--right-only", "--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) argv_array_split(&format_patch.args, opts->git_format_patch_opt.buf); diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index ca99e8c..1323f30 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -159,7 +159,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' ' test_must_fail git rebase ' -test_expect_failure 'rebase works with format.useAutoBase' ' +test_expect_success 'rebase works with format.useAutoBase' ' test_config format.useAutoBase true && git checkout topic && git rebase master -- cgit v0.10.2-6-g49f6