From patchwork Thu Dec 10 10:05:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11964069 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 766C4C4167B for ; Thu, 10 Dec 2020 10:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 483A823609 for ; Thu, 10 Dec 2020 10:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728638AbgLJKGa (ORCPT ); Thu, 10 Dec 2020 05:06:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726313AbgLJKGY (ORCPT ); Thu, 10 Dec 2020 05:06:24 -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 C1CC9C0613D6 for ; Thu, 10 Dec 2020 02:05:43 -0800 (PST) Received: by mail-oi1-x243.google.com with SMTP id s2so5145374oij.2 for ; Thu, 10 Dec 2020 02:05:43 -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=BBkcYudC5IYbiUK+V0PX4doz+JknEvoGMT+r73ZiJhY=; b=UFIGDf2VtjfOMuJfubGjL20zd1Umsulh9oNvkb33zRR6aJcR7nvokiBjxqPHmGinEP A1fHp8XI4DJHQ8GXyN9EeNv7/RY7cq/gefI+XFmyGuPCs5+kc4mBz84UaC+ZPAQCaFhp ayrFpzftcvByf/yLr62S6cWTmrjwxrCyj4s6GmPkut3/bmWFJIw7OS9N1JFHtXWXK/59 E6hmfBf/O8+0gnkIsFQDJVlw4u9ljlXeWP0N7HhpvOBxxBMxcLbksWtEIrl3cbeYlK0a XYjgyvIpkHtkCGhE7pc1A9LxCaruk93JAM/AraZ7nuLbLa4WuwAxTd0ryAIlUAPDnEYN QlJA== 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=BBkcYudC5IYbiUK+V0PX4doz+JknEvoGMT+r73ZiJhY=; b=bRXm54hkPtec8RbdmJTTnSFmqVhgB64S8UCcJbkpbvK6MkqLKSGttE8EzOql8kVjGr JNmSUIU+betXuXBo6muG8cZ737oN/DrTY6/MHRuUTd5edA8O5m5Ge/7Mki5VBwgrPDib TkVW5ve/188fqic57dB6oy1fk8t4zxtX89om+/Z39i3afLcSI3u0x24jZrDXKu8mmNu+ S6o0RdUb1meT8w04J2g95LC6YzdptZoXNXgrSMvXo7Zrz3vZTEWe6VqSfnSjx2qSRC9h iN934MUQbsndgpM4kCTlYF/S3gfVlpnNubsQN9OsusDFlqn+wWKYCQ3mSLrgODG3+6WH VsrA== X-Gm-Message-State: AOAM532ErH8gc61Xu3MTvZ7VthviP4Zzsvqn0XeKiDf4Nr0Ymv9pOhiW 7OJMEgCzqFSg268QPHdMnaeOtGGg9CXU9g== X-Google-Smtp-Source: ABdhPJxhojwnsC6qjApwaQo9IwV8MJ9BwadSULeJtC/86bLxS55qtw4h28JWhuUQacxEZTbO2msN0g== X-Received: by 2002:aca:b1c3:: with SMTP id a186mr4900486oif.8.1607594743040; Thu, 10 Dec 2020 02:05:43 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id g5sm984836otq.43.2020.12.10.02.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:05:42 -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: Thu, 10 Dec 2020 04:05:36 -0600 Message-Id: <20201210100538.696787-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210100538.696787-1-felipe.contreras@gmail.com> References: <20201210100538.696787-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It's much cleaner this way. Also, we would like to be able to make this check before the decision to rebase is made. 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 Thu Dec 10 10:05:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11964067 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 CC51EC433FE for ; Thu, 10 Dec 2020 10:06:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 883AA23609 for ; Thu, 10 Dec 2020 10:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729089AbgLJKGk (ORCPT ); Thu, 10 Dec 2020 05:06:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728147AbgLJKGZ (ORCPT ); Thu, 10 Dec 2020 05:06:25 -0500 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5257C061793 for ; Thu, 10 Dec 2020 02:05:45 -0800 (PST) Received: by mail-oi1-x242.google.com with SMTP id p126so5125506oif.7 for ; Thu, 10 Dec 2020 02:05:45 -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=nlaH2HiQHdcJora12BW7DR1eNVAaESPKLIf3N1gK6YQ=; b=BcgXfmaGKKh8Z1UVZPJBHzJii9BhJIiz6kqKZsLpbrCmiT8/U9fYUA8PyrEiKV1DY+ jnpezF/nVp32eizHibpKhDZVoEKDC6XRomt4rAtleZC8R9j8gVj5b2ruOa0Jd+qwg7X2 Bv3XfV5Phx8j/F45GxKf8c49FShEn4TcslpitgKUeWphzcJ56lBfTGZuOIrjuzTyIgGJ GTKb4PbCM/9Ih433vSXpkfNo8McRsh2rjabw2OtP0UXKq77Zd4f4Ig7LbBdH2fLh8z7o mW8j71rJrBrBS5qsoSLELptfAow2acAADXuXJCP5zir8qaROxkJv4BcWvVijbRby/XoB bCiQ== 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=nlaH2HiQHdcJora12BW7DR1eNVAaESPKLIf3N1gK6YQ=; b=XXaCERSvPT2E6uFh/KltpZ9iwaPnxohXt/N2DR+TUXQHPmwK7enG5pmuKwDtrt5dBn fg8FKTnOgkXprBovhQK8d4/WndnCw5oZc+kFNeELwFjsT9G9l5Aw9t/giqsY6py5i3Nx Co94pfhd/v7Rlwaw2xXcayjuyT7TdoullnlIOpgaRDtPbQXfyXHJqBOcD30qVI8BYM7v ROvx5UZy41LCn3kR0dNmM9+v6lL0TixpXbI4B2t6hUpAU88+mCxuMVrjWj75eCsc2e8p 8F7vDOe7ZHAqo9eHaOnzhYKyLCGVy00DGtNv1dwpZ5aK6BABsftStQjYTsqKoTeSiWQc 9Zwg== X-Gm-Message-State: AOAM531gSgbbq6tREtGgSf6AtwJoOZeVD6bRGCNCt/lB/7ezNYOFafcb VGJtlqZwtNlNacc0Uz336oM34yU94WaYyA== X-Google-Smtp-Source: ABdhPJzJR7xLbUD8EgtASXmcOPEToTpdHOkT9laH411iETsozqnDn2+YzUj/GpxNW0N39qWHeSiz8w== X-Received: by 2002:a54:4799:: with SMTP id o25mr4832967oic.33.1607594744807; Thu, 10 Dec 2020 02:05:44 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id g2sm900996ooh.39.2020.12.10.02.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:05:44 -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: Thu, 10 Dec 2020 04:05:37 -0600 Message-Id: <20201210100538.696787-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210100538.696787-1-felipe.contreras@gmail.com> References: <20201210100538.696787-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). 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 Thu Dec 10 10:05:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11964071 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 6951DC4361B for ; Thu, 10 Dec 2020 10:07:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 200D222DA9 for ; Thu, 10 Dec 2020 10:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728920AbgLJKGe (ORCPT ); Thu, 10 Dec 2020 05:06:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbgLJKG1 (ORCPT ); Thu, 10 Dec 2020 05:06:27 -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 53CE2C061794 for ; Thu, 10 Dec 2020 02:05:47 -0800 (PST) Received: by mail-oi1-x243.google.com with SMTP id w124so2017089oia.6 for ; Thu, 10 Dec 2020 02:05:47 -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=2szruxJnWf41uQaF2p/QjnHt6VBQe2JkZ+WAoy0/Z1U=; b=HU3HPoTpQ8F+BOUq5Gt7vFeryX7dv7Bq/sAIDIxP5mqY4lI8jSIRUEDdLcCUK4c3zV YwYgW75S6neuHEZyuLN7Ja1vSR0T4JHbvgFHyBCV1l+2G4sZ+Ea/iIWNLrtPHnth0gAu OUChOKKsj0FFQMRcl4X6XhdnLUkByoWCCCsMmzNrP3ajMxxzcA4OtUc9BG/s2gtU/pZf tDz9uNjTbjPcPahjQ5LfcCUs7fnbNCXndkcAF3p/jA1+ZKR7vSwYZGkkSs/mqYYS/Dbl HNoGg9dy/wDuhWKGeIpXiAuvOKwobOhTgAHZS+GAouZCHquGxVXvLZyqzMiH/Oe5h8cr fpOQ== 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=2szruxJnWf41uQaF2p/QjnHt6VBQe2JkZ+WAoy0/Z1U=; b=PVjmcboMhkaC48bycG6PXmHVWWVtQ23rpKmX/TDLKYvRdUnKkPLTB1hkt9GcByHxTn 8GSNfazeHBQhSq+kxrCFE5xgXiUsso6zhKnxgUNfdS59CivQNyqSLJqGxdKGI4YTfOOc qqgj4m7Wq59QKykaDNN+5Z5HmvA5KSJHP4MGwYfQMwDzksLFpe74ORTM3cELsjwtOgeJ 0dpkS0lRjM9XxXkcxwCfwysA5CicT2YSEmsE3kCKo5ebt9Nbg1IF9+naXLbZYXxyaPeM 1F47cBexlBjZx/0hDzZsSNjGKJLBqsFWQ8Vhi4uk697H73KvduRK2Q4rul1RJOQEmYTw BFLQ== X-Gm-Message-State: AOAM532epCg8QHovAwOAPf117KcW4Ncfp8PVi2OG+ufX0mlII6e7KHzE l1YGGymQkFbFSbDVzWAFmZsCJX6oF9eGzA== X-Google-Smtp-Source: ABdhPJw/BUBgmN9yNN2hzdwh+UrIj5ORi6X09rUdO0/PFB/ksXYr7jo8r8k8r/Ypty1YlFqVLldTTA== X-Received: by 2002:aca:4257:: with SMTP id p84mr4894326oia.176.1607594746505; Thu, 10 Dec 2020 02:05:46 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id 9sm986728otl.52.2020.12.10.02.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:05:45 -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: Thu, 10 Dec 2020 04:05:38 -0600 Message-Id: <20201210100538.696787-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210100538.696787-1-felipe.contreras@gmail.com> References: <20201210100538.696787-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. This requires the tests to pick another base, so the merge is not fast-forward. And in the cases where --ff-only is specified add test_must_fail (since now they are non-fast-forward). Signed-off-by: Felipe Contreras --- builtin/pull.c | 7 +++++-- t/t7601-merge-pull-config.sh | 28 +++++++++++++++++----------- 2 files changed, 22 insertions(+), 13 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..6b4adab8b1 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -28,7 +28,7 @@ test_expect_success 'setup' ' ' test_expect_success 'pull.rebase not set' ' - git reset --hard c0 && + git reset --hard c2 && git -c color.advice=always pull . c1 2>err && test_decode_color decoded && test_i18ngrep "hint: " decoded && @@ -36,54 +36,60 @@ test_expect_success 'pull.rebase not set' ' ' -test_expect_success 'pull.rebase not set and pull.ff=true' ' +test_expect_success 'pull.rebase not set (fast-forward)' ' git reset --hard c0 && + 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' ' + 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' ' - git reset --hard c0 && + 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' ' - git reset --hard c0 && + git reset --hard c2 && test_config pull.ff only && - git pull . c1 2>err && + 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' ' - git reset --hard c0 && + 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' ' - git reset --hard c0 && + 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' ' - git reset --hard c0 && + 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' ' - git reset --hard c0 && + 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' ' - git reset --hard c0 && - git pull --ff-only . c1 2>err && + git reset --hard c2 && + test_must_fail git pull --ff-only . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err '