{"thread":{"id":"57200","subject":"[PATCH v2] builtin/pull.c: teach run_merge() to honor rebase.autostash config","startedAt":"2022-01-06T14:59:06Z","lastAt":"2022-01-06T14:59:06Z","messageCount":1,"participants":["John Cai"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"445624","messageId":"20220106145851.77154-1-johncai86@gmail.com","threadId":"57200","inReplyTo":null,"subject":"[PATCH v2] builtin/pull.c: teach run_merge() to honor rebase.autostash config","fromName":"John Cai","fromEmail":"johncai86@gmail.com","sentAt":"2022-01-06T14:58:51Z","receivedAt":"2022-01-06T14:59:06Z","isPatch":true,"sender":{"key":"johncai86@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2354211?v=4"},"body":"On a git pull --rebase, if fast forward is possible we run merge.\nHowever, merge will not honor rebase.autostash if it is configured. This\nhas the unfortunate result of\n\n$ git config rebase.autostash true\n$ git pull --rebase\n\nto ignore the rebase.autostash value.\n\nAllow run_merge() to honor rebase.autostash by passing in\nconfig_autostash if --autostash or --no-autostash flags are not\nexplicitly set.\n\nReported-by: \"Tilman Vogel\" <tilman.vogel@web.de>\nCo-authored-by: \"Junio C Hamano\" <gister@pobox.com>\nSigned-off-by: \"John Cai\" <johncai86@gmail.com>\n---\n\nNotes:\n    Fix a bug that prevents git pull --rebase from honoring the rebase.autostash\n    config value.\n\n    Changes since V1:\n    - used simpler fix as proposed by Junio\n    - removed redundant test cases\n\n builtin/pull.c          |  9 ++++++++-\n t/t5521-pull-options.sh | 12 ++++++++++++\n 2 files changed, 20 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 100cbf9fb8..8423e420ee 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -1133,7 +1133,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"cannot rebase with locally recorded submodule modifications\"));\n \n \t\tif (can_ff) {\n-\t\t\t/* we can fast-forward this without invoking rebase */\n+\t\t\t/*\n+\t\t\t* We can fast-forward without invoking\n+\t\t\t* rebase, by calling run_merge().  But we\n+\t\t\t* have to allow rebase.autostash=true to kick\n+\t\t\t* in.\n+\t\t\t*/\n+\t\t\tif (opt_autostash < 0)\n+\t\t\t\topt_autostash = config_autostash;\n \t\t\topt_ff = \"--ff-only\";\n \t\t\tret = run_merge();\n \t\t} else {\ndiff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh\nindex 66cfcb09c5..66fac99d2b 100755\n--- a/t/t5521-pull-options.sh\n+++ b/t/t5521-pull-options.sh\n@@ -252,4 +252,16 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '\n \ttest_must_fail git -C dst pull --no-ff --no-verify --verify\n '\n \n+test_expect_success 'git pull --rebase --autostash succeeds on ff' '\n+\ttest_when_finished \"rm -fr src dst actual\" &&\n+\tgit init src &&\n+\ttest_commit -C src \"initial\" file \"content\" &&\n+\tgit clone src dst &&\n+\ttest_commit -C src --printf \"more_content\" file \"more content\\ncontent\\n\" &&\n+\techo \"dirty\" >>dst/file &&\n+\tgit -C dst pull --rebase --autostash >actual 2>&1 &&\n+\tgrep -q \"Fast-forward\" actual &&\n+\tgrep -q \"Applied autostash.\" actual\n+'\n+\n test_done\n-- \n2.34.1\n\n"}]}