From patchwork Fri Dec 18 21:10:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982975 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.8 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 722C2C4361B for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3531123B88 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726230AbgLRVLL (ORCPT ); Fri, 18 Dec 2020 16:11:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLK (ORCPT ); Fri, 18 Dec 2020 16:11:10 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 785F0C06138C for ; Fri, 18 Dec 2020 13:10:30 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id b24so3274506otj.0 for ; Fri, 18 Dec 2020 13:10:30 -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=fqdgFuw3AE+7gvHj7goBAP/wOSj/ige0wAsPlIa238o=; b=CBJYOGx51bOxY3c+0rOq5S5Us4q7DZIHsz7z20MbWBQedQH2w8oeabfDtCBUOXgmIe lwxPb9y+3Hiv9OSoEq3j95OJLjIv5eSOpJqNeyhr+DgXfYAcBXxMS6sYrzTjgfV93aXi 10/4IBqNkcjt2WCnaveIFZtRyTBlsT6GfiO7STNU4j9s3VMdk4rF0jMlwz6huVmI2Hhx rGkyQ1mB0RMTMwL+DWUgbXC6dQFx5Ob3LZBtXqtzZd7d6+kYU+fIIHOg1bIyy+zNBAyy FlVHKXj8sf/xzCxB7HSbcLMoVm5nl3ukE+wTNgfp4ODAyuCAcmfbK3Ip1HrSc/8U/Z6u 57QA== 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=fqdgFuw3AE+7gvHj7goBAP/wOSj/ige0wAsPlIa238o=; b=PlcrshvIewBdzYQ/jqagiBzWXsLvG1d44AVsUhTnYoPKF9xeUQ9fX3Wt4WKcKSXw43 nV/uI23QiqsKh6CkTvWmWET1NE4ySTi+acYW0TYhtTAwD5/6wwNEDa1q0ykhzqLnmJco 8QQkFQgfovZ2ohzGCdq1n9q03WkJ4K1FONWKd/85+VNPW7Vpl5fnR/z/wpJCDpd00ycY KOa2il4ZHeMBoDhWd56nTfDBdX2UqLUbUIHk5//XukpPFi1p6fUhjlZ3GsYmv2GQ+axH /Rs8SYJcpxeoSDjygmE2eTQnAPxXhIRYSFIXE5jEKKWk6CB02DWbVdJl+dCa7eK1VPjM Jt3Q== X-Gm-Message-State: AOAM532GiBEpbHY/ZWz8au7YEnP/dfYVtnOunxmZCjeQ5+iU6uQZTEDq oIETn9jIANzaxnav+LN47mo8sUA5elTppA== X-Google-Smtp-Source: ABdhPJzXYkdBjPat9Yob4cnSpcOb67bTCjD8N3/88Cm0qgAsLfYGMJJiFxsPs9Am5V8HGAI9hFNJmQ== X-Received: by 2002:a05:6830:1d71:: with SMTP id l17mr4309905oti.269.1608325829669; Fri, 18 Dec 2020 13:10:29 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id z189sm2005218oia.28.2020.12.18.13.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:29 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 01/13] doc: pull: explain what is a fast-forward Date: Fri, 18 Dec 2020 15:10:14 -0600 Message-Id: <20201218211026.1937168-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We want users to know what is a fast-forward in order to understand the default warning. Let's expand the explanation in order to cover both the simple, and the complex cases with as much detail as possible. Signed-off-by: Felipe Contreras --- Documentation/git-pull.txt | 41 ++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 5c3fb67c01..142df1c4a1 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -41,16 +41,41 @@ Assume the following history exists and the current branch is ------------ A---B---C master on origin / - D---E---F---G master + D---E master ^ origin/master in your repository ------------ Then "`git pull`" will fetch and replay the changes from the remote `master` branch since it diverged from the local `master` (i.e., `E`) -until its current commit (`C`) on top of `master` and record the -result in a new commit along with the names of the two parent commits -and a log message from the user describing the changes. +until its current commit (`C`) on top of `master`. + +After the remote changes have been synchronized, the local `master` will +be fast-forwarded to the same commit as the remote one, therefore +creating a linear history. + +------------ + D---E---A---B---C master, origin/master +------------ + +However, a non-fast-forward case looks very different: + +------------ + A---B---C origin/master + / + D---E---F---G master +------------ + +If there are additional changes in the local `master`, it's +not possible to fast-forward, so a decision must be made how to +synchronize the local, and remote brances. + +In these situations `git pull` will warn you about your possible +options, which are either merge (`--no-rebase`), or rebase (`--rebase`). +However, by default it will continue doing a merge. + +A merge will create a new commit with two parent commits (`G` and `C`) +and a log message describing the changes, which you can edit. ------------ A---B---C origin/master @@ -58,8 +83,11 @@ and a log message from the user describing the changes. D---E---F---G---H master ------------ +Once the merge commit is created (`H`), your local `master` branch has +incorporated the changes of the remote `master` branch. + See linkgit:git-merge[1] for details, including how conflicts -are presented and handled. +are presented and handled, and also linkgit:git-rebase[1]. In Git 1.7.0 or later, to cancel a conflicting merge, use `git reset --merge`. *Warning*: In older versions of Git, running 'git pull' @@ -248,7 +276,8 @@ version. SEE ALSO -------- -linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-config[1] +linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-rebase[1], +linkgit:git-config[1] GIT --- From patchwork Fri Dec 18 21:10:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982977 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.8 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 8F269C2D0E4 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5181423B8A for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726246AbgLRVLM (ORCPT ); Fri, 18 Dec 2020 16:11:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLM (ORCPT ); Fri, 18 Dec 2020 16:11:12 -0500 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 151BEC061282 for ; Fri, 18 Dec 2020 13:10:32 -0800 (PST) Received: by mail-oi1-x22a.google.com with SMTP id p126so4296993oif.7 for ; Fri, 18 Dec 2020 13:10:32 -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=qeZueia3JmAKGtXPiZEnwXas/1iWvyNIvfXqqhCkiJo=; b=a1h1Y8r8ry7rmLCoG5r7edxw5OU5UTignZptUGqzGn1XlD3UyDwjnGLKO/e3RW7/sm +6q89RFVFGe+Vwf33l/Zio5ZtrDnCIMtRtGxVHIOrwDE9rBFnqUF6n4QIfVOr9qXAeYh HohwXVrSewsJwLe0Y87+jF+q2G0e6X/5qRdDX3CoBD8aXWUmTIkqaatrUEdzLs2xilUF HrzBN253cnC6LZI62Rn0WwnMTukFJjgbgWhSSCKM4d2yEY8cboMTX8CPvIRQsw1d/OEn raYeVVSoKJRQuZnIl6fJbkFIMFOsgI3upMap08Tnvp0c1lzp3dtHzdQAEh0amBCvLuTe uu3A== 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=qeZueia3JmAKGtXPiZEnwXas/1iWvyNIvfXqqhCkiJo=; b=rkl18pGD/2HXD3BKqM08ljINmvQwT1ukpM4EnlqXi0sovpipMIczlqZkXgYRs1+3+/ /yrYqNyTCwBnu+cWmMyi+BBJYcWDYDxDrx1OObRAJFm3m0obhn8FCbOuC5C9dWdyFz7/ urL0JqueUCgjQQPaIe1jbk90+jaJLGdXmNhGcjpdotQbq6ttlO6PtOv/lQtX8MzKL6bR WDjHldqDWCGWpM1Rx2s3uMgXRovcpLzbj0rL9Pj9VRkMk7qWyEue2Sz0EQfFqLvg3nii QjsC5rjA0l+ETMLb2DxBH8W244IIQ6sJ9N4JVE75BoPX18iG7TR6Jk8u08zwoFcMvNuM D3eQ== X-Gm-Message-State: AOAM5336pBljBrIZgLsj6x/BEYFUeLqVVegYLUoH9pKoeZHdcbudn1fC 7NmDfLfH2IUPtbEp4esWYsvfKRq2tf9UKA== X-Google-Smtp-Source: ABdhPJzxKrr9lVuYh90zlIs8zBka8EJSoj350JQ5JssFTxwAgFwJT2gY4EII0IzYLlum9oFDRaBaAg== X-Received: by 2002:aca:130a:: with SMTP id e10mr3932031oii.163.1608325831216; Fri, 18 Dec 2020 13:10:31 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id i25sm2121586oto.56.2020.12.18.13.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:30 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 02/13] pull: improve default warning Date: Fri, 18 Dec 2020 15:10:15 -0600 Message-Id: <20201218211026.1937168-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org According to feedback from GitHub trainers [1], most newcomers don't understand what a rebase is. So in the default warning we want to provide our users with a command that does the most sensible thing, fixes the divergence, gets rid of the warning, with the minimum mental effort, and happens to be the default: git pull --no-rebase (later --merge) In addition, we don't want to start by recommending a permanent configuration, but a temporary solution so they start training their fingers and maybe learn how to do a rebase. So we start with the commands. Also, we need to be clear about what we mean by "specifying"; merge, or rebase. Moreover, thanks to the previous patch now "git pull --help" explains what a fast-forward is, let's mention that reference. And finally, use --global in the configuration commands like we did with push.default. [1] https://lore.kernel.org/git/20130909201751.GA14437@sigill.intra.peff.net/ Signed-off-by: Felipe Contreras --- builtin/pull.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index e8927fc2ff..a766d9762c 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -927,18 +927,20 @@ static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_ static void show_advice_pull_non_ff(void) { - 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" + advise(_("Pulling without specifying how to reconcile divergent branches is discouraged;\n" + "you need to specify if you want a merge, or a rebase.\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" + " git pull --no-rebase # the default (merge)\n" + " git pull --rebase\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")); + "You can squelch this message by running one of the following commands:\n" + "\n" + " git config --global pull.rebase false # merge\n" + " git config --global pull.rebase true # rebase\n" + " git config --global pull.ff only # fast-forward only\n" + "\n" + "If unsure, run \"git pull --no-rebase\".\n" + "Read \"git pull --help\" for more information.")); } int cmd_pull(int argc, const char **argv, const char *prefix) From patchwork Fri Dec 18 21:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982981 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.8 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 A1BE8C3526B for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71F1823B8C for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbgLRVLO (ORCPT ); Fri, 18 Dec 2020 16:11:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLN (ORCPT ); Fri, 18 Dec 2020 16:11:13 -0500 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880B1C061285 for ; Fri, 18 Dec 2020 13:10:33 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id f132so4253835oib.12 for ; Fri, 18 Dec 2020 13:10:33 -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=iblx90t190+ni7k16wu8LQ9RY1VxmlRErEfCbCmp/ZU=; b=K/ZWAn/XCp4VVzJpK3wrBYMxW8gKGny4jWBlHpr9KJbzkrRMYHWj56DFSvPrvb3w4z Hpkd5XUK4AAJOSRoCPq5DTIcmy24/ROOengEvDxW2Xn094jS5677/VbdC8AAJW1Na5kl bkLdtkZm78K5dZ9h2fMaFOGeO/MsE82gQJDqgZPE4lhRGNbTYy9VBgZ4PtGeMcYKI87j 8JYgMOf0YCI1q/VPDf+IcjSOvJtbTbqdeS6eBJHbG68iHs1A+921PfIMn/sA7FguqNUq 8ICRKfRAeSrVGbSzqJiW0O1+qsTsQfH2d7C9ooiGkeu8NZBiF/8Ok00bQ7IXGrpjoZbB 749g== 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=iblx90t190+ni7k16wu8LQ9RY1VxmlRErEfCbCmp/ZU=; b=obUhaWKpcuALEFDfukkqB3t9EWYI/2XL78oEBkotE5pvmc4y3ulDNyUYVSNB9c7C2D 6eCwrpe2QFH196OKjJNCRx4aAq2VhPoX6vv0cAQGhWrQ2VoDOJP6HK3uscL9YHlrass5 yT/1FbOqp+7y1Dv0EWTDOxY0RCf6KM8tmatZKWWPYwxlkyI0MQPAK/+199W7qNs1tJjg nhuw9CRR4AKJyyy/wjvP5VgBW2gjpf4jDLzbS8xuyHrKyUyUNFJRa9RXZbr6G3zgsM6U tXImbdfJvgNMOYqK7qwR7r6Wxu4pyZWj/jtBAhR2hZmD+LvlAuZB4t5qLXVf78jw1iuM O0KA== X-Gm-Message-State: AOAM530Ed3F3/0F+y9eDR5Jw0xr/9KPGlogigbcJld4mxuP6jV9sYTrU nr7GYgM4Qb0x9L2O/U1LV07kC3yhLzai3w== X-Google-Smtp-Source: ABdhPJxkWpc5c55dTETJOZgM6Ys8uVuWBC2Cuf4CAfInSyALip4fbDNdv5JU3sPxsKSgidTReQTTVQ== X-Received: by 2002:a05:6808:10b:: with SMTP id b11mr1849501oie.90.1608325832814; Fri, 18 Dec 2020 13:10:32 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k3sm2139848oof.31.2020.12.18.13.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:32 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 03/13] pull: cleanup autostash check Date: Fri, 18 Dec 2020 15:10:16 -0600 Message-Id: <20201218211026.1937168-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently "git pull --rebase" takes a shortcut in the case a fast-forward merge is possible; run_merge() is called with --ff-only. However, "git merge" didn't have an --autostash option, so, when "git pull --rebase --autostash" was called *and* the fast-forward merge shortcut was taken, then the pull failed. This was fixed in commit f15e7cf5cc (pull: ff --rebase --autostash works in dirty repo, 2017-06-01) by simply skipping the fast-forward merge shortcut. Later on "git merge" learned the --autostash option [a03b55530a (merge: teach --autostash option, 2020-04-07)], and so did "git pull" [d9f15d37f1 (pull: pass --autostash to merge, 2020-04-07)]. Therefore it's not necessary to skip the fast-forward merge shortcut anymore when called with --rebase --autostash. Let's always take the fast-forward merge shortcut by essentially reverting f15e7cf5cc. Reviewed-by: Elijah Newren Signed-off-by: Felipe Contreras --- builtin/pull.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index a766d9762c..42cd6c38d8 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -949,7 +949,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct oid_array merge_heads = OID_ARRAY_INIT; struct object_id orig_head, curr_head; struct object_id rebase_fork_point; - int autostash; int rebase_unspecified = 0; int can_ff; @@ -984,8 +983,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &orig_head)) oidclr(&orig_head); - autostash = config_autostash; if (opt_rebase) { + int autostash = config_autostash; if (opt_autostash != -1) autostash = opt_autostash; @@ -1067,13 +1066,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); - if (!autostash) { - if (can_ff) { - /* we can fast-forward this without invoking rebase */ - opt_ff = "--ff-only"; - ran_ff = 1; - ret = run_merge(); - } + + if (can_ff) { + /* we can fast-forward this without invoking rebase */ + opt_ff = "--ff-only"; + ran_ff = 1; + ret = run_merge(); } if (!ran_ff) ret = run_rebase(&newbase, &upstream); From patchwork Fri Dec 18 21:10:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982979 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.8 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 BBB71C2BBD5 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D51723B99 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbgLRVLP (ORCPT ); Fri, 18 Dec 2020 16:11:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLP (ORCPT ); Fri, 18 Dec 2020 16:11:15 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28029C061248 for ; Fri, 18 Dec 2020 13:10:35 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id d8so3248077otq.6 for ; Fri, 18 Dec 2020 13:10:35 -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=fJnlbsKYM0chD/Gthl0v17QGOikKDyUWIw8ZTTLMq28=; b=XH7aZmenEMUyAqMgHNRnKUS6QahzX16fw1amWAeBXMqoVGfGgtM/vgCYBNP7TOfkEP 4677MmPkY4RTuysmvUcGd1lidYM3Iiu/R6TO3nbEotIk86cBEC2KGCojS1LMfnsMeMj4 bLI4hPvZDblPfNEZdyzsi5jtMBJ2Y9dhU9prLv6n1ZCml3lyqELQtJ/65sfmaHz4Aq1k 5Q+uI8bQ5bcG972GeoAYcSH4GsKD93di7DlyPn2kkUlavD+Xyh6/OrZrLlxVQ8M8ybG7 69venrLBXb7vPJDOXtNmNOL+VMq0K3ojnx2U3dKA/v/EwWJOTfDQ9aJR72t7iNDe+jct hnXQ== 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=fJnlbsKYM0chD/Gthl0v17QGOikKDyUWIw8ZTTLMq28=; b=E63ydwnqbaZ/kJ30WeOS/7iVsWRpYzYHzP6XR1UK/ulszTC3QOvCAhn5KaWtgITOp8 EgQFIPdmQWY26SzS3SFOv21sKa9Op+gxTBzGEZvtR36seYtVcOpliZniWxDGVGP1M8Gu mFGibP8DIMQQZNvoKD5urnLnI6w93+ODk2Rm7/E4jVWowrkvztLOwzAVnjhG8RSnae9R ka65nAdLbuhVRrMIpHXuiqyeyiZsR6PC6asXvxeUhjJvNR8pW8P3c3lZXW3UWpGcAda4 Q9vJ34PmwqLiQUbk3tICD/e8NmGTkNzSZnsQGGgQDOGd2s2CslSVkNE2IYuQaemORmmj INDw== X-Gm-Message-State: AOAM533eu4PottwZyioM1iBp3+HuDyhBv29kHCnwFJkYWJJmiYbEx8k4 qkZWQaD42Pc6tT8mOykc4Fe5ClrU7/STuQ== X-Google-Smtp-Source: ABdhPJzg2duQu7voba2GC/4E6hXr4sAnartrR9BZd8O4kEeS18eTDoJEJ3EVxUnpEHdYA1Kce7YNrQ== X-Received: by 2002:a9d:4d8b:: with SMTP id u11mr4253591otk.13.1608325834376; Fri, 18 Dec 2020 13:10:34 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k63sm2000347oia.14.2020.12.18.13.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:33 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 04/13] pull: trivial cleanup Date: Fri, 18 Dec 2020 15:10:17 -0600 Message-Id: <20201218211026.1937168-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-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 store ran_ff. Now it's obvious from the conditionals. Signed-off-by: Felipe Contreras --- builtin/pull.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 42cd6c38d8..21089e5a29 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1055,7 +1055,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase) { int ret = 0; - int ran_ff = 0; struct object_id newbase; struct object_id upstream; @@ -1070,11 +1069,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (can_ff) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; - ran_ff = 1; ret = run_merge(); - } - if (!ran_ff) + } else { ret = run_rebase(&newbase, &upstream); + } if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) From patchwork Fri Dec 18 21:10:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982985 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.8 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 D70C9C3526C for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A998723B8C for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbgLRVLR (ORCPT ); Fri, 18 Dec 2020 16:11:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLR (ORCPT ); Fri, 18 Dec 2020 16:11:17 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C57B7C061257 for ; Fri, 18 Dec 2020 13:10:36 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id q25so3220221otn.10 for ; Fri, 18 Dec 2020 13:10:36 -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=Lsl+sWriWCYORJvslnQcUmwMhoPI7rKMRcrlo3RHonk=; b=D3brVgX3PPiTUNBUIAdxzNtTC9zT0Z12DvTrr7q/C28nde17jOWzLjHbaJdcO9JO9W TdSJylr1dvS1vvAwBAYOvfWaHxGEalCjs7p0LRK3fXxNFrSFKB/HbxaxbSX0tbWqjLiE /M8OjY4uQ/HrHzyyVi9lI+Yq0RthrSyF6pJGGpIk+QcqGfLOaJ0UWjiwwEXhxdNytYfW py8hKIq+vJNdWKCQ+MJ/sRJdxkM/TOC2OpuZ7a4kCikRUd0H7L5FsHrOuzmd5dYhTZya K/kilhRMyEcGNirurtyHNU3ykaOYEWWRud9SBHbpdvqgOCflqAQ0UBdH6F5cb3Kbafxg tJPw== 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=Lsl+sWriWCYORJvslnQcUmwMhoPI7rKMRcrlo3RHonk=; b=YXtfeg+exhhAzzyWuoG/OJepJ356JqgTwuzLxqGPyA793HuE8IS5v2nAjlB8gZWrL2 mxkRqcl7ByM52Qr1piGymv4e1pKdPz7NBTPxh2qZYuq6bxL5aMj3Vo3LNb42SpKYlrZn /G1Xd0Sve7ZKQV6rXsPytm0LLxIWf9utFJlYf1xqQ3AX9/tD8tPopO/UAR/h3CqYS79c wozAKL1JXe2UksxHpXSljIhRKfOf373jHByMjjUuH8uevTuLXtIZNpeGAV3WPbQM9s/A Cn5hiSgFXvKuslAgIQmC+HpSCp2GlZ3xKFZkJh88VfBcrK21smimEROkTy5JhgBuOVO/ 3W5Q== X-Gm-Message-State: AOAM5337GawJ0GftNsUOK7KJIDRcsD5YD/EovBo2+NYgZt2nLEfQI82k eqRR4QOZAgYTYJ80Swf95DeogXSybV/lTQ== X-Google-Smtp-Source: ABdhPJx1hAwNfc8XKetJ/aPu4ImPU40gMc5bfvYR/B8LelUR7LbF3xQ8TLHOSeUhWbC5xssOFsbUAA== X-Received: by 2002:a9d:12d7:: with SMTP id g81mr4374038otg.103.1608325836047; Fri, 18 Dec 2020 13:10:36 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id h7sm2146104otq.21.2020.12.18.13.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:35 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 05/13] pull: trivial whitespace style fix Date: Fri, 18 Dec 2020 15:10:18 -0600 Message-Id: <20201218211026.1937168-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Two spaces unaligned to anything is not part of the coding-style. A single tab is. Signed-off-by: Felipe Contreras --- builtin/pull.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 21089e5a29..48e25a5061 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -126,9 +126,9 @@ static struct option pull_options[] = { /* Options passed to git-merge or git-rebase */ OPT_GROUP(N_("Options related to merging")), OPT_CALLBACK_F('r', "rebase", &opt_rebase, - "(false|true|merges|preserve|interactive)", - N_("incorporate changes by rebasing rather than merging"), - PARSE_OPT_OPTARG, parse_opt_rebase), + "(false|true|merges|preserve|interactive)", + N_("incorporate changes by rebasing rather than merging"), + PARSE_OPT_OPTARG, parse_opt_rebase), OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL, N_("do not show a diffstat at the end of the merge"), PARSE_OPT_NOARG | PARSE_OPT_NONEG), From patchwork Fri Dec 18 21:10:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982983 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 1BBB6C3526D for ; Fri, 18 Dec 2020 21:11:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E917F23B88 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726350AbgLRVLY (ORCPT ); Fri, 18 Dec 2020 16:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgLRVLX (ORCPT ); Fri, 18 Dec 2020 16:11:23 -0500 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F57C0611C5 for ; Fri, 18 Dec 2020 13:10:39 -0800 (PST) Received: by mail-oi1-x232.google.com with SMTP id 9so4332583oiq.3 for ; Fri, 18 Dec 2020 13:10:38 -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=x+F6cRJBos+Vo3d9Mk4QTpObXryw6TFb/P50PLf2xic=; b=Zmi0RFoAOtIWLKbrd+B0VsD+UQ490LuXjYtLgaBWjZ9B8INTFsHhiRu3Aq2avW75tq DxGVv32kTsIrxSiUl57GrjorDA0UIGY09xb1XeIvbGeWLUsQOzC/bfWKluetTBR6TJVq OUUuQKd8vSHr+JgomOmjRvxYTY1gNFcaVuc34LmmXHF9D2uq7ehKDPN3g+h9rsoTx9nz K14+eUMOdxR37D3olXzfFvuIaz5fhmvtaGhDQ4+F1Zuw44gcGg6Sfwps+TzeohDzn2MU HOolSblUjfhNrPlJF1locfQbhQ/biXKxYfUo7yCwihecnacNIG02hKM4khmbq6++qUov lqcw== 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=x+F6cRJBos+Vo3d9Mk4QTpObXryw6TFb/P50PLf2xic=; b=iJRsqFNbK/Huvif0nKN0JtcJNOf5V/NZf6K0yjbv2hV3JNfRoOxI05lHwxHeijrWgJ g6cbw3Yovmo7/oWIJ1xo9tC4i+5iFL/1qeQc560GRQRP+svqU8iXztRrTR9NeGZ/zH0p ocUWhvYjl37CHyigumjY3C90T/6NipMEoFGxfNhsfWmwW4pxHoslLGZIEgNVsdCFksct kSJ4pXEpWy5UEl22EsfmEBvUe10DW32I8AWGaVOrT0QWW9jA9neBVJ3EVBlnyNX/Skk+ ozjkeh3IeBfYmRg5F4xxTPY1PXD3QdStlaHKwFIZPg319yZxbh/Y8mm3X7/mr/Y0nRzY x1wA== X-Gm-Message-State: AOAM5304E0sMu4bOK4sQHafVhgiD4Qp+gfhS8OVEMsosDYTDK8b5KXsN a6ZbTAyX9nELt8yPWLLnE68XAx8xZptQbg== X-Google-Smtp-Source: ABdhPJym00gt1aWAVNBLZxrA2/D1Q5QZt9asGWqoV/sk7cZJrZ5LvyQV2Dzq4EsbGdR1ZGT04tvg0g== X-Received: by 2002:aca:af8f:: with SMTP id y137mr4202254oie.55.1608325838154; Fri, 18 Dec 2020 13:10:38 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id f10sm2145361oti.11.2020.12.18.13.10.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:37 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 06/13] pull: introduce --merge option Date: Fri, 18 Dec 2020 15:10:19 -0600 Message-Id: <20201218211026.1937168-7-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Previously --no-rebase (which still works for backwards compatibility). Now we can update the default warning, and the git-pull(1) man page to use --merge instead of the non-intuitive --no-rebase. Signed-off-by: Felipe Contreras --- Documentation/git-pull.txt | 11 +++++++---- builtin/pull.c | 6 ++++-- t/t7601-merge-pull-config.sh | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 142df1c4a1..195496e63d 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -71,8 +71,8 @@ not possible to fast-forward, so a decision must be made how to synchronize the local, and remote brances. In these situations `git pull` will warn you about your possible -options, which are either merge (`--no-rebase`), or rebase (`--rebase`). -However, by default it will continue doing a merge. +options, which are either `--merge`, or `--rebase`. However, by default +it will continue doing a merge. A merge will create a new commit with two parent commits (`G` and `C`) and a log message describing the changes, which you can edit. @@ -159,8 +159,11 @@ It rewrites history, which does not bode well when you published that history already. Do *not* use this option unless you have read linkgit:git-rebase[1] carefully. ---no-rebase:: - Override earlier --rebase. +-m:: +--merge:: + Force a merge. ++ +Previously this was --no-rebase, but that usage has been deprecated. Options related to fetching ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/builtin/pull.c b/builtin/pull.c index 48e25a5061..1336b59b21 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -129,6 +129,8 @@ static struct option pull_options[] = { "(false|true|merges|preserve|interactive)", N_("incorporate changes by rebasing rather than merging"), PARSE_OPT_OPTARG, parse_opt_rebase), + OPT_SET_INT('m', "merge", &opt_rebase, + N_("incorporate changes by merging"), REBASE_FALSE), OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL, N_("do not show a diffstat at the end of the merge"), PARSE_OPT_NOARG | PARSE_OPT_NONEG), @@ -930,7 +932,7 @@ static void show_advice_pull_non_ff(void) advise(_("Pulling without specifying how to reconcile divergent branches is discouraged;\n" "you need to specify if you want a merge, or a rebase.\n" "\n" - " git pull --no-rebase # the default (merge)\n" + " git pull --merge # the default\n" " git pull --rebase\n" "\n" "You can squelch this message by running one of the following commands:\n" @@ -939,7 +941,7 @@ static void show_advice_pull_non_ff(void) " git config --global pull.rebase true # rebase\n" " git config --global pull.ff only # fast-forward only\n" "\n" - "If unsure, run \"git pull --no-rebase\".\n" + "If unsure, run \"git pull --merge\".\n" "Read \"git pull --help\" for more information.")); } diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 52e8ccc933..6d03e0b9fe 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -60,9 +60,9 @@ test_expect_success 'pull.rebase not set and --rebase given' ' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' -test_expect_success 'pull.rebase not set and --no-rebase given' ' +test_expect_success 'pull.rebase not set and --merge given' ' git reset --hard c0 && - git pull --no-rebase . c1 2>err && + git pull --merge . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' @@ -119,9 +119,9 @@ test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' -test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' ' +test_expect_success 'pull.rebase not set and --merge given (not-fast-forward)' ' git reset --hard c2 && - git pull --no-rebase . c1 2>err && + git pull --merge . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' From patchwork Fri Dec 18 21:10:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982987 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 08B5DC3526E for ; Fri, 18 Dec 2020 21:11:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5C3123B98 for ; Fri, 18 Dec 2020 21:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726374AbgLRVLY (ORCPT ); Fri, 18 Dec 2020 16:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgLRVLX (ORCPT ); Fri, 18 Dec 2020 16:11:23 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE50FC0611CA for ; Fri, 18 Dec 2020 13:10:41 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id s2so4340247oij.2 for ; Fri, 18 Dec 2020 13:10:41 -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=nXD5U3guJClu2AEznHStFRdMM9B1SEyl0CgnQM9fnd0=; b=e8CbyHBX3canU1111zKCJ/Be+zO+Li7mDoaRDkCrI/P2414hxc93L1NBuWlNR2UUMr vrXQEuVh/02O1hftow2Mr/7jw5M7hv9GeVn4CXB2E1x0LIidfuoWyoePt+RrpN4uSwvu SrgsdYc9MaaIlKfqaAZEGGYev9asY3pvSztyVRA/tEOkfL+Lzpegi156U+UfNsGEmrAj GqfWg0nzaHJRo7GDH4AB87FNr8kB/q0TghyuHWvz4UQjXcnTi7Ya38B0VJ1AgRoQX0rM g6Af419IaFK2tedNIff8qENQRhtfSFR9lfmt5s3arYFNPmZ7XUcppNKXh2JGPUdEq1g4 Op+g== 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=nXD5U3guJClu2AEznHStFRdMM9B1SEyl0CgnQM9fnd0=; b=VTqxo4Hk9ss5BO3onKs+UihXXFuIHKKow9QloEkFGyg/9waWajKc9Tmjd3O1fRYQjn 1BCQIKnsud2iFSv4cm0e8+l1GfqkuUeoRnwPjtaWBxvbEIsqpZU2RcY3BK3DfvTwV4n+ h6aeUru4HXlgaw80QXKTSy5Yqg3eOp/ou0Ol7sh3WCt3W3zuH7hv09reDJm/mFTbzo0N DYHt/1xZdne+WtldW1kG9PVHEvBRgqlsiw022BFixYs4vgurBmssErb4ED5R7iWRAViA D/NggjVeq7jvfqkXFEgGatxa6EEM5e6gCY7taR9A6Io2/PUniS1FOGIsHYqkXvG4pyum NJeA== X-Gm-Message-State: AOAM531/5KksVIBshmVVeuPfAYTnPKOHgXIUGfgWP7EGcGKCZcxXJsRA UHksSq3/XLwcLa0T9GnVFO3whCSYnXflTg== X-Google-Smtp-Source: ABdhPJxc+275guVF+gepob92kD9tJJPj0VfBoUzoK4gd6LOBPqZrN/8blbC7jlJPA2dDTuiN5hgDOA== X-Received: by 2002:aca:1004:: with SMTP id 4mr4153475oiq.4.1608325840925; Fri, 18 Dec 2020 13:10:40 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id r10sm2194323oom.2.2020.12.18.13.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:40 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 07/13] rebase: add REBASE_DEFAULT Date: Fri, 18 Dec 2020 15:10:20 -0600 Message-Id: <20201218211026.1937168-8-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By introducing a default we can distinguish when the user has forced an option. Therefore there's no need pass around an extra variable variable (it's the same as opt_rebase == REBASE_DEFAULT), nor is there any need to initialize opt_rebase to an invalid value. Additionally this will allow us to override the default with a configuration, and subsequently the configuration with arguments. Cc: Junio C Hamano Signed-off-by: Felipe Contreras --- builtin/pull.c | 27 ++++++++++++--------------- rebase.h | 3 ++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 1336b59b21..c0a90fa741 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -74,7 +74,7 @@ static char *opt_progress; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; /* Options passed to git-merge or git-rebase */ -static enum rebase_type opt_rebase = -1; +static enum rebase_type opt_rebase; static char *opt_diffstat; static char *opt_log; static char *opt_signoff; @@ -326,7 +326,7 @@ static const char *config_get_ff(void) * looks for the value of "pull.rebase". If both configuration keys do not * exist, returns REBASE_FALSE. */ -static enum rebase_type config_get_rebase(int *rebase_unspecified) +static enum rebase_type config_get_rebase(void) { struct branch *curr_branch = branch_get("HEAD"); const char *value; @@ -346,9 +346,7 @@ static enum rebase_type config_get_rebase(int *rebase_unspecified) if (!git_config_get_value("pull.rebase", &value)) return parse_config_rebase("pull.rebase", value, 1); - *rebase_unspecified = 1; - - return REBASE_FALSE; + return REBASE_DEFAULT; } /** @@ -443,7 +441,7 @@ static void NORETURN die_no_merge_candidates(const char *repo, const char **refs const char *remote = curr_branch ? curr_branch->remote_name : NULL; if (*refspecs) { - if (opt_rebase) + if (opt_rebase >= REBASE_TRUE) fprintf_ln(stderr, _("There is no candidate for rebasing against among the refs that you just fetched.")); else fprintf_ln(stderr, _("There are no candidates for merging among the refs that you just fetched.")); @@ -456,7 +454,7 @@ static void NORETURN die_no_merge_candidates(const char *repo, const char **refs repo); } else if (!curr_branch) { fprintf_ln(stderr, _("You are not currently on a branch.")); - if (opt_rebase) + if (opt_rebase >= REBASE_TRUE) fprintf_ln(stderr, _("Please specify which branch you want to rebase against.")); else fprintf_ln(stderr, _("Please specify which branch you want to merge with.")); @@ -471,7 +469,7 @@ static void NORETURN die_no_merge_candidates(const char *repo, const char **refs remote_name = _(""); fprintf_ln(stderr, _("There is no tracking information for the current branch.")); - if (opt_rebase) + if (opt_rebase >= REBASE_TRUE) fprintf_ln(stderr, _("Please specify which branch you want to rebase against.")); else fprintf_ln(stderr, _("Please specify which branch you want to merge with.")); @@ -951,7 +949,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct oid_array merge_heads = OID_ARRAY_INIT; struct object_id orig_head, curr_head; struct object_id rebase_fork_point; - int rebase_unspecified = 0; int can_ff; if (!getenv("GIT_REFLOG_ACTION")) @@ -973,8 +970,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (!opt_ff) opt_ff = xstrdup_or_null(config_get_ff()); - if (opt_rebase < 0) - opt_rebase = config_get_rebase(&rebase_unspecified); + if (!opt_rebase) + opt_rebase = config_get_rebase(); if (read_cache_unmerged()) die_resolve_conflict("pull"); @@ -985,7 +982,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (get_oid("HEAD", &orig_head)) oidclr(&orig_head); - if (opt_rebase) { + if (opt_rebase >= REBASE_TRUE) { int autostash = config_autostash; if (opt_autostash != -1) autostash = opt_autostash; @@ -1045,17 +1042,17 @@ int cmd_pull(int argc, const char **argv, const char *prefix) die(_("Cannot merge multiple branches into empty head.")); return pull_into_void(merge_heads.oid, &curr_head); } - if (opt_rebase && merge_heads.nr > 1) + if (opt_rebase >= REBASE_TRUE && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); - if (rebase_unspecified && !opt_ff && !can_ff) { + if (!opt_rebase && !opt_ff && !can_ff) { if (opt_verbosity >= 0) show_advice_pull_non_ff(); } - if (opt_rebase) { + if (opt_rebase >= REBASE_TRUE) { int ret = 0; struct object_id newbase; diff --git a/rebase.h b/rebase.h index cc723d4748..34d4acfd74 100644 --- a/rebase.h +++ b/rebase.h @@ -3,7 +3,8 @@ enum rebase_type { REBASE_INVALID = -1, - REBASE_FALSE = 0, + REBASE_DEFAULT = 0, + REBASE_FALSE, REBASE_TRUE, REBASE_PRESERVE, REBASE_MERGES, From patchwork Fri Dec 18 21:10:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982991 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.8 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 BECBDC2BBD5 for ; Fri, 18 Dec 2020 21:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93C7C23B97 for ; Fri, 18 Dec 2020 21:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726386AbgLRVLu (ORCPT ); Fri, 18 Dec 2020 16:11:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbgLRVLt (ORCPT ); Fri, 18 Dec 2020 16:11:49 -0500 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54D4BC0611CB for ; Fri, 18 Dec 2020 13:10:43 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id 9so886427ooy.7 for ; Fri, 18 Dec 2020 13:10: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=nTC2i4Kqiy7b4NRapVUTn/nxdD61UKezGyvzG3JiejU=; b=gpdgbxAudyonMMtrdSRKn+w/T8eLv96yfXAq8aC1XDt21Ztnks5HS35rwxuktFtzSy akxieEoI7iBk0p3t3HbjsgpgpxlY/0hLbRAGJg1WR/Ay8zpiFGnGm15GlMbflN/MaaWt t121deiF355Rxqsn0fYsjwyMR92YydnkXxB2Z0HwKdGCZlq7cHJL26OJlaGjZhxRR2lV yyWTfQJd2z1HjunVd2tn1jOUzsL93jhzEaI0B0CE3B1apM/7Pas8Pqm+O8MHBEItZ/0w 9GqwBcICknkJh5y+p+5lIA+sqM+W8XryxAWB14CQOn2tHPafTMNLA+k1Ei2sz6VJZZub XpmA== 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=nTC2i4Kqiy7b4NRapVUTn/nxdD61UKezGyvzG3JiejU=; b=ThdycU9q0XyQz7TsJMEcQDf4tLGWmk6nR7WGsaab7i7t4iA74B51Pfy/y68b7veXwU dK+DN2Vcjju+yWPt6SAplW36Etnf1QBUeVfHT+QXoitam1s2THgSCnygt1TqKJrAniT3 bo/sK1ItjrniDde2auHUMI3+RdIFUp0et0NcOoA0FEn9b0xWP6yQvNIPxzq2jyEpkyhb WkIniIJ3gtTjxQFoxHkr8c/YrqTHRX6Xs8sx/RQa1TOnHIh2v8Ja3U5u8d1uo1+gIOgY VgDlhUXYSq5x0NV76qUdrNzINqILxKnRykuV8iGHC0+qSUi9IJ9+iOIzqSkHVIfQjklY PcNA== X-Gm-Message-State: AOAM533C27/5Uouyg2Hddca2f+0DsvVO6RaWW5k73u4oXrVBNjE/v/B3 Mi6/kwsYXQpwuXLWC2FrgR1zMa6e6rKNsg== X-Google-Smtp-Source: ABdhPJzwgMLnhAUn33k8EfwNsYM4mUj17BfP7iaWJtNCm3paHGnHulHncuqcxtBTB7uX+ZT0lXjTzg== X-Received: by 2002:a4a:a2c5:: with SMTP id r5mr4245539ool.72.1608325842527; Fri, 18 Dec 2020 13:10:42 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id n16sm2252419oop.9.2020.12.18.13.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:41 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 08/13] pull: move configurations fetches Date: Fri, 18 Dec 2020 15:10:21 -0600 Message-Id: <20201218211026.1937168-9-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we have FETCH_DEFAULT we can fetch the configuration before parsing the argument options. The options will override the configuration, and if they don't; opt_rebase will remain being FETCH_DEFAULT. Signed-off-by: Felipe Contreras --- builtin/pull.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index c0a90fa741..2fd5e44e03 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -951,6 +951,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct object_id rebase_fork_point; int can_ff; + opt_ff = xstrdup_or_null(config_get_ff()); + opt_rebase = config_get_rebase(); + if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -967,12 +970,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) parse_repo_refspecs(argc, argv, &repo, &refspecs); - if (!opt_ff) - opt_ff = xstrdup_or_null(config_get_ff()); - - if (!opt_rebase) - opt_rebase = config_get_rebase(); - if (read_cache_unmerged()) die_resolve_conflict("pull"); From patchwork Fri Dec 18 21:10:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982989 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 05FCFC4361B for ; Fri, 18 Dec 2020 21:11:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C151B23B8C for ; Fri, 18 Dec 2020 21:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbgLRVLu (ORCPT ); Fri, 18 Dec 2020 16:11:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbgLRVLt (ORCPT ); Fri, 18 Dec 2020 16:11:49 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 389F4C0617A7 for ; Fri, 18 Dec 2020 13:10:45 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id p126so4297664oif.7 for ; Fri, 18 Dec 2020 13:10: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=Jy8+czBJC1KsHub/3/U21d5o/JdFjS/drfS0NNOEsUU=; b=kfRPHhAp4vEBONim3AFb3xAlP3dNyvI/4DhcVyXYHJe5SO8FoqtKlEeW1Baz+jY/x8 Kahlx6z0mmmatwHZZ/5+6NU3vefXQCIWSp3EFgkjN9p1dLRIiVUdMttLiXQto4RerzAG 1chxw4DmV2Y7y5h1DJgUYYHayb2TKTYsLCYQeHDYNGu/Zg8maBaV6lVuC4VKyYeRbumi pAISihLSVYe2fneRLP4JEo6iFEPSk8uOdUEmrFtbN0eR+vRBbDAZc68fHFzKWIJgRRpv kooNZAxOP0ioATxvXZFn6lmSCcLyLGv3V8Xht1ZOmR/+10te9nk723VL/GavkAZLJl5S kmoQ== 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=Jy8+czBJC1KsHub/3/U21d5o/JdFjS/drfS0NNOEsUU=; b=SJvkiO0M6/0Zivkb3hfzkNihz+H9mV4bvMdCdnXMOr0PvL/scJWworOZ21YmtOb/UA BZxFblzz81dEavIwWt+0iU5z69CfGEb0qz3ZVBhc0AO3xYWE4yzeuOwd9WHNjZUJIJCb pM8GEOojtTQDS7rSxfalGQWqkOcoKREO0xkbTNFXEfd3L5BV7Nk7nabbFcLIN/sKwPME E+llsDHiaO4LmO8dFZwkx0fZR9E9upBTklA9SYYde8/nh2p96Y8EtSR7TEa/OoCMx1o1 EEVO7H6SMthURQlJlW0/9lbtfXw01qvVDLRfVVdj6Wlc76ct9HNH3nzlSU3f2/RQwY58 DxUQ== X-Gm-Message-State: AOAM530hwnR3sLdHrNjwI+BMD0L0CzzVdbnbgqPYb6rDAoS3Vp7l0Y3h pEiI73hJRedh3y1RkfAmF6Q8iw0ojXh0vg== X-Google-Smtp-Source: ABdhPJwlH9PArtrMbhzCJE2YNhhMhlPHdeUTOChr/htqrZdAAEjffqUeQLiK7QhzahXg5z5RgTVI/g== X-Received: by 2002:a05:6808:6c2:: with SMTP id m2mr4065521oih.123.1608325844436; Fri, 18 Dec 2020 13:10:44 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id o49sm2120564ota.51.2020.12.18.13.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:43 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 09/13] pull: show warning with --ff options Date: Fri, 18 Dec 2020 15:10:22 -0600 Message-Id: <20201218211026.1937168-10-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We want the user to specify either --merge or --rebase, if she doesn't we throw a warning. Using --ff, --no-ff, or --ff-only does not make the merge explicit. For example, if the user has the following configuration: git config pull.rebase true git pull --no-ff A merge is not implied. We should be consistent and either imply a merge; in which case a previous "pull.rebase=true" configuration is overridden, or don't; in which case the warning should be thrown. Cc: Junio C Hamano Signed-off-by: Felipe Contreras --- builtin/pull.c | 2 +- t/t7601-merge-pull-config.sh | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 2fd5e44e03..f1a03ccd14 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1044,7 +1044,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); - if (!opt_rebase && !opt_ff && !can_ff) { + if (!opt_rebase && !can_ff) { if (opt_verbosity >= 0) show_advice_pull_non_ff(); } diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 6d03e0b9fe..7c4607191a 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -96,21 +96,21 @@ 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_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_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_i18ngrep "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' ' @@ -128,19 +128,19 @@ test_expect_success 'pull.rebase not set and --merge given (not-fast-forward)' ' 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_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_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_i18ngrep "Pulling without specifying how to reconcile" err ' test_expect_success 'merge c1 with c2' ' From patchwork Fri Dec 18 21:10:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982993 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 41F63C4361B for ; Fri, 18 Dec 2020 21:11:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14B6D23B8C for ; Fri, 18 Dec 2020 21:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbgLRVLw (ORCPT ); Fri, 18 Dec 2020 16:11:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbgLRVLv (ORCPT ); Fri, 18 Dec 2020 16:11:51 -0500 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CC1C0611CC for ; Fri, 18 Dec 2020 13:10:47 -0800 (PST) Received: by mail-ot1-x32a.google.com with SMTP id d20so3266792otl.3 for ; Fri, 18 Dec 2020 13:10: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=At4/fPLbLHQ0dYuXcHtVXoGbM1YL7nwX6kdmxalFtyM=; b=r7K4g/CM8gIv2YHEW4zQVU/L+ag044oRSgzmHA+K5EKGr1fP9lzNU+SG8Uf8fM9e+8 Gf3nF1FWxlVYsLk/PItRUVUlzfoi14T3Fm+NOBuc0m+3IEcE1Dv5DnVG6bmASlUslK2r pL9lPKZf500PfL2NDAasr+hi4e9gpYKMVoa8XAn1BMEfcH6BbqIuKYKLm2egBU32XEaE dZCAFzmUkQWqZET2wZ12IaNYaVfaM3wfPJ+TWwtbj8gJzAyEfgMphWA7MQeZaqWv8QJl zfKMsR8Lb3AWcsgux0f6tMDqFS1qHH/VWPeF5RzY+loUeLDnJXSPpu3Bc/vkGjUFBJXQ th4w== 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=At4/fPLbLHQ0dYuXcHtVXoGbM1YL7nwX6kdmxalFtyM=; b=ijYSrHkOP5gRbWI4wJ0DuLkjF+v9wskXQt8TDoCVQn47kWnS/yOEeqzfvACk+oAgZX JMsyNihrk73KQa2ctCSy4NXCiiuu+tlgpRdJAUsvQGjNZVWlxtnA/btOkACSfIsa0j9m KQ9qsx8IWAWPaQyGKexiKvlFZXrrdo0O3VEKdghsxUR0F/A9nPRVzN5A7s8xzU/G/yOB 6NMzYs9zMlZAKHrJaQjm2Y5uko+kiCv/FalFZXf8GzadXGRrva3qNK4KdH2mYE/gKKgd 3skScVcwEjffY+Bb/gGOIG4X1Y7qAW9zyzIm4a4giR7nX1Vpxi8alCo/v2QYCVRfb3de sEJg== X-Gm-Message-State: AOAM532MFaILhzddTYtjt0DiLiIsV3VVcmf6ieBBnEF7wROgS+L+i7Cm zb9g62nx6apDKGYtyY53IA766gS60CQ+Cg== X-Google-Smtp-Source: ABdhPJxeL7aCqvv5zPcPJX0MSuTk25oQCtFLHz2gRR2hlT3RAkWe6M3gSat2AG8PjG1nMgIVXiJ0jg== X-Received: by 2002:a9d:17cb:: with SMTP id j69mr2762162otj.6.1608325846097; Fri, 18 Dec 2020 13:10:46 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id q77sm2160234ooq.15.2020.12.18.13.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:45 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras , Theodore Ts'o Subject: [PATCH v2 10/13] pull: add pull.mode Date: Fri, 18 Dec 2020 15:10:23 -0600 Message-Id: <20201218211026.1937168-11-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The evolution of pull options has somewhat served most users, however, they have been found lacking for a very needed trio: merge / rebase / fast-forward-only. Another thing that is missing is the possibility to specify pull options on a per-repository basis, as Theodore Ts'o suggested long time ago [1]. This patch adds a pull.mode option with two possible values (for now); merge and rebase. If set, it overrides what the user has specified in pull.rebase, and it's updated with either --merge, or --rebase. In addition to pull.mode, a 'remote..pullmode' configuration is introduced, so the user can specify the desired options based on the source of the pull, rather than the destination. And of course; new modes like fast-forward-only can be introduced later on. [1] https://lore.kernel.org/git/20130312212027.GE14792@thunk.org Cc: Theodore Ts'o Signed-off-by: Felipe Contreras --- Documentation/config/pull.txt | 6 +++ Documentation/config/remote.txt | 6 +++ Documentation/git-pull.txt | 3 +- builtin/pull.c | 81 +++++++++++++++++++++++++++++++-- rebase.c | 10 ++++ rebase.h | 9 ++++ t/t5520-pull.sh | 54 ++++++++++++++++++++++ t/t7601-merge-pull-config.sh | 14 ++++++ 8 files changed, 178 insertions(+), 5 deletions(-) diff --git a/Documentation/config/pull.txt b/Documentation/config/pull.txt index 5404830609..f4385cde33 100644 --- a/Documentation/config/pull.txt +++ b/Documentation/config/pull.txt @@ -29,6 +29,12 @@ mode. it unless you understand the implications (see linkgit:git-rebase[1] for details). +pull.mode:: + When "git pull" is run, this determines if it would either merge or + rebase the fetched branch. The possible values are 'merge', + and 'rebase'. See "branch..pullmode" for setting this on a + per-branch basis. + pull.octopus:: The default merge strategy to use when pulling multiple branches at once. diff --git a/Documentation/config/remote.txt b/Documentation/config/remote.txt index a8e6437a90..a732c92cf5 100644 --- a/Documentation/config/remote.txt +++ b/Documentation/config/remote.txt @@ -84,3 +84,9 @@ remote..promisor:: remote..partialclonefilter:: The filter that will be applied when fetching from this promisor remote. + +remote..pullmode:: + When "git pull" is run, this determines if it would either merge or + rebase the branches from this remote. The possible values are 'merge', and + 'rebase'. See "pull.mode" for doing this in a non + repository-specific manner. diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 195496e63d..65f8b16a7d 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -72,7 +72,8 @@ synchronize the local, and remote brances. In these situations `git pull` will warn you about your possible options, which are either `--merge`, or `--rebase`. However, by default -it will continue doing a merge. +it will continue doing a merge (you can change that with the `pull.mode` +configuration). A merge will create a new commit with two parent commits (`G` and `C`) and a log message describing the changes, which you can edit. diff --git a/builtin/pull.c b/builtin/pull.c index f1a03ccd14..bfadd585c7 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -27,6 +27,8 @@ #include "commit-reach.h" #include "sequencer.h" +static enum pull_mode_type 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 @@ -49,6 +51,14 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value, return REBASE_INVALID; } +static enum pull_mode_type parse_config_pull_mode(const char *key, const char *value) +{ + enum pull_mode_type v = pull_mode_parse_value(value); + if (v == PULL_MODE_INVALID) + die(_("Invalid value for %s: %s"), key, value); + return v; +} + /** * Callback for --rebase, which parses arg with parse_config_rebase(). */ @@ -60,9 +70,21 @@ static int parse_opt_rebase(const struct option *opt, const char *arg, int unset *value = parse_config_rebase("--rebase", arg, 0); else *value = unset ? REBASE_FALSE : REBASE_TRUE; + + if (*value > 0) + mode = *value >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE; + return *value == REBASE_INVALID ? -1 : 0; } +static int parse_opt_merge(const struct option *opt, const char *arg, int unset) +{ + enum rebase_type *value = opt->value; + mode = PULL_MODE_MERGE; + *value = REBASE_FALSE; + return 0; +} + static const char * const pull_usage[] = { N_("git pull [] [ [...]]"), NULL @@ -129,8 +151,9 @@ static struct option pull_options[] = { "(false|true|merges|preserve|interactive)", N_("incorporate changes by rebasing rather than merging"), PARSE_OPT_OPTARG, parse_opt_rebase), - OPT_SET_INT('m', "merge", &opt_rebase, - N_("incorporate changes by merging"), REBASE_FALSE), + OPT_CALLBACK_F('m', "merge", &opt_rebase, NULL, + N_("incorporate changes by merging"), + PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_merge), OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL, N_("do not show a diffstat at the end of the merge"), PARSE_OPT_NOARG | PARSE_OPT_NONEG), @@ -349,6 +372,31 @@ static enum rebase_type config_get_rebase(void) return REBASE_DEFAULT; } +static enum pull_mode_type config_get_pull_mode(const char *repo) +{ + const char *value; + struct remote *remote; + + remote = remote_get(repo); + + if (remote) { + char *key = xstrfmt("remote.%s.pullmode", remote->name); + + if (!git_config_get_value(key, &value)) { + enum pull_mode_type ret = parse_config_pull_mode(key, value); + free(key); + return ret; + } + + free(key); + } + + if (!git_config_get_value("pull.mode", &value)) + return parse_config_pull_mode("pull.mode", value); + + return PULL_MODE_DEFAULT; +} + /** * Read config variables. */ @@ -935,8 +983,8 @@ static void show_advice_pull_non_ff(void) "\n" "You can squelch this message by running one of the following commands:\n" "\n" - " git config --global pull.rebase false # merge\n" - " git config --global pull.rebase true # rebase\n" + " git config --global pull.mode merge\n" + " git config --global pull.mode rebase\n" " git config --global pull.ff only # fast-forward only\n" "\n" "If unsure, run \"git pull --merge\".\n" @@ -970,6 +1018,31 @@ int cmd_pull(int argc, const char **argv, const char *prefix) parse_repo_refspecs(argc, argv, &repo, &refspecs); + /* + * If the user has not specified --merge or --rebase, fetch pull.mode to override + * pull.rename. + */ + if (!mode) { + mode = config_get_pull_mode(repo); + + switch (mode) { + case PULL_MODE_MERGE: + opt_rebase = REBASE_FALSE; + break; + case PULL_MODE_REBASE: + /* Do not oeverride other rebase modes */ + if (opt_rebase < REBASE_TRUE) + opt_rebase = REBASE_TRUE; + break; + case PULL_MODE_DEFAULT: + if (opt_rebase > 0) + mode = opt_rebase >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE; + break; + default: + break; + } + } + if (read_cache_unmerged()) die_resolve_conflict("pull"); diff --git a/rebase.c b/rebase.c index f8137d859b..bdfca49886 100644 --- a/rebase.c +++ b/rebase.c @@ -33,3 +33,13 @@ enum rebase_type rebase_parse_value(const char *value) return REBASE_INVALID; } + +enum pull_mode_type pull_mode_parse_value(const char *value) +{ + if (!strcmp(value, "merge") || !strcmp(value, "m")) + return PULL_MODE_MERGE; + else if (!strcmp(value, "rebase") || !strcmp(value, "r")) + return PULL_MODE_REBASE; + + return PULL_MODE_INVALID; +} diff --git a/rebase.h b/rebase.h index 34d4acfd74..5ab8f4ddd5 100644 --- a/rebase.h +++ b/rebase.h @@ -13,4 +13,13 @@ enum rebase_type { enum rebase_type rebase_parse_value(const char *value); +enum pull_mode_type { + PULL_MODE_INVALID = -1, + PULL_MODE_DEFAULT = 0, + PULL_MODE_MERGE, + PULL_MODE_REBASE +}; + +enum pull_mode_type pull_mode_parse_value(const char *value); + #endif /* REBASE */ diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 9fae07cdfa..59799ac4d5 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -449,6 +449,16 @@ test_expect_success 'pull.rebase' ' test_cmp expect actual ' +test_expect_success 'pull.mode rebase' ' + git reset --hard before-rebase && + test_config pull.mode rebase && + git pull . copy && + test_cmp_rev HEAD^ copy && + echo new >expect && + git show HEAD:file2 >actual && + test_cmp expect actual +' + test_expect_success 'pull --autostash & pull.rebase=true' ' test_config pull.rebase true && test_pull_autostash 1 --autostash @@ -480,6 +490,18 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' test_cmp expect actual ' +test_expect_success 'remote..pullmode' ' + git reset --hard before-rebase && + git remote add test_remote . && + test_when_finished "git remote remove test_remote" && + test_config remote.test_remote.pullmode rebase && + git pull test_remote copy && + test_cmp_rev HEAD^ copy && + echo new >expect && + git show HEAD:file2 >actual && + test_cmp expect actual +' + test_expect_success 'pull --rebase warns on --verify-signatures' ' git reset --hard before-rebase && git pull --rebase --verify-signatures . copy 2>err && @@ -523,6 +545,17 @@ test_expect_success 'pull.rebase=false create a new merge commit' ' test_cmp expect actual ' +test_expect_success 'pull.mode=merge create a new merge commit' ' + git reset --hard before-preserve-rebase && + test_config pull.mode merge && + git pull . copy && + test_cmp_rev HEAD^1 before-preserve-rebase && + test_cmp_rev HEAD^2 copy && + echo file3 >expect && + git show HEAD:file3.t >actual && + test_cmp expect actual +' + test_expect_success 'pull.rebase=true flattens keep-merge' ' git reset --hard before-preserve-rebase && test_config pull.rebase true && @@ -552,6 +585,16 @@ test_expect_success REBASE_P \ test_cmp_rev HEAD^2 keep-merge ' +test_expect_success REBASE_P \ + 'pull.rebase=preserve rebases and merges keep-merge with pull.mode' ' + git reset --hard before-preserve-rebase && + test_config pull.mode rebase && + test_config pull.rebase preserve && + git pull . copy && + test_cmp_rev HEAD^^ copy && + test_cmp_rev HEAD^2 keep-merge +' + test_expect_success 'pull.rebase=interactive' ' write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && echo I was here >fake.out && @@ -593,6 +636,17 @@ test_expect_success '--rebase=false create a new merge commit' ' test_cmp expect actual ' +test_expect_success '--rebase=false create a new merge commit with pull.mode' ' + git reset --hard before-preserve-rebase && + test_config pull.mode rebase && + git pull --rebase=false . copy && + test_cmp_rev HEAD^1 before-preserve-rebase && + test_cmp_rev HEAD^2 copy && + echo file3 >expect && + git show HEAD:file3.t >actual && + test_cmp expect actual +' + test_expect_success '--rebase=true rebases and flattens keep-merge' ' git reset --hard before-preserve-rebase && test_config pull.rebase preserve && diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 7c4607191a..47fd2e2d05 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -33,6 +33,13 @@ test_expect_success 'pull.rebase not set' ' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' +test_expect_success 'pull.mode set' ' + git reset --hard c0 && + test_config pull.mode merge && + 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 c0 && test_config pull.ff true && @@ -92,6 +99,13 @@ test_expect_success 'pull.rebase not set (not-fast-forward)' ' test_i18ngrep "Pulling without specifying how to reconcile" decoded ' +test_expect_success 'pull.mode set' ' + git reset --hard c2 && + test_config pull.mode merge && + 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 (not-fast-forward)' ' git reset --hard c2 && test_config pull.ff true && From patchwork Fri Dec 18 21:10:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982999 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 6AF54C3526C for ; Fri, 18 Dec 2020 21:11:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DE1E23B8C for ; Fri, 18 Dec 2020 21:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726455AbgLRVLw (ORCPT ); Fri, 18 Dec 2020 16:11:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbgLRVLv (ORCPT ); Fri, 18 Dec 2020 16:11:51 -0500 Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0918C0611CD for ; Fri, 18 Dec 2020 13:10:48 -0800 (PST) Received: by mail-oi1-x22a.google.com with SMTP id s2so4340640oij.2 for ; Fri, 18 Dec 2020 13:10:48 -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=hNEMEKzSDTCVU2kILL0ju1Yn8sQa1nHeURrNwfpMW/Q=; b=BR6pZBq0LSNQ36up+UfLXKtynNGuZN4gmdUmJcQsho/u65jWQ5BWYsGLvozcyrcsek 0d3arG1lxN9BHfYlA6N/z+XlsaJiIHyqIJs/pDXQ89O/x+H7IwtqTJJgxgxiaPL+zIYq AcbjyX48cJrYheZe1cX3rCfE54F0uAGLWTX8K5BxocjtaGnlpuvV0vqsPYiKUl1Wf+hr sKOZg5maYVLPX0bhHTDe+b9R6XhlM8vHrHqNQ3swwCFRulMF/9KH3P5FuMQQcW4sTFH3 uDiaBHBgrHdSyNW2tD51tbeL30ughiYdmMCgwJJEy9qi1qV44ib7NMY+pzmI+KlLvPUH lmtg== 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=hNEMEKzSDTCVU2kILL0ju1Yn8sQa1nHeURrNwfpMW/Q=; b=icpKUXCQYt+s04lFZBFQKcgAWdgoqQCkRGvt60zCj1rCd0W/u4Qv+moeqZzk9mH7zf /It5A/H+whI58ibevyRohlF55x5VeTYGfWthLikG4VvFK1TQ5NkdBOMT+Q4aZrKMPGO7 ZF1UmJ7YC6GYTUe4lY4cMl+3soyernnYzYuSG91wl0j1UkxesWc+Z2710U3ktk5uzlyV J29qUfPxmM53Wdy9sJBi7W5+C9QQEjDENjkB8QXS2/qswuaTq8B4r3Nt+RZDgG32o1lx aiABmDFFF3HnF9+MgDftpd8Jhv6qgWqIzumFjy6za6GebC4R+2S7cfF38RRdxVOLnjah HEjA== X-Gm-Message-State: AOAM533q7JUdldEs7FXuhFDx8URCTSa3HTzttdxTYUO/9Pd8S41jaOeQ wD9R4y9wwKwhdQuR2mb98C2p+7+yFBzVPw== X-Google-Smtp-Source: ABdhPJwIj0uL35ZdNRFaVj3zHzj0HyP5kTUfKcjB31e54pyS76HCM2HBgej6d730+SBH8dEzaJEK2Q== X-Received: by 2002:aca:ba42:: with SMTP id k63mr3995362oif.111.1608325848044; Fri, 18 Dec 2020 13:10:48 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id g12sm2170354oos.8.2020.12.18.13.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:47 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 11/13] pull: add pull.mode=fast-forward Date: Fri, 18 Dec 2020 15:10:24 -0600 Message-Id: <20201218211026.1937168-12-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It is very typical for Git newcomers to inadvertently create merges and worse; pushing them. This is one of the reasons many experienced users prefer to avoid 'git pull', and recommend newcomers to avoid it as well. To escape these problems--and keep 'git pull' useful--it has been suggested that 'git pull' barfs by default if the merge is non-fast-forward, which unfortunately would break backwards compatibility. This patch leaves everything in place to enable this new mode, but it only gets enabled if the user specifically configures it: pull.mode = fast-forward Later on this mode can be enabled by default. For *some* of the long discussions you can read: https://lore.kernel.org/git/20130522115042.GA20649@inner.h.apk.li https://lore.kernel.org/git/1377988690-23460-1-git-send-email-felipe.contreras@gmail.com https://lore.kernel.org/4ay6w9i74cygt6ii1b0db7wg.1398433713382@email.android.com Signed-off-by: Felipe Contreras --- Documentation/config/pull.txt | 4 +-- Documentation/config/remote.txt | 4 +-- builtin/pull.c | 6 ++++- rebase.c | 2 ++ rebase.h | 3 ++- t/t5520-pull.sh | 44 +++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Documentation/config/pull.txt b/Documentation/config/pull.txt index f4385cde33..2b5e813259 100644 --- a/Documentation/config/pull.txt +++ b/Documentation/config/pull.txt @@ -32,8 +32,8 @@ for details). pull.mode:: When "git pull" is run, this determines if it would either merge or rebase the fetched branch. The possible values are 'merge', - and 'rebase'. See "branch..pullmode" for setting this on a - per-branch basis. + 'rebase', and 'fast-forward'. See "branch..pullmode" for setting + this on a per-branch basis. pull.octopus:: The default merge strategy to use when pulling multiple branches diff --git a/Documentation/config/remote.txt b/Documentation/config/remote.txt index a732c92cf5..e7db1d46c1 100644 --- a/Documentation/config/remote.txt +++ b/Documentation/config/remote.txt @@ -87,6 +87,6 @@ remote..partialclonefilter:: remote..pullmode:: When "git pull" is run, this determines if it would either merge or - rebase the branches from this remote. The possible values are 'merge', and - 'rebase'. See "pull.mode" for doing this in a non + rebase the branches from this remote. The possible values are 'merge', + 'rebase', and 'fast-forward'. See "pull.mode" for doing this in a non repository-specific manner. diff --git a/builtin/pull.c b/builtin/pull.c index bfadd585c7..ef23d8a52f 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -985,7 +985,7 @@ static void show_advice_pull_non_ff(void) "\n" " git config --global pull.mode merge\n" " git config --global pull.mode rebase\n" - " git config --global pull.ff only # fast-forward only\n" + " git config --global pull.mode fast-forward\n" "\n" "If unsure, run \"git pull --merge\".\n" "Read \"git pull --help\" for more information.")); @@ -1027,6 +1027,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) switch (mode) { case PULL_MODE_MERGE: + case PULL_MODE_FAST_FORWARD: opt_rebase = REBASE_FALSE; break; case PULL_MODE_REBASE: @@ -1117,6 +1118,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); + if (mode == PULL_MODE_FAST_FORWARD && !can_ff) + die(_("The pull was not fast-forward, please either merge or rebase.\n")); + if (!opt_rebase && !can_ff) { if (opt_verbosity >= 0) show_advice_pull_non_ff(); diff --git a/rebase.c b/rebase.c index bdfca49886..9fe99b5b16 100644 --- a/rebase.c +++ b/rebase.c @@ -40,6 +40,8 @@ enum pull_mode_type pull_mode_parse_value(const char *value) return PULL_MODE_MERGE; else if (!strcmp(value, "rebase") || !strcmp(value, "r")) return PULL_MODE_REBASE; + else if (!strcmp(value, "fast-forward") || !strcmp(value, "f")) + return PULL_MODE_FAST_FORWARD; return PULL_MODE_INVALID; } diff --git a/rebase.h b/rebase.h index 5ab8f4ddd5..e66a73feb4 100644 --- a/rebase.h +++ b/rebase.h @@ -17,7 +17,8 @@ enum pull_mode_type { PULL_MODE_INVALID = -1, PULL_MODE_DEFAULT = 0, PULL_MODE_MERGE, - PULL_MODE_REBASE + PULL_MODE_REBASE, + PULL_MODE_FAST_FORWARD }; enum pull_mode_type pull_mode_parse_value(const char *value); diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 59799ac4d5..45d818065f 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -873,4 +873,48 @@ test_expect_success 'git pull --rebase against local branch' ' test_cmp expect file2 ' +setup_other () { + test_when_finished "git checkout master && git branch -D other test" && + git checkout -b other $1 && + >new && + git add new && + git commit -m new && + git checkout -b test -t other && + git reset --hard master +} + +setup_ff () { + setup_other master +} + +setup_non_ff () { + setup_other master^ +} + +test_expect_success 'fast-forward (pull.mode=fast-forward)' ' + setup_ff && + git -c pull.mode=fast-forward pull +' + +test_expect_success 'non-fast-forward (pull.mode=fast-forward)' ' + setup_non_ff && + test_must_fail git -c pull.mode=fast-forward pull +' + +test_expect_success 'non-fast-forward with merge (pull.mode=fast-forward)' ' + setup_non_ff && + git -c pull.mode=fast-forward pull --merge +' + +test_expect_success 'non-fast-forward with rebase (pull.mode=fast-forward)' ' + setup_non_ff && + git -c pull.mode=fast-forward pull --rebase +' + +test_expect_success 'non-fast-forward error message (pull.mode=fast-forward)' ' + setup_non_ff && + test_must_fail git -c pull.mode=fast-forward pull 2> error && + test_i18ngrep "The pull was not fast-forward" error +' + test_done From patchwork Fri Dec 18 21:10:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982995 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.8 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 92454C2D0E4 for ; Fri, 18 Dec 2020 21:11:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 630DD23B8C for ; Fri, 18 Dec 2020 21:11:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726553AbgLRVLx (ORCPT ); Fri, 18 Dec 2020 16:11:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbgLRVLw (ORCPT ); Fri, 18 Dec 2020 16:11:52 -0500 Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B965C0611CE for ; Fri, 18 Dec 2020 13:10:50 -0800 (PST) Received: by mail-oo1-xc2c.google.com with SMTP id k7so892317ooa.0 for ; Fri, 18 Dec 2020 13:10:50 -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=WCoF4V5PqhUQYsEAL18dofYAQioY8Ya2E2hUmGPD06c=; b=OMRoJUr9SzmeweByYhjwFUf3w7R4MyCa/HPcM/8PYJFG9R+N2te9o6aK2v2cTluKfa Z9dvzTpWNWAkmk6gZ6grU+0UH6u+d7VkWgDWMJLJ9Y6PFaueyScqOGWBR+YAEJQzIGBc tnwjIKVPUUyDSFnlZ7ytr4hLMpBqDGIvDI0/rS+nLEgE+z94+9kpN4cfmcON0jexcT0x tjdOR+CVF6ujWcVR8eQgkt7JmB5ICIfO6CZoqDxhn0v0IExK+A1qKgV5OWwY+vMkRppG CJ69FCn2kMFXaxZZgNjxrkIhfJaIyTZfLm5u53z3Z3yHdYydnow8tr0DuL6bDqSW5GrP ZCww== 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=WCoF4V5PqhUQYsEAL18dofYAQioY8Ya2E2hUmGPD06c=; b=J7hq3Kg4C7EsjJYtuhFrcBARr72FJezJzLq+s/QgajK2d5Hq4rChPLqfjTKEArKZF8 R3nR+epsy3MRvyNdf6guqdpm4grGaXbDUVe3reY2R+uIpg8pTKaHEDqQNy8y/G+SWzkt VU7+x6IhTbMlyECleVGgbcllB9ZL40/1w2JtWZ/ZlUBNbfwp0Nw1IxmK2mAZEcnuucKQ 543Q5NVV8c/50xZBlWWNW7wZ6w1RvzULZoQ5TGuq9UDI7glyXWiH2USv4Y4rbm089L7X UUfoBiu+vxIP2j/Bm6g5rVCURZwLu/ZRSEiiIrfh2gmwP7g0PTCEaJvruNIuTE39Ad8k 9DHQ== X-Gm-Message-State: AOAM533me1ZkfLdbdaba7M0EQ+xpQ8aclc/ysBYO5AaAjiaUyqUfxGQ1 1PWiz77I1vLZF2QNHrRjNWH++HLZM8NKtQ== X-Google-Smtp-Source: ABdhPJz7o4UHhWudLcOoRe4TgRJpt1FpEQzkjPu5a8ZaE9xnTjxPwVdyqv0CRd7wwr/K+Vd8aclPtg== X-Received: by 2002:a4a:4046:: with SMTP id n67mr4235869ooa.91.1608325849674; Fri, 18 Dec 2020 13:10:49 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id u3sm2130682otk.31.2020.12.18.13.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:49 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 12/13] pull: reorganize mode conditionals Date: Fri, 18 Dec 2020 15:10:25 -0600 Message-Id: <20201218211026.1937168-13-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that everything is in place we can shuffle around the conditionals so it's clearer what we are trying to do. No functional changes. Signed-off-by: Felipe Contreras --- builtin/pull.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index ef23d8a52f..ad8afabe9b 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1118,12 +1118,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); - if (mode == PULL_MODE_FAST_FORWARD && !can_ff) - die(_("The pull was not fast-forward, please either merge or rebase.\n")); - - if (!opt_rebase && !can_ff) { - if (opt_verbosity >= 0) + if (!can_ff) { + if (!mode && opt_verbosity >= 0) show_advice_pull_non_ff(); + + if (mode == PULL_MODE_FAST_FORWARD) + die(_("The pull was not fast-forward, please either merge or rebase.\n")); } if (opt_rebase >= REBASE_TRUE) { From patchwork Fri Dec 18 21:10:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11982997 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 57169C2BBD5 for ; Fri, 18 Dec 2020 21:11:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16C7C23B8C for ; Fri, 18 Dec 2020 21:11:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726598AbgLRVLy (ORCPT ); Fri, 18 Dec 2020 16:11:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726499AbgLRVLw (ORCPT ); Fri, 18 Dec 2020 16:11:52 -0500 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DDC6C0611CF for ; Fri, 18 Dec 2020 13:10:52 -0800 (PST) Received: by mail-ot1-x32e.google.com with SMTP id 11so3224457oty.9 for ; Fri, 18 Dec 2020 13:10:52 -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=YiPxE17V8hJz9o3ZjklqM7GvBtwPNsM6SC1G7fOVRRE=; b=CEXeVd/4nWeN0OgqlNZJsf7Rp8+oRI9CwvVFJaiT8GSEMaIKmzR/BNA52REbSuh+7l /PBrPSdHcsdc61zhvlH131utPIaKetKrHvWiQLWqQz67d4v7XSjVtolLALXlDDVXc4O2 FcP+YY4uizYoWDXj3t9Wr07lheioSDLIML28HnLJ2JHfsWqaaeUxqUeYx1jgXff3l1Ll GGyVCHIY4e7AHlwq8VtatUQWDVrkukcEYpg2cLkSXCrdjkgGcw8y6+YIhpZws8QPAku5 SOi9cYLhp4Z4cRDVrrCkE2jqjJqFd263JbW6DVVs/SoJab9jAeoxT5y337z23DdTuF+U 1UZA== 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=YiPxE17V8hJz9o3ZjklqM7GvBtwPNsM6SC1G7fOVRRE=; b=QBuZ1d1wJGhfKP6RkDzq/fBTXC+V9KYEjpRuMdVmY/67Z0i2dPOnsG1D4+/6sUiKup gsjaXClVVjFHCJgVNXUv649e0zms9mX0inqTf7lQT2eo/kcsurZ3czHj/G4TFQnvhtNN odCFl/NRXZRml8y9DArB7EArCVVVmD6WL1EYv/w+82AkEK6BvBUUsNaZIHbhdM11B4yg Oo9QG7dqFPPdaX9Jua501NdF2GwuT8nKsmkNkdvIvix3rCLFXSRiLcN8mV/1vXuJMKoI Z0QTJ+d6ayzm+ud3EUoiBajXDlKobFEbq9RqFqc8/b8n7zN8m/5m3Jj1h3nAV6F5HGCJ 8HSg== X-Gm-Message-State: AOAM532F9p05xHeCmP1a7EXnWbgGQ5CTAduzS0WWSb7ba+OadgPH/O0a DI0b+SFrTpHrviMclAvBlFONax10N1rlMw== X-Google-Smtp-Source: ABdhPJyVZuyqG5fzuBGddRJQ8mFsXKM5sc9jZmqk068C64Pq3iWOUPxhJ5GEYS2SAYhrpGy+LSdOFw== X-Received: by 2002:a05:6830:22eb:: with SMTP id t11mr4495332otc.114.1608325851675; Fri, 18 Dec 2020 13:10:51 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id t13sm2014515oih.26.2020.12.18.13.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 13:10:51 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Elijah Newren , Felipe Contreras Subject: [PATCH v2 13/13] pull: improve --rebase and pull.rebase interaction Date: Fri, 18 Dec 2020 15:10:26 -0600 Message-Id: <20201218211026.1937168-14-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.30.0.rc0 In-Reply-To: <20201218211026.1937168-1-felipe.contreras@gmail.com> References: <20201218211026.1937168-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Currently --rebase without argument overrides pull.rebase: git config pull.rebase merges git pull --rebase Up until now this hasn't been a big issue, since user has not been forced to specify a merge, or a rebase. But with the introduction of --merge and pull.mode, the user could in theory have the following configuration: git config pull.mode merge git config pull.rebase merges In such case, the user would expect: git pull --rebase To be the same as: git pull --rebase=merges If the user wants to override the configuration, she can do: git pull --rebase=true Signed-off-by: Felipe Contreras --- builtin/pull.c | 10 ++++++++-- t/t5520-pull.sh | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index ad8afabe9b..4e8e9d85a2 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -68,8 +68,14 @@ static int parse_opt_rebase(const struct option *opt, const char *arg, int unset if (arg) *value = parse_config_rebase("--rebase", arg, 0); - else - *value = unset ? REBASE_FALSE : REBASE_TRUE; + else { + if (!unset) { + /* --rebase shouldn't override pull.rebase=merges (and others) */ + if (*value < REBASE_TRUE) + *value = REBASE_TRUE; + } else + *value = REBASE_FALSE; + } if (*value > 0) mode = *value >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE; diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 45d818065f..d0f5722eab 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -595,6 +595,16 @@ test_expect_success REBASE_P \ test_cmp_rev HEAD^2 keep-merge ' +test_expect_success REBASE_P \ + 'pull.rebase=preserve interacts correctly with pull.mode and --rebase' ' + git reset --hard before-preserve-rebase && + test_config pull.mode merge && + test_config pull.rebase preserve && + git pull --rebase . copy && + test_cmp_rev HEAD^^ copy && + test_cmp_rev HEAD^2 keep-merge +' + test_expect_success 'pull.rebase=interactive' ' write_script "$TRASH_DIRECTORY/fake-editor" <<-\EOF && echo I was here >fake.out &&