{"thread":{"id":"52353","subject":"Bug with \"git rebase\" when format.useAutoBase is set","startedAt":"2019-11-26T20:50:57Z","lastAt":"2019-12-04T21:25:19Z","messageCount":33,"participants":["Christian Biesinger","Denton Liu","Eric Sunshine","Junio C Hamano","René Scharfe"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387106","messageId":"CAPTJ0XEcMJEwPBEL4akncJ_A5XwyQyKL95fpf2tC0rNXJK65Og@mail.gmail.com","threadId":"52353","inReplyTo":null,"subject":"Bug with \"git rebase\" when format.useAutoBase is set","fromName":"Christian Biesinger","fromEmail":"cbiesinger@google.com","sentAt":"2019-11-26T20:50:18Z","receivedAt":"2019-11-26T20:50:57Z","isPatch":false,"sender":{"key":"cbiesinger@google.com","avatar":null},"body":"Hello!\n\nI recently tried setting the format.useAutoBase setting to true so\nthat patches I send with git format-patch identify their base commit.\n\nUnfortunately this seems to break \"git rebase\" completely, I always\nget the following error. Is this expected? This is with git version\n2.24.0.432.g9d3f5f5b63-goog\n\n$ git rebase --onto  foo 4a7dabea39556979cbf6bcbdd98a9413ce129fd0\nFirst, rewinding head to replay your work on top of it...\nfatal: failed to get upstream, if you want to record base commit automatically,\nplease use git branch --set-upstream-to to track a remote branch.\nOr you could specify base commit by --base=<base-commit-id> manually\nerror:\ngit encountered an error while preparing the patches to replay\nthese revisions:\n\n    4a7dabea39556979cbf6bcbdd98a9413ce129fd0..12f4dc41bf9f018ecc1042830d5534de941f329e\n\nAs a result, git cannot rebase them.\n"},{"id":"387121","messageId":"cover.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"CAPTJ0XEcMJEwPBEL4akncJ_A5XwyQyKL95fpf2tC0rNXJK65Og@mail.gmail.com","subject":"[PATCH 0/5] rebase: fix breakage with `format.useAutoBase`","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:07Z","receivedAt":"2019-11-27T02:09:13Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Thanks for reporting the breakage, Christian.\n\nApparently, this use case has been broken for a long time... Since\nbb52995f3e (format-patch: introduce format.useAutoBase configuration,\n2016-04-26). I'm surprised it's only been reported now.\n\nThis patchset fixes the breakage by teaching\n`git format-patch --no-base` and making rebase use it.\n\nDenton Liu (5):\n  t3400: demonstrate failure with format.useAutoBase\n  format-patch: fix indentation\n  t4014: use `test_config`\n  format-patch: teach --no-base\n  rebase: fix `format.useAutoBase` breakage\n\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 26 ++++++++++++++++++++++----\n builtin/rebase.c                   |  3 ++-\n t/t3400-rebase.sh                  |  6 ++++++\n t/t4014-format-patch.sh            | 14 +++++++++-----\n 5 files changed, 42 insertions(+), 12 deletions(-)\n\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387122","messageId":"a1741e54346a387a65e272f0210118ce81475358.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:11Z","receivedAt":"2019-11-27T02:09:16Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Ever since bb52995f3e (format-patch: introduce format.useAutoBase\nconfiguration, 2016-04-26), `git rebase` has been broken when\n`format.useAutoBase = true`. Demonstrate that failure here.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t3400-rebase.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ab18ac5f28..ca99e8c6c4 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n+test_expect_failure 'rebase works with format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit checkout topic &&\n+\tgit rebase master\n+'\n+\n test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '\n \tgit checkout -b default-base master &&\n \tgit checkout -b default topic &&\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387123","messageId":"46fd4113aad5bd6c9925304eca35c808274982ba.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH 2/5] format-patch: fix indentation","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:14Z","receivedAt":"2019-11-27T02:09:19Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Signed-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/log.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a26f223ab4..9c44682f61 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1350,7 +1350,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)\n \t\tstring_list_clear(&extra_to, 0);\n \t\tstring_list_clear(&extra_cc, 0);\n \t} else {\n-\t    add_header(arg);\n+\t\tadd_header(arg);\n \t}\n \treturn 0;\n }\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387124","messageId":"22b1fb14f9ac841e93b6177cec216530a6756d7c.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH 3/5] t4014: use `test_config`","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:17Z","receivedAt":"2019-11-27T02:09:22Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Instead of manually unsetting the config after the test case is done,\nuse `test_config` to do it automatically. While we're at it, fix a typo\nin a test case name.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t4014-format-patch.sh | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 69267b16f0..c7cc643adf 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'\n \ttest_must_fail \tgit format-patch --base=auto -1\n '\n \n-test_expect_success 'format-patch format.useAutoBaseoption' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n+test_expect_success 'format-patch format.useAutoBase option' '\n \tgit checkout local &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse upstream >commit-id-base &&\n@@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '\n '\n \n test_expect_success 'format-patch --base overrides format.useAutoBase' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout --base=HEAD~1 -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse HEAD~1 >commit-id-base &&\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387125","messageId":"e072c36e6a41ef70d2a15c052c672f94b54ce930.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH 4/5] format-patch: teach --no-base","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:19Z","receivedAt":"2019-11-27T02:09:24Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If `format.useAutoBase = true`, there was no way to override this from\nthe command-line. Teach format-patch the `--no-base` option which\noverrides `format.useAutoBase`.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 24 +++++++++++++++++++++---\n t/t4014-format-patch.sh            |  6 ++++++\n 3 files changed, 30 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 00bdf9b125..0d4f8951bb 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n   Output an all-zero hash in each patch's From header instead\n   of the hash of the commit.\n \n---base=<commit>::\n+--[no-]base[=<commit>]::\n \tRecord the base tree information to identify the state the\n \tpatch series applies to.  See the BASE TREE INFORMATION section\n \tbelow for details. If <commit> is \"auto\", a base commit is\n-\tautomatically chosen.\n+\tautomatically chosen. The `--no-base` option overrides a\n+\t`format.useAutoBase` configuration.\n \n --root::\n \tTreat the revision argument as a <revision range>, even if it\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 9c44682f61..c017df4056 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1388,6 +1388,23 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n \treturn 0;\n }\n \n+static int base_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tchar **base_commit = opt->value;\n+\n+\tfree(*base_commit);\n+\n+\tif (unset) {\n+\t\tbase_auto = 0;\n+\t\t*base_commit = NULL;\n+\t} else if (arg) {\n+\t\t*base_commit = xstrdup(arg);\n+\t} else {\n+\t\tBUG(\"arg is NULL\");\n+\t}\n+\treturn 0;\n+}\n+\n struct base_tree_info {\n \tstruct object_id base_commit;\n \tint nr_patch_id, alloc_patch_id;\n@@ -1676,10 +1693,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n \t\t\t    N_(\"add a signature\")),\n-\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n-\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n+\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n+\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n+\t\t\t   0, base_callback },\n \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n-\t\t\t\tN_(\"add a signature from a file\")),\n+\t\t\tN_(\"add a signature from a file\")),\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_BOOL(0, \"progress\", &show_progress,\n \t\t\t N_(\"show progress while generating patches\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex c7cc643adf..a5b6302a1c 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit format-patch --stdout --no-base -1 >patch &&\n+\t! grep \"^base-commit:\" patch\n+'\n+\n test_expect_success 'format-patch --base with --attach' '\n \tgit format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&\n \tsed -n -e \"/^base-commit:/s/.*/1/p\" -e \"/^---*mimemime--$/s/.*/2/p\" \\\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387126","messageId":"15e6ccb2037d1e27b461d2344a13ebf1d5e10136.1574820308.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH 5/5] rebase: fix `format.useAutoBase` breakage","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T02:09:22Z","receivedAt":"2019-11-27T02:09:28Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"With `format.useAutoBase = true`, running rebase resulted in an\nerror when an upstream was't set:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nFix this by always passing `--no-base` to format-patch from rebase so\nthat the effect of `format.useAutoBase` is negated.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/rebase.c  | 3 ++-\n t/t3400-rebase.sh | 2 +-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex e755087b0f..51980ab63d 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1012,7 +1012,8 @@ static int run_am(struct rebase_options *opts)\n \targv_array_pushl(&format_patch.args, \"format-patch\", \"-k\", \"--stdout\",\n \t\t\t \"--full-index\", \"--cherry-pick\", \"--right-only\",\n \t\t\t \"--src-prefix=a/\", \"--dst-prefix=b/\", \"--no-renames\",\n-\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\", NULL);\n+\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\",\n+\t\t\t \"--no-base\", NULL);\n \tif (opts->git_format_patch_opt.len)\n \t\targv_array_split(&format_patch.args,\n \t\t\t\t opts->git_format_patch_opt.buf);\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ca99e8c6c4..1323f30fee 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,7 +159,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n-test_expect_failure 'rebase works with format.useAutoBase' '\n+test_expect_success 'rebase works with format.useAutoBase' '\n \ttest_config format.useAutoBase true &&\n \tgit checkout topic &&\n \tgit rebase master\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387127","messageId":"CAPig+cTqRcZ6R7bFqeNG_bvwqgAKP7NVEHBSQxgpVk+PgGVMVg@mail.gmail.com","threadId":"52353","inReplyTo":"a1741e54346a387a65e272f0210118ce81475358.1574820308.git.liu.denton@gmail.com","subject":"Re: [PATCH 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-11-27T02:26:58Z","receivedAt":"2019-11-27T02:27:12Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Nov 26, 2019 at 9:09 PM Denton Liu <liu.denton@gmail.com> wrote:\n> Ever since bb52995f3e (format-patch: introduce format.useAutoBase\n> configuration, 2016-04-26), `git rebase` has been broken when\n> `format.useAutoBase = true`. Demonstrate that failure here.\n\nWhat specifically does \"broken\" mean here?\n\n> Reported-by: Christian Biesinger <cbiesinger@google.com>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\n> @@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n> +test_expect_failure 'rebase works with format.useAutoBase' '\n> +       test_config format.useAutoBase true &&\n> +       git checkout topic &&\n> +       git rebase master\n> +'\n\nHaving read both the commit message and the test itself, I'm not wiser\nabout what is actually \"broken\" or what this is demonstrating.\n"},{"id":"387129","messageId":"CAPig+cSH36aPwUDhtkiknpSsas-osCVnJ=cyNUzOgKXdvOCnmw@mail.gmail.com","threadId":"52353","inReplyTo":"15e6ccb2037d1e27b461d2344a13ebf1d5e10136.1574820308.git.liu.denton@gmail.com","subject":"Re: [PATCH 5/5] rebase: fix `format.useAutoBase` breakage","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-11-27T02:42:39Z","receivedAt":"2019-11-27T02:42:54Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Nov 26, 2019 at 9:09 PM Denton Liu <liu.denton@gmail.com> wrote:\n> With `format.useAutoBase = true`, running rebase resulted in an\n> error when an upstream was't set:\n\ns/was't/wasn't/\n\n>         fatal: failed to get upstream, if you want to record base commit automatically,\n>         please use git branch --set-upstream-to to track a remote branch.\n>         Or you could specify base commit by --base=<base-commit-id> manually\n>         error:\n>         git encountered an error while preparing the patches to replay\n>         these revisions:\n>\n>             ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n>\n>         As a result, git cannot rebase them.\n>\n> Fix this by always passing `--no-base` to format-patch from rebase so\n> that the effect of `format.useAutoBase` is negated.\n>\n> Reported-by: Christian Biesinger <cbiesinger@google.com>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n"},{"id":"387184","messageId":"CAPTJ0XH62P_-R4XCy5Jv-egQ06H8eJZ4YhLdRGAt721WVD5bXQ@mail.gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"Re: [PATCH 0/5] rebase: fix breakage with `format.useAutoBase`","fromName":"Christian Biesinger","fromEmail":"cbiesinger@google.com","sentAt":"2019-11-27T17:14:59Z","receivedAt":"2019-11-27T17:15:38Z","isPatch":true,"sender":{"key":"cbiesinger@google.com","avatar":null},"body":"On Tue, Nov 26, 2019 at 8:09 PM Denton Liu <liu.denton@gmail.com> wrote:\n>\n> Thanks for reporting the breakage, Christian.\n>\n> Apparently, this use case has been broken for a long time... Since\n> bb52995f3e (format-patch: introduce format.useAutoBase configuration,\n> 2016-04-26). I'm surprised it's only been reported now.\n\nThanks for fixing! Maybe few people use this option as it's not\ndocumented in the format-patch manpage? (A separate thing to fix, I\nguess)\n\nChristian\n\n> This patchset fixes the breakage by teaching\n> `git format-patch --no-base` and making rebase use it.\n>\n> Denton Liu (5):\n>   t3400: demonstrate failure with format.useAutoBase\n>   format-patch: fix indentation\n>   t4014: use `test_config`\n>   format-patch: teach --no-base\n>   rebase: fix `format.useAutoBase` breakage\n>\n>  Documentation/git-format-patch.txt |  5 +++--\n>  builtin/log.c                      | 26 ++++++++++++++++++++++----\n>  builtin/rebase.c                   |  3 ++-\n>  t/t3400-rebase.sh                  |  6 ++++++\n>  t/t4014-format-patch.sh            | 14 +++++++++-----\n>  5 files changed, 42 insertions(+), 12 deletions(-)\n>\n> --\n> 2.24.0.504.g3cd56eb17d\n>\n"},{"id":"387196","messageId":"cover.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574820308.git.liu.denton@gmail.com","subject":"[PATCH v2 0/5] rebase: fix breakage with `format.useAutoBase`","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:36Z","receivedAt":"2019-11-27T18:13:41Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Apparently, this use case has been broken for a long time... Since\nbb52995f3e (format-patch: introduce format.useAutoBase configuration,\n2016-04-26). I'm surprised it's only been reported now.\n\nThis patchset fixes the breakage by teaching\n`git format-patch --no-base` and making rebase use it.\n\nChanges since v1:\n\n* Update some log messages\n\nDenton Liu (5):\n  t3400: demonstrate failure with format.useAutoBase\n  format-patch: fix indentation\n  t4014: use test_config()\n  format-patch: teach --no-base\n  rebase: fix format.useAutoBase breakage\n\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 26 ++++++++++++++++++++++----\n builtin/rebase.c                   |  3 ++-\n t/t3400-rebase.sh                  |  6 ++++++\n t/t4014-format-patch.sh            | 14 +++++++++-----\n 5 files changed, 42 insertions(+), 12 deletions(-)\n\nRange-diff against v1:\n1:  a1741e5434 ! 1:  4089e51041 t3400: demonstrate failure with format.useAutoBase\n    @@ Commit message\n     \n         Ever since bb52995f3e (format-patch: introduce format.useAutoBase\n         configuration, 2016-04-26), `git rebase` has been broken when\n    -    `format.useAutoBase = true`. Demonstrate that failure here.\n    +    `format.useAutoBase = true`. It fails when rebasing a branch that\n    +    doesn't have an upstream set:\n    +\n    +            fatal: failed to get upstream, if you want to record base commit automatically,\n    +            please use git branch --set-upstream-to to track a remote branch.\n    +            Or you could specify base commit by --base=<base-commit-id> manually\n    +            error:\n    +            git encountered an error while preparing the patches to replay\n    +            these revisions:\n    +\n    +                ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n    +\n    +            As a result, git cannot rebase them.\n    +\n    +    Demonstrate that failure here.\n     \n         Reported-by: Christian Biesinger <cbiesinger@google.com>\n     \n2:  46fd4113aa = 2:  d288d6c3a5 format-patch: fix indentation\n3:  22b1fb14f9 ! 3:  196b5d8dbc t4014: use `test_config`\n    @@ Metadata\n     Author: Denton Liu <liu.denton@gmail.com>\n     \n      ## Commit message ##\n    -    t4014: use `test_config`\n    +    t4014: use test_config()\n     \n         Instead of manually unsetting the config after the test case is done,\n    -    use `test_config` to do it automatically. While we're at it, fix a typo\n    +    use test_config() to do it automatically. While we're at it, fix a typo\n         in a test case name.\n     \n      ## t/t4014-format-patch.sh ##\n4:  e072c36e6a = 4:  f7e5325cc0 format-patch: teach --no-base\n5:  15e6ccb203 ! 5:  62c59c12e3 rebase: fix `format.useAutoBase` breakage\n    @@ Metadata\n     Author: Denton Liu <liu.denton@gmail.com>\n     \n      ## Commit message ##\n    -    rebase: fix `format.useAutoBase` breakage\n    +    rebase: fix format.useAutoBase breakage\n     \n         With `format.useAutoBase = true`, running rebase resulted in an\n    -    error when an upstream was't set:\n    +    error when an upstream wasn't set:\n     \n                 fatal: failed to get upstream, if you want to record base commit automatically,\n                 please use git branch --set-upstream-to to track a remote branch.\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387197","messageId":"4089e51041a9cbd15e62882c370ed254d8e63cfd.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v2 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:39Z","receivedAt":"2019-11-27T18:13:43Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Ever since bb52995f3e (format-patch: introduce format.useAutoBase\nconfiguration, 2016-04-26), `git rebase` has been broken when\n`format.useAutoBase = true`. It fails when rebasing a branch that\ndoesn't have an upstream set:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nDemonstrate that failure here.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t3400-rebase.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ab18ac5f28..ca99e8c6c4 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n+test_expect_failure 'rebase works with format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit checkout topic &&\n+\tgit rebase master\n+'\n+\n test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '\n \tgit checkout -b default-base master &&\n \tgit checkout -b default topic &&\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387198","messageId":"d288d6c3a56fab339b2dfed59579c1acecda4559.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v2 2/5] format-patch: fix indentation","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:41Z","receivedAt":"2019-11-27T18:13:46Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Signed-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/log.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a26f223ab4..9c44682f61 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1350,7 +1350,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)\n \t\tstring_list_clear(&extra_to, 0);\n \t\tstring_list_clear(&extra_cc, 0);\n \t} else {\n-\t    add_header(arg);\n+\t\tadd_header(arg);\n \t}\n \treturn 0;\n }\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387199","messageId":"196b5d8dbccfa550608c9a6c19ae4b7743089f41.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v2 3/5] t4014: use test_config()","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:44Z","receivedAt":"2019-11-27T18:13:48Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Instead of manually unsetting the config after the test case is done,\nuse test_config() to do it automatically. While we're at it, fix a typo\nin a test case name.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t4014-format-patch.sh | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 69267b16f0..c7cc643adf 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'\n \ttest_must_fail \tgit format-patch --base=auto -1\n '\n \n-test_expect_success 'format-patch format.useAutoBaseoption' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n+test_expect_success 'format-patch format.useAutoBase option' '\n \tgit checkout local &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse upstream >commit-id-base &&\n@@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '\n '\n \n test_expect_success 'format-patch --base overrides format.useAutoBase' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout --base=HEAD~1 -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse HEAD~1 >commit-id-base &&\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387200","messageId":"f7e5325cc0a7c29b62abe361e188c7cf9c59a9ca.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v2 4/5] format-patch: teach --no-base","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:46Z","receivedAt":"2019-11-27T18:13:50Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If `format.useAutoBase = true`, there was no way to override this from\nthe command-line. Teach format-patch the `--no-base` option which\noverrides `format.useAutoBase`.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 24 +++++++++++++++++++++---\n t/t4014-format-patch.sh            |  6 ++++++\n 3 files changed, 30 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 00bdf9b125..0d4f8951bb 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n   Output an all-zero hash in each patch's From header instead\n   of the hash of the commit.\n \n---base=<commit>::\n+--[no-]base[=<commit>]::\n \tRecord the base tree information to identify the state the\n \tpatch series applies to.  See the BASE TREE INFORMATION section\n \tbelow for details. If <commit> is \"auto\", a base commit is\n-\tautomatically chosen.\n+\tautomatically chosen. The `--no-base` option overrides a\n+\t`format.useAutoBase` configuration.\n \n --root::\n \tTreat the revision argument as a <revision range>, even if it\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 9c44682f61..c017df4056 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1388,6 +1388,23 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n \treturn 0;\n }\n \n+static int base_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tchar **base_commit = opt->value;\n+\n+\tfree(*base_commit);\n+\n+\tif (unset) {\n+\t\tbase_auto = 0;\n+\t\t*base_commit = NULL;\n+\t} else if (arg) {\n+\t\t*base_commit = xstrdup(arg);\n+\t} else {\n+\t\tBUG(\"arg is NULL\");\n+\t}\n+\treturn 0;\n+}\n+\n struct base_tree_info {\n \tstruct object_id base_commit;\n \tint nr_patch_id, alloc_patch_id;\n@@ -1676,10 +1693,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n \t\t\t    N_(\"add a signature\")),\n-\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n-\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n+\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n+\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n+\t\t\t   0, base_callback },\n \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n-\t\t\t\tN_(\"add a signature from a file\")),\n+\t\t\tN_(\"add a signature from a file\")),\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n \t\tOPT_BOOL(0, \"progress\", &show_progress,\n \t\t\t N_(\"show progress while generating patches\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex c7cc643adf..a5b6302a1c 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit format-patch --stdout --no-base -1 >patch &&\n+\t! grep \"^base-commit:\" patch\n+'\n+\n test_expect_success 'format-patch --base with --attach' '\n \tgit format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&\n \tsed -n -e \"/^base-commit:/s/.*/1/p\" -e \"/^---*mimemime--$/s/.*/2/p\" \\\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387201","messageId":"62c59c12e376dd73317a7e5d78275bca12875340.1574878089.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v2 5/5] rebase: fix format.useAutoBase breakage","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T18:13:48Z","receivedAt":"2019-11-27T18:13:53Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"With `format.useAutoBase = true`, running rebase resulted in an\nerror when an upstream wasn't set:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nFix this by always passing `--no-base` to format-patch from rebase so\nthat the effect of `format.useAutoBase` is negated.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/rebase.c  | 3 ++-\n t/t3400-rebase.sh | 2 +-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex e755087b0f..51980ab63d 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1012,7 +1012,8 @@ static int run_am(struct rebase_options *opts)\n \targv_array_pushl(&format_patch.args, \"format-patch\", \"-k\", \"--stdout\",\n \t\t\t \"--full-index\", \"--cherry-pick\", \"--right-only\",\n \t\t\t \"--src-prefix=a/\", \"--dst-prefix=b/\", \"--no-renames\",\n-\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\", NULL);\n+\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\",\n+\t\t\t \"--no-base\", NULL);\n \tif (opts->git_format_patch_opt.len)\n \t\targv_array_split(&format_patch.args,\n \t\t\t\t opts->git_format_patch_opt.buf);\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ca99e8c6c4..1323f30fee 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,7 +159,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n-test_expect_failure 'rebase works with format.useAutoBase' '\n+test_expect_success 'rebase works with format.useAutoBase' '\n \ttest_config format.useAutoBase true &&\n \tgit checkout topic &&\n \tgit rebase master\n-- \n2.24.0.504.g3cd56eb17d\n\n"},{"id":"387240","messageId":"20191127195615.GA7413@generichostname","threadId":"52353","inReplyTo":"f7e5325cc0a7c29b62abe361e188c7cf9c59a9ca.1574878089.git.liu.denton@gmail.com","subject":"Re: [PATCH v2 4/5] format-patch: teach --no-base","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-11-27T19:56:15Z","receivedAt":"2019-11-27T19:56:19Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"On Wed, Nov 27, 2019 at 10:13:46AM -0800, Denton Liu wrote:\n> If `format.useAutoBase = true`, there was no way to override this from\n> the command-line. Teach format-patch the `--no-base` option which\n> overrides `format.useAutoBase`.\n> \n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n>  Documentation/git-format-patch.txt |  5 +++--\n>  builtin/log.c                      | 24 +++++++++++++++++++++---\n>  t/t4014-format-patch.sh            |  6 ++++++\n>  3 files changed, 30 insertions(+), 5 deletions(-)\n> \n> diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\n> index 00bdf9b125..0d4f8951bb 100644\n> --- a/Documentation/git-format-patch.txt\n> +++ b/Documentation/git-format-patch.txt\n> @@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n>    Output an all-zero hash in each patch's From header instead\n>    of the hash of the commit.\n>  \n> ---base=<commit>::\n> +--[no-]base[=<commit>]::\n>  \tRecord the base tree information to identify the state the\n>  \tpatch series applies to.  See the BASE TREE INFORMATION section\n>  \tbelow for details. If <commit> is \"auto\", a base commit is\n> -\tautomatically chosen.\n> +\tautomatically chosen. The `--no-base` option overrides a\n> +\t`format.useAutoBase` configuration.\n>  \n>  --root::\n>  \tTreat the revision argument as a <revision range>, even if it\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 9c44682f61..c017df4056 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1388,6 +1388,23 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n>  \treturn 0;\n>  }\n>  \n> +static int base_callback(const struct option *opt, const char *arg, int unset)\n> +{\n> +\tchar **base_commit = opt->value;\n> +\n> +\tfree(*base_commit);\n> +\n> +\tif (unset) {\n> +\t\tbase_auto = 0;\n> +\t\t*base_commit = NULL;\n> +\t} else if (arg) {\n> +\t\t*base_commit = xstrdup(arg);\n> +\t} else {\n> +\t\tBUG(\"arg is NULL\");\n> +\t}\n> +\treturn 0;\n> +}\n> +\n>  struct base_tree_info {\n>  \tstruct object_id base_commit;\n>  \tint nr_patch_id, alloc_patch_id;\n> @@ -1676,10 +1693,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n>  \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n>  \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n>  \t\t\t    N_(\"add a signature\")),\n> -\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n> -\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n> +\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n> +\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n> +\t\t\t   0, base_callback },\n>  \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n> -\t\t\t\tN_(\"add a signature from a file\")),\n> +\t\t\tN_(\"add a signature from a file\")),\n\nOops, this is reindentation is a spurious change and should be dropped.\n\n>  \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n>  \t\tOPT_BOOL(0, \"progress\", &show_progress,\n>  \t\t\t N_(\"show progress while generating patches\")),\n> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\n> index c7cc643adf..a5b6302a1c 100755\n> --- a/t/t4014-format-patch.sh\n> +++ b/t/t4014-format-patch.sh\n> @@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success 'format-patch --no-base overrides format.useAutoBase' '\n> +\ttest_config format.useAutoBase true &&\n> +\tgit format-patch --stdout --no-base -1 >patch &&\n> +\t! grep \"^base-commit:\" patch\n> +'\n> +\n>  test_expect_success 'format-patch --base with --attach' '\n>  \tgit format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&\n>  \tsed -n -e \"/^base-commit:/s/.*/1/p\" -e \"/^---*mimemime--$/s/.*/2/p\" \\\n> -- \n> 2.24.0.504.g3cd56eb17d\n> \n"},{"id":"387340","messageId":"xmqqimn12s5l.fsf@gitster-ct.c.googlers.com","threadId":"52353","inReplyTo":"CAPig+cTqRcZ6R7bFqeNG_bvwqgAKP7NVEHBSQxgpVk+PgGVMVg@mail.gmail.com","subject":"Re: [PATCH 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-11-30T17:25:10Z","receivedAt":"2019-11-30T17:25:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Tue, Nov 26, 2019 at 9:09 PM Denton Liu <liu.denton@gmail.com> wrote:\n>> Ever since bb52995f3e (format-patch: introduce format.useAutoBase\n>> configuration, 2016-04-26), `git rebase` has been broken when\n>> `format.useAutoBase = true`. Demonstrate that failure here.\n>\n> What specifically does \"broken\" mean here?\n>\n>> Reported-by: Christian Biesinger <cbiesinger@google.com>\n>> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n>> ---\n>> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\n>> @@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n>> +test_expect_failure 'rebase works with format.useAutoBase' '\n>> +       test_config format.useAutoBase true &&\n>> +       git checkout topic &&\n>> +       git rebase master\n>> +'\n>\n> Having read both the commit message and the test itself, I'm not wiser\n> about what is actually \"broken\" or what this is demonstrating.\n\nTrue.\n\nThe tests must be crystal clear what kind of brokenness it is\ndemonstrating, not just \"this test is expected to fail\", especially\nwhen the \"expect failure in one step, fix and flip expectation in a\nseparate step\" pattern is used; otherwise it becomes doubly puzzling.\n\nThanks.\n"},{"id":"387480","messageId":"cover.1575445582.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1574878089.git.liu.denton@gmail.com","subject":"[PATCH v3 0/5] rebase: fix breakage with `format.useAutoBase`","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:47:49Z","receivedAt":"2019-12-04T07:47:53Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Apparently, this use case has been broken for a long time... Since\nbb52995f3e (format-patch: introduce format.useAutoBase configuration,\n2016-04-26). I'm surprised it's only been reported now.\n\nThis patchset fixes the breakage by teaching\n`git format-patch --no-base` and making rebase use it.\n\nThis patch is based on the latest master since it's such an old bug that\nonly got noticed recently, I'm not sure if it's worth fixing in 'maint'.\nThe series does not apply cleanly on top of 'maint' because it relies on\nc1a6f21cd4 (Doc: add more detail for git-format-patch, 2019-08-27) but\nthe conflicts are relatively minor.\n\nChanges since v2:\n\n* Remove spurious indentation change\n\n* Rebase onto the latest master\n\nChanges since v1:\n\n* Update some log messages\n\nDenton Liu (5):\n  t3400: demonstrate failure with format.useAutoBase\n  format-patch: fix indentation\n  t4014: use test_config()\n  format-patch: teach --no-base\n  rebase: fix format.useAutoBase breakage\n\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 24 +++++++++++++++++++++---\n builtin/rebase.c                   |  3 ++-\n t/t3400-rebase.sh                  |  6 ++++++\n t/t4014-format-patch.sh            | 14 +++++++++-----\n 5 files changed, 41 insertions(+), 11 deletions(-)\n\nRange-diff against v2:\n1:  4089e51041 = 1:  8d67bbe5bf t3400: demonstrate failure with format.useAutoBase\n2:  d288d6c3a5 = 2:  8cfde9f98e format-patch: fix indentation\n3:  196b5d8dbc = 3:  638c4add00 t4014: use test_config()\n4:  f7e5325cc0 ! 4:  6cba51ca24 format-patch: teach --no-base\n    @@ builtin/log.c: int cmd_format_patch(int argc, const char **argv, const char *pre\n     +\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n     +\t\t\t   0, base_callback },\n      \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n    --\t\t\t\tN_(\"add a signature from a file\")),\n    -+\t\t\tN_(\"add a signature from a file\")),\n    + \t\t\t\tN_(\"add a signature from a file\")),\n      \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n    - \t\tOPT_BOOL(0, \"progress\", &show_progress,\n    - \t\t\t N_(\"show progress while generating patches\")),\n     \n      ## t/t4014-format-patch.sh ##\n     @@ t/t4014-format-patch.sh: test_expect_success 'format-patch --base overrides format.useAutoBase' '\n5:  62c59c12e3 = 5:  eb266aaedc rebase: fix format.useAutoBase breakage\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387481","messageId":"8d67bbe5bfb7b09dff9687a06acb92fbf8202699.1575445583.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v3 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:47:51Z","receivedAt":"2019-12-04T07:48:03Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Ever since bb52995f3e (format-patch: introduce format.useAutoBase\nconfiguration, 2016-04-26), `git rebase` has been broken when\n`format.useAutoBase = true`. It fails when rebasing a branch that\ndoesn't have an upstream set:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nDemonstrate that failure here.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t3400-rebase.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ab18ac5f28..ca99e8c6c4 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n+test_expect_failure 'rebase works with format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit checkout topic &&\n+\tgit rebase master\n+'\n+\n test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '\n \tgit checkout -b default-base master &&\n \tgit checkout -b default topic &&\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387482","messageId":"8cfde9f98e416aa44bc27e71d200990fd4d83ae6.1575445583.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v3 2/5] format-patch: fix indentation","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:47:54Z","receivedAt":"2019-12-04T07:48:03Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Signed-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/log.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a26f223ab4..9c44682f61 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1350,7 +1350,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)\n \t\tstring_list_clear(&extra_to, 0);\n \t\tstring_list_clear(&extra_cc, 0);\n \t} else {\n-\t    add_header(arg);\n+\t\tadd_header(arg);\n \t}\n \treturn 0;\n }\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387483","messageId":"6cba51ca247423c76bda498152c162900aba1b59.1575445583.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v3 4/5] format-patch: teach --no-base","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:47:59Z","receivedAt":"2019-12-04T07:48:04Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If `format.useAutoBase = true`, there was no way to override this from\nthe command-line. Teach format-patch the `--no-base` option which\noverrides `format.useAutoBase`.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      | 22 ++++++++++++++++++++--\n t/t4014-format-patch.sh            |  6 ++++++\n 3 files changed, 29 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 00bdf9b125..0d4f8951bb 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n   Output an all-zero hash in each patch's From header instead\n   of the hash of the commit.\n \n---base=<commit>::\n+--[no-]base[=<commit>]::\n \tRecord the base tree information to identify the state the\n \tpatch series applies to.  See the BASE TREE INFORMATION section\n \tbelow for details. If <commit> is \"auto\", a base commit is\n-\tautomatically chosen.\n+\tautomatically chosen. The `--no-base` option overrides a\n+\t`format.useAutoBase` configuration.\n \n --root::\n \tTreat the revision argument as a <revision range>, even if it\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 9c44682f61..645d6db7cc 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1388,6 +1388,23 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n \treturn 0;\n }\n \n+static int base_callback(const struct option *opt, const char *arg, int unset)\n+{\n+\tchar **base_commit = opt->value;\n+\n+\tfree(*base_commit);\n+\n+\tif (unset) {\n+\t\tbase_auto = 0;\n+\t\t*base_commit = NULL;\n+\t} else if (arg) {\n+\t\t*base_commit = xstrdup(arg);\n+\t} else {\n+\t\tBUG(\"arg is NULL\");\n+\t}\n+\treturn 0;\n+}\n+\n struct base_tree_info {\n \tstruct object_id base_commit;\n \tint nr_patch_id, alloc_patch_id;\n@@ -1676,8 +1693,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n \t\t\t    N_(\"add a signature\")),\n-\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n-\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n+\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n+\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n+\t\t\t   0, base_callback },\n \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n \t\t\t\tN_(\"add a signature from a file\")),\n \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex c7cc643adf..a5b6302a1c 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit format-patch --stdout --no-base -1 >patch &&\n+\t! grep \"^base-commit:\" patch\n+'\n+\n test_expect_success 'format-patch --base with --attach' '\n \tgit format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&\n \tsed -n -e \"/^base-commit:/s/.*/1/p\" -e \"/^---*mimemime--$/s/.*/2/p\" \\\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387484","messageId":"638c4add00657daa9b7a4fa50882053335d5caef.1575445583.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v3 3/5] t4014: use test_config()","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:47:56Z","receivedAt":"2019-12-04T07:48:04Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Instead of manually unsetting the config after the test case is done,\nuse test_config() to do it automatically. While we're at it, fix a typo\nin a test case name.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t4014-format-patch.sh | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 69267b16f0..c7cc643adf 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'\n \ttest_must_fail \tgit format-patch --base=auto -1\n '\n \n-test_expect_success 'format-patch format.useAutoBaseoption' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n+test_expect_success 'format-patch format.useAutoBase option' '\n \tgit checkout local &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse upstream >commit-id-base &&\n@@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '\n '\n \n test_expect_success 'format-patch --base overrides format.useAutoBase' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout --base=HEAD~1 -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse HEAD~1 >commit-id-base &&\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387485","messageId":"eb266aaedcfb346b405a7a7073caa6b6482480fe.1575445583.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v3 5/5] rebase: fix format.useAutoBase breakage","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T07:48:01Z","receivedAt":"2019-12-04T07:48:07Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"With `format.useAutoBase = true`, running rebase resulted in an\nerror when an upstream wasn't set:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nFix this by always passing `--no-base` to format-patch from rebase so\nthat the effect of `format.useAutoBase` is negated.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/rebase.c  | 3 ++-\n t/t3400-rebase.sh | 2 +-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex e755087b0f..51980ab63d 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1012,7 +1012,8 @@ static int run_am(struct rebase_options *opts)\n \targv_array_pushl(&format_patch.args, \"format-patch\", \"-k\", \"--stdout\",\n \t\t\t \"--full-index\", \"--cherry-pick\", \"--right-only\",\n \t\t\t \"--src-prefix=a/\", \"--dst-prefix=b/\", \"--no-renames\",\n-\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\", NULL);\n+\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\",\n+\t\t\t \"--no-base\", NULL);\n \tif (opts->git_format_patch_opt.len)\n \t\targv_array_split(&format_patch.args,\n \t\t\t\t opts->git_format_patch_opt.buf);\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ca99e8c6c4..1323f30fee 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,7 +159,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n-test_expect_failure 'rebase works with format.useAutoBase' '\n+test_expect_success 'rebase works with format.useAutoBase' '\n \ttest_config format.useAutoBase true &&\n \tgit checkout topic &&\n \tgit rebase master\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387486","messageId":"3d355c0c-805a-a55d-eb4e-e4918585e30c@web.de","threadId":"52353","inReplyTo":"6cba51ca247423c76bda498152c162900aba1b59.1575445583.git.liu.denton@gmail.com","subject":"Re: [PATCH v3 4/5] format-patch: teach --no-base","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-12-04T10:36:25Z","receivedAt":"2019-12-04T10:36:45Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 04.12.19 um 08:47 schrieb Denton Liu:\n> If `format.useAutoBase = true`, there was no way to override this from\n> the command-line. Teach format-patch the `--no-base` option which\n> overrides `format.useAutoBase`.\n\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 9c44682f61..645d6db7cc 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1388,6 +1388,23 @@ static int from_callback(const struct option *opt, const char *arg, int unset)\n>  \treturn 0;\n>  }\n>\n> +static int base_callback(const struct option *opt, const char *arg, int unset)\n> +{\n> +\tchar **base_commit = opt->value;\n> +\n> +\tfree(*base_commit);\n> +\n> +\tif (unset) {\n> +\t\tbase_auto = 0;\n> +\t\t*base_commit = NULL;\n> +\t} else if (arg) {\n> +\t\t*base_commit = xstrdup(arg);\n> +\t} else {\n> +\t\tBUG(\"arg is NULL\");\n> +\t}\n> +\treturn 0;\n> +}\n> +\n>  struct base_tree_info {\n>  \tstruct object_id base_commit;\n>  \tint nr_patch_id, alloc_patch_id;\n> @@ -1676,8 +1693,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n>  \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n>  \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n>  \t\t\t    N_(\"add a signature\")),\n> -\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n> -\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n> +\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n> +\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n> +\t\t\t   0, base_callback },\n>  \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n>  \t\t\t\tN_(\"add a signature from a file\")),\n>  \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n\nClearing the global variable base_auto feels unclean to me, as does the\nintroduction of a callback for that purpose.  Why not set base_commit\nafter reading the config and before parsing command line options to\nreflect base_auto?  That would achieve the intended precedence in a\nsimpler way, something like this:\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a26f223ab4..af1b0d0209 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1714,6 +1714,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\trev.mime_boundary = default_attach;\n \t\trev.no_inline = 1;\n \t}\n+\tif (base_auto)\n+\t\tbase_commit = \"auto\";\n\n \t/*\n \t * Parse the arguments before setup_revisions(), or something\n@@ -1973,7 +1975,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t}\n\n \tmemset(&bases, 0, sizeof(bases));\n-\tif (base_commit || base_auto) {\n+\tif (base_commit) {\n \t\tstruct commit *base = get_base_commit(base_commit, list, nr);\n \t\treset_revision_walk();\n \t\tclear_object_flags(UNINTERESTING);\n\n"},{"id":"387490","messageId":"CAPTJ0XEZ9ydM-EkuJfarK6epChDLsj9tZsb_KxH8BMYmv-PB7g@mail.gmail.com","threadId":"52353","inReplyTo":"62c59c12e376dd73317a7e5d78275bca12875340.1574878089.git.liu.denton@gmail.com","subject":"Re: [PATCH v2 5/5] rebase: fix format.useAutoBase breakage","fromName":"Christian Biesinger","fromEmail":"cbiesinger@google.com","sentAt":"2019-12-04T16:21:44Z","receivedAt":"2019-12-04T16:22:26Z","isPatch":true,"sender":{"key":"cbiesinger@google.com","avatar":null},"body":"On Wed, Nov 27, 2019 at 12:13 PM Denton Liu <liu.denton@gmail.com> wrote:\n>\n> With `format.useAutoBase = true`, running rebase resulted in an\n> error when an upstream wasn't set:\n\nFWIW, this also failed for me when an upstream was set.\n\nChristian\n"},{"id":"387495","messageId":"xmqq5ziw57ew.fsf@gitster-ct.c.googlers.com","threadId":"52353","inReplyTo":"3d355c0c-805a-a55d-eb4e-e4918585e30c@web.de","subject":"Re: [PATCH v3 4/5] format-patch: teach --no-base","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-04T17:26:15Z","receivedAt":"2019-12-04T17:26:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Clearing the global variable base_auto feels unclean to me, as does the\n> introduction of a callback for that purpose.  Why not set base_commit\n> after reading the config and before parsing command line options to\n> reflect base_auto?  That would achieve the intended precedence in a\n> simpler way, something like this:\n\nNice.\n\n\n>\n> diff --git a/builtin/log.c b/builtin/log.c\n> index a26f223ab4..af1b0d0209 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1714,6 +1714,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n>  \t\trev.mime_boundary = default_attach;\n>  \t\trev.no_inline = 1;\n>  \t}\n> +\tif (base_auto)\n> +\t\tbase_commit = \"auto\";\n>\n>  \t/*\n>  \t * Parse the arguments before setup_revisions(), or something\n> @@ -1973,7 +1975,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n>  \t}\n>\n>  \tmemset(&bases, 0, sizeof(bases));\n> -\tif (base_commit || base_auto) {\n> +\tif (base_commit) {\n>  \t\tstruct commit *base = get_base_commit(base_commit, list, nr);\n>  \t\treset_revision_walk();\n>  \t\tclear_object_flags(UNINTERESTING);\n"},{"id":"387512","messageId":"cover.1575494617.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575445582.git.liu.denton@gmail.com","subject":"[PATCH v4 0/5] rebase: fix breakage with `format.useAutoBase`","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:24:44Z","receivedAt":"2019-12-04T21:24:52Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Apparently, this use case has been broken for a long time... Since\nbb52995f3e (format-patch: introduce format.useAutoBase configuration,\n2016-04-26). I'm surprised it's only been reported now.\n\nThis patchset fixes the breakage by teaching\n`git format-patch --no-base` and making rebase use it.\n\nThis patch is based on the latest master since it's such an old bug that\nonly got noticed recently, I'm not sure if it's worth fixing in 'maint'.\nThe series does not apply cleanly on top of 'maint' because it relies on\nc1a6f21cd4 (Doc: add more detail for git-format-patch, 2019-08-27) but\nthe conflicts are relatively minor.\n\nChanges since v3:\n\n* Correct error in log messages more precise by saying that rebases fail\n  in general (even if an upstream is set)\n\n* Change ugly use of OPT_CALLBACK into a more elegant form\n\nChanges since v2:\n\n* Remove spurious indentation change\n\n* Rebase onto the latest master\n\nChanges since v1:\n\n* Update some log messages\n\nDenton Liu (5):\n  t3400: demonstrate failure with format.useAutoBase\n  format-patch: fix indentation\n  t4014: use test_config()\n  format-patch: teach --no-base\n  rebase: fix format.useAutoBase breakage\n\n Documentation/git-format-patch.txt |  5 +++--\n builtin/log.c                      |  9 ++++++---\n builtin/rebase.c                   |  3 ++-\n t/t3400-rebase.sh                  |  6 ++++++\n t/t4014-format-patch.sh            | 14 +++++++++-----\n 5 files changed, 26 insertions(+), 11 deletions(-)\n\nRange-diff against v3:\n1:  78b928bf49 ! 1:  386148a550 t3400: demonstrate failure with format.useAutoBase\n    @@ Commit message\n     \n         Ever since bb52995f3e (format-patch: introduce format.useAutoBase\n         configuration, 2016-04-26), `git rebase` has been broken when\n    -    `format.useAutoBase = true`. It fails when rebasing a branch that\n    -    doesn't have an upstream set:\n    +    `format.useAutoBase = true`. It fails when rebasing a branch:\n     \n                 fatal: failed to get upstream, if you want to record base commit automatically,\n                 please use git branch --set-upstream-to to track a remote branch.\n2:  5435a04427 = 2:  0464bd61c2 format-patch: fix indentation\n3:  455f2df08d = 3:  a55eacbad7 t4014: use test_config()\n4:  7c7b94c0c4 ! 4:  eb35de8f49 format-patch: teach --no-base\n    @@ Commit message\n         format-patch: teach --no-base\n     \n         If `format.useAutoBase = true`, there was no way to override this from\n    -    the command-line. Teach format-patch the `--no-base` option which\n    -    overrides `format.useAutoBase`.\n    +    the command-line. Teach the `--no-base` option in format-patch to\n    +    override `format.useAutoBase`.\n    +\n    +    Helped-by: René Scharfe <l.s.r@web.de>\n     \n      ## Documentation/git-format-patch.txt ##\n     @@ Documentation/git-format-patch.txt: you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n    @@ Documentation/git-format-patch.txt: you can use `--suffix=-patch` to get `0001-d\n      \tTreat the revision argument as a <revision range>, even if it\n     \n      ## builtin/log.c ##\n    -@@ builtin/log.c: static int from_callback(const struct option *opt, const char *arg, int unset)\n    - \treturn 0;\n    - }\n    - \n    -+static int base_callback(const struct option *opt, const char *arg, int unset)\n    -+{\n    -+\tchar **base_commit = opt->value;\n    -+\n    -+\tfree(*base_commit);\n    -+\n    -+\tif (unset) {\n    -+\t\tbase_auto = 0;\n    -+\t\t*base_commit = NULL;\n    -+\t} else if (arg) {\n    -+\t\t*base_commit = xstrdup(arg);\n    -+\t} else {\n    -+\t\tBUG(\"arg is NULL\");\n    -+\t}\n    -+\treturn 0;\n    -+}\n    -+\n    - struct base_tree_info {\n    - \tstruct object_id base_commit;\n    - \tint nr_patch_id, alloc_patch_id;\n    +@@ builtin/log.c: static struct commit *get_base_commit(const char *base_commit,\n    + \t\tbase = lookup_commit_reference_by_name(base_commit);\n    + \t\tif (!base)\n    + \t\t\tdie(_(\"unknown commit %s\"), base_commit);\n    +-\t} else if ((base_commit && !strcmp(base_commit, \"auto\")) || base_auto) {\n    ++\t} else if ((base_commit && !strcmp(base_commit, \"auto\"))) {\n    + \t\tstruct branch *curr_branch = branch_get(NULL);\n    + \t\tconst char *upstream = branch_get_upstream(curr_branch, NULL);\n    + \t\tif (upstream) {\n     @@ builtin/log.c: int cmd_format_patch(int argc, const char **argv, const char *prefix)\n    - \t\t\t    PARSE_OPT_OPTARG, thread_callback },\n    - \t\tOPT_STRING(0, \"signature\", &signature, N_(\"signature\"),\n    - \t\t\t    N_(\"add a signature\")),\n    --\t\tOPT_STRING(0, \"base\", &base_commit, N_(\"base-commit\"),\n    --\t\t\t   N_(\"add prerequisite tree info to the patch series\")),\n    -+\t\t{ OPTION_CALLBACK, 0, \"base\", &base_commit, N_(\"base-commit\"),\n    -+\t\t\t   N_(\"add prerequisite tree info to the patch series\"),\n    -+\t\t\t   0, base_callback },\n    - \t\tOPT_FILENAME(0, \"signature-file\", &signature_file,\n    --\t\t\t\tN_(\"add a signature from a file\")),\n    -+\t\t\tN_(\"add a signature from a file\")),\n    - \t\tOPT__QUIET(&quiet, N_(\"don't print the patch filenames\")),\n    - \t\tOPT_BOOL(0, \"progress\", &show_progress,\n    - \t\t\t N_(\"show progress while generating patches\")),\n    + \ts_r_opt.def = \"HEAD\";\n    + \ts_r_opt.revarg_opt = REVARG_COMMITTISH;\n    + \n    ++\tif (base_auto)\n    ++\t\tbase_commit = \"auto\";\n    ++\n    + \tif (default_attach) {\n    + \t\trev.mime_boundary = default_attach;\n    + \t\trev.no_inline = 1;\n    +@@ builtin/log.c: int cmd_format_patch(int argc, const char **argv, const char *prefix)\n    + \t}\n    + \n    + \tmemset(&bases, 0, sizeof(bases));\n    +-\tif (base_commit || base_auto) {\n    ++\tif (base_commit) {\n    + \t\tstruct commit *base = get_base_commit(base_commit, list, nr);\n    + \t\treset_revision_walk();\n    + \t\tclear_object_flags(UNINTERESTING);\n     \n      ## t/t4014-format-patch.sh ##\n     @@ t/t4014-format-patch.sh: test_expect_success 'format-patch --base overrides format.useAutoBase' '\n5:  2b4166e371 ! 5:  210905f163 rebase: fix format.useAutoBase breakage\n    @@ Commit message\n         rebase: fix format.useAutoBase breakage\n     \n         With `format.useAutoBase = true`, running rebase resulted in an\n    -    error when an upstream wasn't set:\n    +    error:\n     \n                 fatal: failed to get upstream, if you want to record base commit automatically,\n                 please use git branch --set-upstream-to to track a remote branch.\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387513","messageId":"386148a550bdbd06e3c35cd506f69c229a4df664.1575494618.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575494617.git.liu.denton@gmail.com","subject":"[PATCH v4 1/5] t3400: demonstrate failure with format.useAutoBase","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:24:50Z","receivedAt":"2019-12-04T21:25:00Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Ever since bb52995f3e (format-patch: introduce format.useAutoBase\nconfiguration, 2016-04-26), `git rebase` has been broken when\n`format.useAutoBase = true`. It fails when rebasing a branch:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nDemonstrate that failure here.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t3400-rebase.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ab18ac5f28..ca99e8c6c4 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n+test_expect_failure 'rebase works with format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit checkout topic &&\n+\tgit rebase master\n+'\n+\n test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '\n \tgit checkout -b default-base master &&\n \tgit checkout -b default topic &&\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387514","messageId":"0464bd61c26109bc6d98ac56bb8bf1fe9d1a6864.1575494618.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575494617.git.liu.denton@gmail.com","subject":"[PATCH v4 2/5] format-patch: fix indentation","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:24:55Z","receivedAt":"2019-12-04T21:25:02Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Signed-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/log.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex a26f223ab4..9c44682f61 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1350,7 +1350,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)\n \t\tstring_list_clear(&extra_to, 0);\n \t\tstring_list_clear(&extra_cc, 0);\n \t} else {\n-\t    add_header(arg);\n+\t\tadd_header(arg);\n \t}\n \treturn 0;\n }\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387516","messageId":"a55eacbad7ca0f15d038fa61d33190b1beb663a7.1575494618.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575494617.git.liu.denton@gmail.com","subject":"[PATCH v4 3/5] t4014: use test_config()","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:25:00Z","receivedAt":"2019-12-04T21:25:08Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"Instead of manually unsetting the config after the test case is done,\nuse test_config() to do it automatically. While we're at it, fix a typo\nin a test case name.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n t/t4014-format-patch.sh | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 69267b16f0..c7cc643adf 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'\n \ttest_must_fail \tgit format-patch --base=auto -1\n '\n \n-test_expect_success 'format-patch format.useAutoBaseoption' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n+test_expect_success 'format-patch format.useAutoBase option' '\n \tgit checkout local &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse upstream >commit-id-base &&\n@@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '\n '\n \n test_expect_success 'format-patch --base overrides format.useAutoBase' '\n-\ttest_when_finished \"git config --unset format.useAutoBase\" &&\n-\tgit config format.useAutoBase true &&\n+\ttest_config format.useAutoBase true &&\n \tgit format-patch --stdout --base=HEAD~1 -1 >patch &&\n \tgrep \"^base-commit:\" patch >actual &&\n \tgit rev-parse HEAD~1 >commit-id-base &&\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387517","messageId":"eb35de8f4917a406d886a6da4180d2d90e95e633.1575494618.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575494617.git.liu.denton@gmail.com","subject":"[PATCH v4 4/5] format-patch: teach --no-base","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:25:06Z","receivedAt":"2019-12-04T21:25:13Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"If `format.useAutoBase = true`, there was no way to override this from\nthe command-line. Teach the `--no-base` option in format-patch to\noverride `format.useAutoBase`.\n\nHelped-by: René Scharfe <l.s.r@web.de>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/git-format-patch.txt | 5 +++--\n builtin/log.c                      | 7 +++++--\n t/t4014-format-patch.sh            | 6 ++++++\n 3 files changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex 00bdf9b125..0d4f8951bb 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.\n   Output an all-zero hash in each patch's From header instead\n   of the hash of the commit.\n \n---base=<commit>::\n+--[no-]base[=<commit>]::\n \tRecord the base tree information to identify the state the\n \tpatch series applies to.  See the BASE TREE INFORMATION section\n \tbelow for details. If <commit> is \"auto\", a base commit is\n-\tautomatically chosen.\n+\tautomatically chosen. The `--no-base` option overrides a\n+\t`format.useAutoBase` configuration.\n \n --root::\n \tTreat the revision argument as a <revision range>, even if it\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 9c44682f61..bf904e887f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1406,7 +1406,7 @@ static struct commit *get_base_commit(const char *base_commit,\n \t\tbase = lookup_commit_reference_by_name(base_commit);\n \t\tif (!base)\n \t\t\tdie(_(\"unknown commit %s\"), base_commit);\n-\t} else if ((base_commit && !strcmp(base_commit, \"auto\")) || base_auto) {\n+\t} else if ((base_commit && !strcmp(base_commit, \"auto\"))) {\n \t\tstruct branch *curr_branch = branch_get(NULL);\n \t\tconst char *upstream = branch_get_upstream(curr_branch, NULL);\n \t\tif (upstream) {\n@@ -1710,6 +1710,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \ts_r_opt.def = \"HEAD\";\n \ts_r_opt.revarg_opt = REVARG_COMMITTISH;\n \n+\tif (base_auto)\n+\t\tbase_commit = \"auto\";\n+\n \tif (default_attach) {\n \t\trev.mime_boundary = default_attach;\n \t\trev.no_inline = 1;\n@@ -1973,7 +1976,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t}\n \n \tmemset(&bases, 0, sizeof(bases));\n-\tif (base_commit || base_auto) {\n+\tif (base_commit) {\n \t\tstruct commit *base = get_base_commit(base_commit, list, nr);\n \t\treset_revision_walk();\n \t\tclear_object_flags(UNINTERESTING);\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex c7cc643adf..a5b6302a1c 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '\n+\ttest_config format.useAutoBase true &&\n+\tgit format-patch --stdout --no-base -1 >patch &&\n+\t! grep \"^base-commit:\" patch\n+'\n+\n test_expect_success 'format-patch --base with --attach' '\n \tgit format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&\n \tsed -n -e \"/^base-commit:/s/.*/1/p\" -e \"/^---*mimemime--$/s/.*/2/p\" \\\n-- \n2.24.0.578.g4820254054\n\n"},{"id":"387518","messageId":"210905f16303e9ce7ae3845e252bc07e288f70c1.1575494618.git.liu.denton@gmail.com","threadId":"52353","inReplyTo":"cover.1575494617.git.liu.denton@gmail.com","subject":"[PATCH v4 5/5] rebase: fix format.useAutoBase breakage","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2019-12-04T21:25:11Z","receivedAt":"2019-12-04T21:25:19Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"With `format.useAutoBase = true`, running rebase resulted in an\nerror:\n\n\tfatal: failed to get upstream, if you want to record base commit automatically,\n\tplease use git branch --set-upstream-to to track a remote branch.\n\tOr you could specify base commit by --base=<base-commit-id> manually\n\terror:\n\tgit encountered an error while preparing the patches to replay\n\tthese revisions:\n\n\t    ede2467cdedc63784887b587a61c36b7850ebfac..d8f581194799ae29bf5fa72a98cbae98a1198b12\n\n\tAs a result, git cannot rebase them.\n\nFix this by always passing `--no-base` to format-patch from rebase so\nthat the effect of `format.useAutoBase` is negated.\n\nReported-by: Christian Biesinger <cbiesinger@google.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n builtin/rebase.c  | 3 ++-\n t/t3400-rebase.sh | 2 +-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex e755087b0f..51980ab63d 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1012,7 +1012,8 @@ static int run_am(struct rebase_options *opts)\n \targv_array_pushl(&format_patch.args, \"format-patch\", \"-k\", \"--stdout\",\n \t\t\t \"--full-index\", \"--cherry-pick\", \"--right-only\",\n \t\t\t \"--src-prefix=a/\", \"--dst-prefix=b/\", \"--no-renames\",\n-\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\", NULL);\n+\t\t\t \"--no-cover-letter\", \"--pretty=mboxrd\", \"--topo-order\",\n+\t\t\t \"--no-base\", NULL);\n \tif (opts->git_format_patch_opt.len)\n \t\targv_array_split(&format_patch.args,\n \t\t\t\t opts->git_format_patch_opt.buf);\ndiff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh\nindex ca99e8c6c4..1323f30fee 100755\n--- a/t/t3400-rebase.sh\n+++ b/t/t3400-rebase.sh\n@@ -159,7 +159,7 @@ test_expect_success 'fail when upstream arg is missing and not configured' '\n \ttest_must_fail git rebase\n '\n \n-test_expect_failure 'rebase works with format.useAutoBase' '\n+test_expect_success 'rebase works with format.useAutoBase' '\n \ttest_config format.useAutoBase true &&\n \tgit checkout topic &&\n \tgit rebase master\n-- \n2.24.0.578.g4820254054\n\n"}]}