From patchwork Sat Dec 12 16:52:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11970139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00B4FC4361B for ; Sat, 12 Dec 2020 16:53:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB3D42246B for ; Sat, 12 Dec 2020 16:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbgLLQxJ (ORCPT ); Sat, 12 Dec 2020 11:53:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407685AbgLLQww (ORCPT ); Sat, 12 Dec 2020 11:52:52 -0500 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7684DC0613D3 for ; Sat, 12 Dec 2020 08:52:12 -0800 (PST) Received: by mail-ot1-x344.google.com with SMTP id q25so11345928otn.10 for ; Sat, 12 Dec 2020 08:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S2y16zpbJLgQCBtnJuWPErw4b7gTF1z77tim59YOdNg=; b=UgShE8q0c0gaMGgA3YUkt178/pRyqTj9aZyzHx+DeXdwUvztxFSg8sKQU8VfWsQpK/ fUl5eFrV8LJPZUyphAL6UJ3YHdrsusZAYjb5CQNtj/m2JTHkR4EGKOEnMdaw199QZWvL HnXGVTI+lNj1X9yNoY2OHrj8sWLZnRlm+YnzRzTNjcK/Rs9mkdEq9j2zpROtqDbkwygp iZB+QAp+HJsU2M3W9xNBv3EAvcSBjdQBlkCHS5zlZTVKcv9i5CLJ7NWxRKNmZnaA1so1 9mJD92sZxCvRDV5GMFe2gntf5q493QzM7CdyH0ENC61uFMJTJ1MphfzOzk0IsEZtmzm3 69iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S2y16zpbJLgQCBtnJuWPErw4b7gTF1z77tim59YOdNg=; b=XWrvPyp4qgm6yN0o7hDj4KPd7a5k24yqZ4NWuesP4ps9vWjwHB+DoKPvPJg0d39pgR wDUAfW2rjcISNAEDbaFtrOVl2di+VoD+89JCTccpTrqJ54tX7ORmcJMCfa38hCQ0KAPu fM9aGYnUwLs9NRd4XfLliFhda0pMtf9BqjGkKmilQr4JSLLoxhilyIxz/4jnwygvQgSQ bXAUJztUHq7NkGWYxjc85EB6hzB2kW1PHns/QReOAOdeffzu1ly0jxcZPR5ddq7k3bwC vxTsI4eS97KcxbYn/Ditjsb+2+SoJl34+OyEq4EDKkiq98Bi1tR2MbMeBSy36mzIpTDV TZMw== X-Gm-Message-State: AOAM531/5OEc0dG/lGEHHyYbX4AKnHW9Z0xFDN807u8jD0uiDI0TSkqw cU1bmp3g9LcAOfAadQoSapzdpjIHD3dl1Q== X-Google-Smtp-Source: ABdhPJwr6WRhLIz0T9eznrmLYrQW/IJOftBB2bXGx0OkGhVQ1fO8hqNbuT8yKvqJ9wOpnZjkY2PxIQ== X-Received: by 2002:a9d:3786:: with SMTP id x6mr14203991otb.176.1607791931652; Sat, 12 Dec 2020 08:52:11 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id o17sm926512otp.30.2020.12.12.08.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Dec 2020 08:52:10 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Elijah Newren , Junio C Hamano , Jeff King , =?utf-8?q?V=C3=ADt_Ondruch?= , Felipe Contreras Subject: [PATCH v5 1/3] pull: refactor fast-forward check Date: Sat, 12 Dec 2020 10:52:06 -0600 Message-Id: <20201212165208.780798-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201212165208.780798-1-felipe.contreras@gmail.com> References: <20201212165208.780798-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It makes the code much cleaner. Plus, we would like to be able to make this check before the decision to rebase is made in a future step. Signed-off-by: Felipe Contreras --- builtin/pull.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index aa56ebcdd0..03e6d53243 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -924,6 +924,20 @@ static int run_rebase(const struct object_id *newbase, return ret; } +static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_head) +{ + int ret; + struct commit_list *list = NULL; + struct commit *merge_head, *head; + + head = lookup_commit_reference(the_repository, orig_head); + commit_list_insert(head, &list); + merge_head = lookup_commit_reference(the_repository, orig_merge_head); + ret = repo_is_descendant_of(the_repository, merge_head, list); + free_commit_list(list); + return ret; +} + int cmd_pull(int argc, const char **argv, const char *prefix) { const char *repo, **refspecs; @@ -1040,22 +1054,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { - struct commit_list *list = NULL; - struct commit *merge_head, *head; - - head = lookup_commit_reference(the_repository, - &orig_head); - commit_list_insert(head, &list); - merge_head = lookup_commit_reference(the_repository, - &merge_heads.oid[0]); - if (repo_is_descendant_of(the_repository, - merge_head, list)) { + if (get_can_ff(&orig_head, &merge_heads.oid[0])) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ran_ff = 1; ret = run_merge(); } - free_commit_list(list); } if (!ran_ff) ret = run_rebase(&newbase, &upstream); From patchwork Sat Dec 12 16:52:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11970141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15AD4C433FE for ; Sat, 12 Dec 2020 16:53:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6F0F22475 for ; Sat, 12 Dec 2020 16:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391571AbgLLQxJ (ORCPT ); Sat, 12 Dec 2020 11:53:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407687AbgLLQwy (ORCPT ); Sat, 12 Dec 2020 11:52:54 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1076AC0613D6 for ; Sat, 12 Dec 2020 08:52:14 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id i6so11377183otr.2 for ; Sat, 12 Dec 2020 08:52:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3PT9LCslgiY/W+NqHL+fY1JTdNNRFQb5v7N6kfp9sSM=; b=gc6jREnC1PDNIiXm3HGDgTbgHN4jPXquPs88d7fdCeONI1MI4Fn+wvdvdvwQDiTJNY 6DcjPRgJid/284Uf3I3jM1zUiRmfsnoXb7d5AxoGhUELl7bCmBETd7ALttPwZduh4kM5 gfCNQ5YU6kVsLx2iMVKqSqGmFatTL+LENEVpNbyk3JiPYPgaPYwY5HgYybBngRw/n3iz Y1wzhkb58zb9hhQX7evTfCatn8VA0qwk5q3c0xoQXE6RLsd04jgEZt3guj1NTHP/IxyW 2yv1fAo2j/dUAcx7kqYe0e8g+FEjhwpoq5/M5bOmffCBVpP7ssf02aA6PIAYgbAXKypr smIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3PT9LCslgiY/W+NqHL+fY1JTdNNRFQb5v7N6kfp9sSM=; b=kzmQ3zehL9whm7hkWq+JO2TRnisGKVrICekpssaRceK98Z+kpPX2Ls6w3XNOGCJ33X CxovlKfQ36hl+cLy3KEusEV0mP9oavtoYL4pGt1OQrOFBZ7BYdklvHO1WS+5f6fgOwJa JWwgSXgZRQw/gZNOnZDERnQ/mkm4wjXAvhOqGtiXI7uqMEPE0t9F75XhceJfQ8oIdd/G jEVSLF93VSVzJC7Ksw4y4iaSF2edrzVa7qDs7nNGwcUyNPe1RpTZrGG2L35KYinm8cfW k6QjHrXge/MeyOgAutFdiU8sLgcasPnUM99Aynkd6UZI9zyWDN43FcZjDXFtj1G/ec52 1ymg== X-Gm-Message-State: AOAM531CBhnXF/ikS7LgHCKU4HZ3gwnk+OG6fU0Rx8pKaB/uuCTX2jsY BXXELk5IVCjT7tSiSLAVHbY8o8qsg0Ju3Q== X-Google-Smtp-Source: ABdhPJyDENwvSxTd4cNVbGHvtycv8hVFFELPI3U7HqQET24WgnlkRzZoGvYpfS+Y9O0i+hdWDNNsPA== X-Received: by 2002:a05:6830:240d:: with SMTP id j13mr14108809ots.319.1607791933154; Sat, 12 Dec 2020 08:52:13 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t19sm2863840otp.36.2020.12.12.08.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Dec 2020 08:52:12 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Elijah Newren , Junio C Hamano , Jeff King , =?utf-8?q?V=C3=ADt_Ondruch?= , Felipe Contreras Subject: [PATCH v5 2/3] pull: move default warning Date: Sat, 12 Dec 2020 10:52:07 -0600 Message-Id: <20201212165208.780798-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201212165208.780798-1-felipe.contreras@gmail.com> References: <20201212165208.780798-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Eventually we want to be able to display the warning only when fast-forward merges are not possible. In order to do so, we need to move the default warning up to the point where we can check if we can fast-forward or not. Additionally, config_get_rebase() was probably never its true home. This requires a temporary variable to check if we are in the "default mode" (no --rebase or --no-rebase specified). But this variable can be removed later on with further code reorganization. Signed-off-by: Felipe Contreras --- builtin/pull.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 03e6d53243..ff8e3ce137 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -27,6 +27,8 @@ #include "commit-reach.h" #include "sequencer.h" +static int default_mode; + /** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is @@ -344,20 +346,7 @@ static enum rebase_type config_get_rebase(void) if (!git_config_get_value("pull.rebase", &value)) return parse_config_rebase("pull.rebase", value, 1); - if (opt_verbosity >= 0 && !opt_ff) { - advise(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" - " git config pull.ff only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); - } + default_mode = 1; return REBASE_FALSE; } @@ -1040,6 +1029,21 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); + if (default_mode && opt_verbosity >= 0 && !opt_ff) { + advise(_("Pulling without specifying how to reconcile divergent branches is\n" + "discouraged. You can squelch this message by running one of the following\n" + "commands sometime before your next pull:\n" + "\n" + " git config pull.rebase false # merge (the default strategy)\n" + " git config pull.rebase true # rebase\n" + " git config pull.ff only # fast-forward only\n" + "\n" + "You can replace \"git config\" with \"git config --global\" to set a default\n" + "preference for all repositories. You can also pass --rebase, --no-rebase,\n" + "or --ff-only on the command line to override the configured default per\n" + "invocation.\n")); + } + if (opt_rebase) { int ret = 0; int ran_ff = 0; From patchwork Sat Dec 12 16:52:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11970143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C90FC4167B for ; Sat, 12 Dec 2020 16:53:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F164F22573 for ; Sat, 12 Dec 2020 16:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395451AbgLLQxM (ORCPT ); Sat, 12 Dec 2020 11:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407688AbgLLQwz (ORCPT ); Sat, 12 Dec 2020 11:52:55 -0500 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BFE9C061793 for ; Sat, 12 Dec 2020 08:52:15 -0800 (PST) Received: by mail-oi1-x243.google.com with SMTP id f132so13835805oib.12 for ; Sat, 12 Dec 2020 08:52:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=40X1+/4spqJl0f48MlFog+hwA1kTXQHXTIpadIA0VPI=; b=NbMjC1ujT1MDKnc2Iuk+ZzEqNVTDzFleaFLCFxrXAGxRboqns+47xcXRSTGzOgG279 0hT5XZZ2115xL6M6yxvEm03QwuXahlLgndfDzgEORv1j2o9/u6ciaFUqfTWAe5UpsJ5A E9OV1ot7/bEFoak/JUTM2QYSdEQh3alsjyEZEzvgDD467X1/FOeYRLnN/KPrW6xqJIhX 7OcxKd70wxDiPWkeA51vyCwbXSfQmw8j0XuqqGVNrEzarv/qktJ+U2dp86VjskgOewNV QRN+9LbFiiikFkH2Ei85hY5w6Fpb4rdN2WStG4RVpGna/h9dWayjsEwvA0YXr8/0/lDZ eE7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=40X1+/4spqJl0f48MlFog+hwA1kTXQHXTIpadIA0VPI=; b=DZ9ZF2J2rVSraG/KnEE6hRcMhCLOtKkapPzH5aRtOSS7AtJ7hX2pCmmGi4ZSjKrKk7 oJ49+W9GpZH+UxtRViy6AEqCStAntqgjR8FW5Nh3RaFUO7nnqOF4MpdDpO4f/V66kfxC BhJfhk1KtyASsJi1ba3NahZZNAfkmM2YbNye5jCihfMRDvdYrAD3FaWFwrxV/mW6+4c6 /xaAyyKTIuu8958y6MUM3axLX6lJaA/UDXS6OziH5YbFGUItj6CZFklHEU0wCi8zDmY4 Awv32Irp1AIRnD+7hPMb7TlEhU4aeLNYOsX+S6z6UG8W+MkJ/PZbbiE3j55TKBcPDn5k u3NQ== X-Gm-Message-State: AOAM5315Or4fnu3zZsoedCz1IiTRbSvrFlbjK0GqTpnwNlDSLOxFuzZE U9ix5t9dWMkXVIXqWIAjVNjLdslSKVWD/Q== X-Google-Smtp-Source: ABdhPJxnuI4QbM7XbgtgSgsTpkY3f3nYmcn+rG8wznM6I32jp3H3H7mT25hIM08qiN3toQ6ToP4oaw== X-Received: by 2002:aca:dc54:: with SMTP id t81mr13152278oig.101.1607791934753; Sat, 12 Dec 2020 08:52:14 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id p8sm2746755oig.22.2020.12.12.08.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Dec 2020 08:52:14 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Elijah Newren , Junio C Hamano , Jeff King , =?utf-8?q?V=C3=ADt_Ondruch?= , Felipe Contreras Subject: [PATCH v5 3/3] pull: display default warning only when non-ff Date: Sat, 12 Dec 2020 10:52:08 -0600 Message-Id: <20201212165208.780798-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201212165208.780798-1-felipe.contreras@gmail.com> References: <20201212165208.780798-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no need to display the annoying warning on every pull... only the ones that are not fast-forward. The current warning tests still pass, but not because of the arguments or the configuration, but because they are all fast-forward. We need to test non-fast-forward situations now. Suggestions-by: Junio C Hamano Signed-off-by: Felipe Contreras --- builtin/pull.c | 7 ++-- t/t7601-merge-pull-config.sh | 66 +++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index ff8e3ce137..9a7caf3a3e 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -934,6 +934,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct object_id orig_head, curr_head; struct object_id rebase_fork_point; int autostash; + int can_ff; if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -1029,7 +1030,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); - if (default_mode && opt_verbosity >= 0 && !opt_ff) { + can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); + + if (default_mode && !can_ff && opt_verbosity >= 0 && !opt_ff) { advise(_("Pulling without specifying how to reconcile divergent branches is\n" "discouraged. You can squelch this message by running one of the following\n" "commands sometime before your next pull:\n" @@ -1058,7 +1061,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { - if (get_can_ff(&orig_head, &merge_heads.oid[0])) { + if (can_ff) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ran_ff = 1; diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 6774e9d86f..52e8ccc933 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -29,11 +29,8 @@ test_expect_success 'setup' ' test_expect_success 'pull.rebase not set' ' git reset --hard c0 && - git -c color.advice=always pull . c1 2>err && - test_decode_color decoded && - test_i18ngrep "hint: " decoded && - test_i18ngrep "Pulling without specifying how to reconcile" decoded - + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and pull.ff=true' ' @@ -87,6 +84,65 @@ test_expect_success 'pull.rebase not set and --ff-only given' ' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' +test_expect_success 'pull.rebase not set (not-fast-forward)' ' + git reset --hard c2 && + git -c color.advice=always pull . c1 2>err && + test_decode_color decoded && + test_i18ngrep "hint: " decoded && + test_i18ngrep "Pulling without specifying how to reconcile" decoded +' + +test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff true && + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff false && + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff only && + test_must_fail git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' ' + git reset --hard c2 && + git pull --rebase . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' ' + git reset --hard c2 && + git pull --no-rebase . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' ' + git reset --hard c2 && + git pull --ff . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' ' + git reset --hard c2 && + git pull --no-ff . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' ' + git reset --hard c2 && + test_must_fail git pull --ff-only . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + test_expect_success 'merge c1 with c2' ' git reset --hard c1 && test -f c0.c &&