From patchwork Wed Nov 25 03:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930269 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 D3156C64E7D for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A31320872 for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EcyJMDz4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbgKYD34 (ORCPT ); Tue, 24 Nov 2020 22:29:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3z (ORCPT ); Tue, 24 Nov 2020 22:29:55 -0500 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6BD9C0613D4 for ; Tue, 24 Nov 2020 19:29:42 -0800 (PST) Received: by mail-oo1-xc42.google.com with SMTP id l10so174790ooh.1 for ; Tue, 24 Nov 2020 19:29:42 -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=+BoELlIO2Np/7X0XEhnINPzKgRHlCgI89Vir8ImGdC4=; b=EcyJMDz4WXyEsW/88LQgzwuVA0HrvcpJXFUYH/IpQXxeDFm3Fp9fh4Y2VrhEGYssCp SnJRbzGJ1jLga2UY9pcSGFck3VMabtRmrExbjeY8n+mag0AZnUpswRjqN1YwlCZgB6yM KKJ+kPXRReuCXIeFf63uThPo2jSeD08GxKCihUA82j0seVz5d+srFTnyAc7HEfUhadez 4OKbNE3GYcBv9N+OYpbeRE3XMw44GMF358yl6X1Kivgkqjz6+Cc75PIq6wKzJVpo0f65 qvK+H53Qt7WUdzQaRZhK2DtZMa7j5Yv4VoUq22jpt0elLH39JEyx7noOXqdAiOMkmFjx Vuvw== 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=+BoELlIO2Np/7X0XEhnINPzKgRHlCgI89Vir8ImGdC4=; b=W1cdzSnsGnthfipnwNvj5rABWITbQjdidAZ+5UO7rtWsiX9y2tqG4u7zLqyuZE81sf 2IlFK0Uj7KH7gVNAxXrZAycAx7xwGV3LhSrUVYes5yOwNTfMymIoCctswq/gnYPbVaSU q1gc1IIhxnLZmNQr5EiOUy7IUHe+NRES9twhGAn2JMmb6AvYFPuevGYe8DGx5VZxmqLh w7szybcOKhXdzV9rMS4Gv1rhF6BRTqHjO90/ihXqsB27WK/TBHkKkQIHcXrIpNOmRIfL NvpjGJ6dpBtkQUuaivfydWxXDjpHC4N1xkD9L7uGL9H4rWsKouTJB9PF2+kPkuYeu1PB Hsmw== X-Gm-Message-State: AOAM533WyjDSIBIM1BXt/4pTij0aSOdkzxomBWGYWsQvaFdnDQbB1IxN cndCyFw1poxq6MvbUuoFJzKeoD1a5SNNTQ== X-Google-Smtp-Source: ABdhPJxCud00f8gR/8Z99kvh+ajRhd6bKoKbWgqG+5my1f9C4MJCpb2QHIN4MTIoyNkVE1FHqBeccQ== X-Received: by 2002:a4a:5857:: with SMTP id f84mr1303003oob.34.1606274982134; Tue, 24 Nov 2020 19:29:42 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id s131sm655305oie.58.2020.11.24.19.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:41 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 01/10] pull: refactor fast-forward check Date: Tue, 24 Nov 2020 21:29:29 -0600 Message-Id: <20201125032938.786393-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This way we will be able to do the check unconditionally (merge or rebase). Signed-off-by: Felipe Contreras --- builtin/pull.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 17aa63cd35..e2de0d4c91 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -906,6 +906,20 @@ static int run_rebase(const struct object_id *curr_head, return ret; } +static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_head) +{ + int ret; + struct commit_list *list = NULL; + struct commit *merge_head, *head; + + head = lookup_commit_reference(the_repository, orig_head); + commit_list_insert(head, &list); + merge_head = lookup_commit_reference(the_repository, orig_merge_head); + ret = repo_is_descendant_of(the_repository, merge_head, list); + free_commit_list(list); + return ret; +} + int cmd_pull(int argc, const char **argv, const char *prefix) { const char *repo, **refspecs; @@ -1016,22 +1030,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { - struct commit_list *list = NULL; - struct commit *merge_head, *head; - - head = lookup_commit_reference(the_repository, - &orig_head); - commit_list_insert(head, &list); - merge_head = lookup_commit_reference(the_repository, - &merge_heads.oid[0]); - if (repo_is_descendant_of(the_repository, - merge_head, list)) { + if (get_can_ff(&orig_head, &merge_heads.oid[0])) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ran_ff = 1; ret = run_merge(); } - free_commit_list(list); } if (!ran_ff) ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point); From patchwork Wed Nov 25 03:29:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930253 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 3AA5BC63798 for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A86CF20872 for ; Wed, 25 Nov 2020 03:30:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IfER16YD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbgKYD3p (ORCPT ); Tue, 24 Nov 2020 22:29:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3o (ORCPT ); Tue, 24 Nov 2020 22:29:44 -0500 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C7BC0613D6 for ; Tue, 24 Nov 2020 19:29:44 -0800 (PST) Received: by mail-ot1-x344.google.com with SMTP id 79so975977otc.7 for ; Tue, 24 Nov 2020 19:29:44 -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=Op5vJWDDN2Q3cMBDBTBcU4vctNwMOESdbcvnV8xMkeo=; b=IfER16YDNWK6OAFKyKaRua1bhMAy0syVW6/gDpG0kjHdXK6njMa9i1rOvIgJ59nbqX 3w2qf9PCF/j6+bLL3lP50o6HivX2pZO3Z+7pL3C+TIquTpcpJ+jvEnJ/pDOOGivIh7qz qmV4RlFJVkQ9OUGzfKp0IXNeQq0WRqfoYLTcPF7L0clicL3KArTmfIVlOlAf/D88gc9y lm4cVZlzwYzac/w/ozcAXvpeJjl/eNj3Jqh2pcQBRPJ3a9vo+GkYRsPUwwMe8fF8DY1B h5+omQk1VErFUehS8E/0WkpFWsQeSO+UDh4l2kzJhJBeflHcqI3/JSvHPQVaDE6nsu2N niJA== 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=Op5vJWDDN2Q3cMBDBTBcU4vctNwMOESdbcvnV8xMkeo=; b=OJts3owPJ1UGu8yYp5WqwmPr9UVpIKXK2sGUWjeqcZ/Y0nZpuvwOUC262Eyfg/A2GJ XTELFeht4v4IsVjVtmzmncXIHw+mvTCQ+v0OI5AeccayMXVv49pj/2ji9/haw/b8Wywt dv53TDL2iwpoQSWynRanpIgZAZ+44T5KVfay2oQMLEY6U8RwidgDRXXfaZs/yO4TPTPR ZC1BMHkx/HuXUyBGNGEuFNCMs3xZMUjt9Z8OrEbCZMOq0BVgAp97/TCiKfJkbi8N7WP9 +BFZZnAKp3BKJr/f2Iox/2SDQR83rHaaow8pzwFAK1RKwTV6Tn7x5k++Hs9e0roRxQYz MZxg== X-Gm-Message-State: AOAM532FeIWoAb0cpCmLH10dVclJnia64DUmLOzUWCCKiNbt1twFdH5q mVH5gd3sJS1EwaeM6Lbd0qiyX3z4MHw1lg== X-Google-Smtp-Source: ABdhPJxoQTQMCiZ4cwJ7owhA8a23NS9PwFqUWwqT3kHCKocZWF3oy1pw3nTZ8i24W33IqvBvXp9fsQ== X-Received: by 2002:a05:6830:3099:: with SMTP id f25mr1402732ots.77.1606274983852; Tue, 24 Nov 2020 19:29:43 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id s28sm574817otd.2.2020.11.24.19.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:43 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 02/10] pull: cleanup autostash check Date: Tue, 24 Nov 2020 21:29:30 -0600 Message-Id: <20201125032938.786393-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This essentially reverts commit f15e7cf5cc. Once commit d9f15d37f1 introduced the autostash option for the merge mode, it's not necessary to skip the fast-forward run_merge() when autostash is set. Signed-off-by: Felipe Contreras --- builtin/pull.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index e2de0d4c91..eaa268c559 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -926,7 +926,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; if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -959,8 +958,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; @@ -1029,13 +1028,11 @@ int cmd_pull(int argc, const char **argv, const char *prefix) recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); - if (!autostash) { - if (get_can_ff(&orig_head, &merge_heads.oid[0])) { - /* we can fast-forward this without invoking rebase */ - opt_ff = "--ff-only"; - ran_ff = 1; - ret = run_merge(); - } + if (get_can_ff(&orig_head, &merge_heads.oid[0])) { + /* we can fast-forward this without invoking rebase */ + opt_ff = "--ff-only"; + ran_ff = 1; + ret = run_merge(); } if (!ran_ff) ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point); From patchwork Wed Nov 25 03:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930255 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 77A53C63777 for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E642F2087C for ; Wed, 25 Nov 2020 03:30:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nbeven52" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727402AbgKYD3q (ORCPT ); Tue, 24 Nov 2020 22:29:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3q (ORCPT ); Tue, 24 Nov 2020 22:29:46 -0500 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42179C0613D6 for ; Tue, 24 Nov 2020 19:29:46 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id y24so1004504otk.3 for ; Tue, 24 Nov 2020 19:29:46 -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=G+qUZvG5cVmpBLeKyUiG5isfp33kmjrbi203XrgYD3U=; b=nbeven52iW0K6SuBCSgZdso3eTcrAkM+FlkIP0qBs/67IopcYRrGINJMvQNBn1dpCJ rSqlJShUCh/d2o3gS+B9YkRVofnf1/C7uXgEngboPGOf164lJGvYQSfX7sdk9sgU4jwZ LMvmdrtbuWM8i+D4QDhvQYjb6lf7j77tqIX9wcH3UpFIp+7fCRVpMZkuJhQxhibVNOE+ p6NSsK8Z0VMWZF0bv2wsPVzQuhdi3DNfD/lF9Q6LeeOvXjNsZ/tHPY/qxLTY+C+XQmqY oPPt1isgxlX8UmyrHjLrpVCUxWCpzaIfCU7l/pKnwSgdFrPk9rEa+VxptuIxxLIwu0Rg BKpw== 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=G+qUZvG5cVmpBLeKyUiG5isfp33kmjrbi203XrgYD3U=; b=tPi94Of3Nid3UZqXV470/E2m/k5BIl7KLRLfQVzoU5bQ7/8rRC59KAwBd4zkw3XXHw HXoA1M1g4suJDtS7IUw9/NCp6um1jw4DRW8qQSffZJbQY/9lQRS8paEKCAMTwQ0hyPG2 kPIc5kTzUl34Vg5SBGkxiUI8Q6TPivIJeqmSWI8YnDFooT8aFCXr/pRZudYKM7+dLMgG o9rKRvQLRWg0t9jHO8btmor7lmmQ2UHeUecSeCPeT19tguuGLkHngIlzT0b7CpBzIgr6 jJ1UP2v5VpeuxBmW5UvQE3mhkQqCwTYdfG+3sXHE6U8/lmwYPipED7yHosRjRyIOnBBF NqRw== X-Gm-Message-State: AOAM53167/VmamDntY3abZC/Z2J0Ongmh49+bbcvLeoJJfC3aZRKNNv4 ybXCKmG7bwlHQaJe3etFkqy2sMFjEHLcqw== X-Google-Smtp-Source: ABdhPJxRdIjD94zNjA5RkntE+3KmpdfX3XqoNgRTbjDWjv/NO8FKn0OvT8OIZg5DTX/DT/OnuMLqfg== X-Received: by 2002:a05:6830:19f4:: with SMTP id t20mr1357745ott.239.1606274985473; Tue, 24 Nov 2020 19:29:45 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id b23sm622495ooa.13.2020.11.24.19.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:44 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 03/10] pull: trivial cleanup Date: Tue, 24 Nov 2020 21:29:31 -0600 Message-Id: <20201125032938.786393-4-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index eaa268c559..121b9fb0e1 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1023,19 +1023,18 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase) { int ret = 0; - int ran_ff = 0; if ((recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); + if (get_can_ff(&orig_head, &merge_heads.oid[0])) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; - ran_ff = 1; ret = run_merge(); - } - if (!ran_ff) + } else { ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point); + } if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) From patchwork Wed Nov 25 03:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930261 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 860B0C64E75 for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 325662075A for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zl2phbFX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727412AbgKYD3t (ORCPT ); Tue, 24 Nov 2020 22:29:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3s (ORCPT ); Tue, 24 Nov 2020 22:29:48 -0500 Received: from mail-oo1-xc41.google.com (mail-oo1-xc41.google.com [IPv6:2607:f8b0:4864:20::c41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2535CC0613D6 for ; Tue, 24 Nov 2020 19:29:48 -0800 (PST) Received: by mail-oo1-xc41.google.com with SMTP id i13so163890oou.11 for ; Tue, 24 Nov 2020 19:29: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=M0pc6VuEbfwATsQhF7UER4sXqH17WZgWHxeF74B6unY=; b=Zl2phbFX523RQM4LRIS2Ba0xV6WH17taSjVF1aUDCWSzxyCsSvCGak2nzMQcvcC5cH E1/ZdOP9KYnawMbvHvixjW+E8HQm6A+G2Z6LpNeAOwnTyxP9HMUGVB/CMsF0NHVcHjqu fjeaZuGxixlwsFOPOLfAeTIkl16LPCEx8NmgQUyM1tk77OfrJ0Sj4kPQ3O95Ezk0MPEd uaHk21OWrjYPrK4taKZQe7vNLxsm4sfLDzAtJTBD41GLmLVu5BebW7pv3l4DYjnes6Uk NkiunX8WRROwyXdtGh+M4ARKEq62OfZmQB6C9rDSgXA7uh7opid/T1nvDaseI2LwTGsG CPCg== 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=M0pc6VuEbfwATsQhF7UER4sXqH17WZgWHxeF74B6unY=; b=gkHRpXBG5rHSduvf5SEPcIjSlN/NGVzVcaB8p/1iJNfhS9bqw90YKvPZDbgHcdy751 wpI5n7ymAEBlgI5/5J6vllLW8KWDieIbOpnLdd5cyex2y+G6B2pbO9BdB5OFVWbFNGkk 0SPfFgOyEWpe/BI0DmE8WO6jgSCQfsL2gY2aYs4WiI/kKb5LMkPYTJaCZXk9lBpJ7NOg eSfLyE0uIBZeaeq7q/2DynsKVnVuik+w25MEx50wGAJs2Z9G9LaB5hSsxGHf4fAzL7Y0 iKN/EOF3Ao87eRy+DeP+hhxHrEDnKMlqVQVUP5vonxb0S5Fll0qPjLs3/JL5MgXvvStg nYHA== X-Gm-Message-State: AOAM5324+rPiPJN/87XCm2QhkL3sU6hNd+j2ej+jbEnLTvMQWOQGpKcM jVYXXmvHZ3SRwVjanDXN3BA0sYTIGbPV8g== X-Google-Smtp-Source: ABdhPJztQ1v+R2mM0ZCNTzcLsvvTi8Ms7oRGfWqYWbLOFRebObsGfeaSudgON+E5xozB14/Qiu3Paw== X-Received: by 2002:a4a:45c3:: with SMTP id y186mr1290192ooa.13.1606274987307; Tue, 24 Nov 2020 19:29:47 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id o7sm573521otk.44.2020.11.24.19.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:46 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 04/10] pull: move default warning Date: Tue, 24 Nov 2020 21:29:32 -0600 Message-Id: <20201125032938.786393-5-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Up to the point where can check if we can fast-forward or not. No functional changes. Signed-off-by: Felipe Contreras --- builtin/pull.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 121b9fb0e1..9a0f7937c2 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -27,6 +27,8 @@ #include "commit-reach.h" #include "sequencer.h" +static int default_mode; + /** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is @@ -344,20 +346,7 @@ static enum rebase_type config_get_rebase(void) if (!git_config_get_value("pull.rebase", &value)) return parse_config_rebase("pull.rebase", value, 1); - if (opt_verbosity >= 0 && !opt_ff) { - warning(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" - " git config pull.ff only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); - } + default_mode = 1; return REBASE_FALSE; } @@ -926,6 +915,7 @@ 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 can_ff; if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -1021,6 +1011,23 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); + can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); + + if (default_mode && opt_verbosity >= 0 && !opt_ff) { + warning(_("Pulling without specifying how to reconcile divergent branches is\n" + "discouraged. You can squelch this message by running one of the following\n" + "commands sometime before your next pull:\n" + "\n" + " git config pull.rebase false # merge (the default strategy)\n" + " git config pull.rebase true # rebase\n" + " git config pull.ff only # fast-forward only\n" + "\n" + "You can replace \"git config\" with \"git config --global\" to set a default\n" + "preference for all repositories. You can also pass --rebase, --no-rebase,\n" + "or --ff-only on the command line to override the configured default per\n" + "invocation.\n")); + } + if (opt_rebase) { int ret = 0; if ((recurse_submodules == RECURSE_SUBMODULES_ON || @@ -1028,7 +1035,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); - if (get_can_ff(&orig_head, &merge_heads.oid[0])) { + if (can_ff) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ret = run_merge(); From patchwork Wed Nov 25 03:29:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930257 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 B5798C6379D for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AAC920872 for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dLbRIDet" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727429AbgKYD3u (ORCPT ); Tue, 24 Nov 2020 22:29:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3u (ORCPT ); Tue, 24 Nov 2020 22:29:50 -0500 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DC3C0613D6 for ; Tue, 24 Nov 2020 19:29:49 -0800 (PST) Received: by mail-ot1-x341.google.com with SMTP id k3so958716otp.12 for ; Tue, 24 Nov 2020 19:29:49 -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=ezc2UR3JD/F3kAcBnenZQ+LV7lq4+/SBkm8KLvsJNBQ=; b=dLbRIDetm6VvePozfuFQtRCpZ94n8mqt+hyL6fL39To0PlAgD9WH3npk8nfsKs7V6f LSQZiysizo6PMItWVwtiF6TtzR/EeyTaGJNGdLOlTPeDUAz0MZvW6R2llCNujq5aCieL Xl2J3UXQrBnO16nvJemwZBFDNJt0RUURMeElr2iVVVccMnBaWCztOk+rhc/Ez9lXLwJf WPc2S+DjMGSGmDhaC6/c80o0gwVt2Ew/4jdjNsI4EsLHcCg8Rg1MR/luIb1SquU+I8XQ /529Y/yqARoLfvm2HdBnI+cNX38lZSGEsJ4TzlnNhIYhQGZwQCe6EsEbI8e9/lfx9dyk rdJA== 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=ezc2UR3JD/F3kAcBnenZQ+LV7lq4+/SBkm8KLvsJNBQ=; b=WrDcUfy2+PwAFmBdlaL6+5ZZQ2yjGj+eH5tLlhY0TKn14sSaZy8JeczysVVdDi3p6A X8fqiFVt2IlKxITNYXZXKctBYxqoCE4/gNTvWMksTCnplfKNclGUVeopDc3zOyX/lgoS BfHf+SiLj6JWfKn5QFBUJ4cljLrZ03N25VDKzzAt4geeTa4hY8PXeXqHWVkNEVdd4m+2 il5j5Ztt7jwdGooKgDuZ8CS33bUM3JmKIaJVy6kiav2721BrVCU+qzh3HCzXyFMNIlAW NoqehWYIQ9tqveGYVlc5rYVMwRiyGiPXdfGU/sncKCKgCOSxALBO4Ax7fGISD+FkWgrb 88Aw== X-Gm-Message-State: AOAM531MxeNiTxhP3kxiwIpxp+5s3lpEI3XjWtpPsHJrs3PmstMMpTBv NEN0mEGDAxDJqx8OxQfC2PaTsme+Fc12aQ== X-Google-Smtp-Source: ABdhPJxDedi4eag0zYPeE2cJBj2T0h2dDlO/6xrHVGp5MSRpsP4ZyQNH/zWFjZBJ36A9YCjjoh6exg== X-Received: by 2002:a9d:7188:: with SMTP id o8mr1437402otj.120.1606274989075; Tue, 24 Nov 2020 19:29:49 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k20sm655175ooh.47.2020.11.24.19.29.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:48 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 05/10] pull: display default warning only when non-ff Date: Tue, 24 Nov 2020 21:29:33 -0600 Message-Id: <20201125032938.786393-6-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no need to display the annoying warning on every pull... only the ones that are not fast-forward. Signed-off-by: Felipe Contreras --- builtin/pull.c | 2 +- t/t7601-merge-pull-config.sh | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 9a0f7937c2..479bdaf0ee 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1013,7 +1013,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); - if (default_mode && opt_verbosity >= 0 && !opt_ff) { + if (default_mode && !can_ff && opt_verbosity >= 0 && !opt_ff) { warning(_("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" diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index c5c4ea5fc0..02e2a9b2c6 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -28,59 +28,65 @@ test_expect_success 'setup' ' ' test_expect_success 'pull.rebase not set' ' - git reset --hard c0 && + git reset --hard c2 && 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' ' +test_expect_success 'pull.rebase not set (fast-forward)' ' git reset --hard c0 && + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and pull.ff=true' ' + git reset --hard c2 && test_config pull.ff true && git pull . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and pull.ff=false' ' - git reset --hard c0 && + git reset --hard c2 && test_config pull.ff false && git pull . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and pull.ff=only' ' - git reset --hard c0 && + git reset --hard c2 && test_config pull.ff only && - git pull . c1 2>err && + test_must_fail git pull . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --rebase given' ' - git reset --hard c0 && + git reset --hard c2 && git pull --rebase . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --no-rebase given' ' - git reset --hard c0 && + git reset --hard c2 && git pull --no-rebase . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --ff given' ' - git reset --hard c0 && + git reset --hard c2 && git pull --ff . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --no-ff given' ' - git reset --hard c0 && + git reset --hard c2 && git pull --no-ff . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and --ff-only given' ' - git reset --hard c0 && - git pull --ff-only . c1 2>err && + git reset --hard c2 && + test_must_fail git pull --ff-only . c1 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err ' From patchwork Wed Nov 25 03:29:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930263 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 1334DC64E7A for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2DB42075A for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cWm1OH1l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727438AbgKYD3w (ORCPT ); Tue, 24 Nov 2020 22:29:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3v (ORCPT ); Tue, 24 Nov 2020 22:29:51 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9901EC0613D6 for ; Tue, 24 Nov 2020 19:29:51 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id k3so958753otp.12 for ; Tue, 24 Nov 2020 19:29:51 -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=3SnoBkZ3kSMVpgqZ5NeBlt0BY1cD/WY+UmHuiONhlg8=; b=cWm1OH1lNvVFAGDoQll0+qn1/DzDu6cvuiC/B2fPC5woOg8Vlw/qRH9i+BloZbJRW6 nWO+f/tmFHTReWbPTyoRpb5LVTluwEcZXxGNMVKOgwCcGfDGF+KGTDq18ycVyjSBfveK 2xg6O/wUKzAczEoatOjdI78YgJP99nK4GnwXYPouWjVD+14Tf+mvOcu8sZuTvAX0OqxI ujfCKSuWTk52cmJhxkQTTuqCM/Xa+2y2w6xqaWuh6CV89i+jHJx09z0fQ63wUv3vRdCs +j3wKdPtXWxPoaqedLvC6lWyzKhs1Eyawihz1XGnSYfzt78r8rES4Dqigq4KjSbt4g2j V+jQ== 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=3SnoBkZ3kSMVpgqZ5NeBlt0BY1cD/WY+UmHuiONhlg8=; b=s4tT5MhbnmkA1qCUagCS08ACGZR2xBXSyqYJnK4fccLQNDmsQCrg2G4yqg6agK3Ux5 XGG+53PNW4+SvqQbv/IBl9jU+jUVe/1i7DpvSWEc9KLyzWXSvY85mIgqD4Gq0kttYy1c mrDMM90iiff7bHZ6MT8oInFr4Es5hYBnDn8NejddEQ5K9owzLGMxb1qGbKOY7BzULDTO wEltCukIcZHMbGzJMxl3KE3YvIckIIM2cOCj+EgyT7wymm3OBx+HDyHgu00OHoxGl+vm ofV5ZjdiXNRST5fefFpYplOtv1vYYq9QKDTbytVk2KC0Gxze561Szb0sYIMeyQaIluNK p5RQ== X-Gm-Message-State: AOAM530yRtEGb2r+FQj7Tn2WORH6OBdtNwfVV5N5neX8azExambL2NRg rQ5vTjEnZGdFG1r3cOR42qVoT6oH28GJqw== X-Google-Smtp-Source: ABdhPJx4glDZmC+FnDJno0aDM+K889ZgqssqpIrbuBdJPrCpHCi4do4GhgtsnXMLCtHxVGrZrHxkTw== X-Received: by 2002:a9d:eeb:: with SMTP id 98mr1423521otj.179.1606274990811; Tue, 24 Nov 2020 19:29:50 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id n62sm558647ota.74.2020.11.24.19.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:50 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 06/10] test: pull-options: revert unnecessary changes Date: Tue, 24 Nov 2020 21:29:34 -0600 Message-Id: <20201125032938.786393-7-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Commit d18c950a69 changed these tests, but it's unclear why. Probably because earlier versions of the patch series died instead of printing a warning. Cc: Alex Henrie Signed-off-by: Felipe Contreras --- t/t5521-pull-options.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index db1a381cd9..1a4fe2583a 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -11,10 +11,10 @@ test_expect_success 'setup' ' git commit -m one) ' -test_expect_success 'git pull -q --no-rebase' ' +test_expect_success 'git pull -q' ' mkdir clonedq && (cd clonedq && git init && - git pull -q --no-rebase "../parent" >out 2>err && + git pull -q "../parent" >out 2>err && test_must_be_empty err && test_must_be_empty out) ' @@ -30,10 +30,10 @@ test_expect_success 'git pull -q --rebase' ' test_must_be_empty out) ' -test_expect_success 'git pull --no-rebase' ' +test_expect_success 'git pull' ' mkdir cloned && (cd cloned && git init && - git pull --no-rebase "../parent" >out 2>err && + git pull "../parent" >out 2>err && test -s err && test_must_be_empty out) ' @@ -46,10 +46,10 @@ test_expect_success 'git pull --rebase' ' test_must_be_empty out) ' -test_expect_success 'git pull -v --no-rebase' ' +test_expect_success 'git pull -v' ' mkdir clonedv && (cd clonedv && git init && - git pull -v --no-rebase "../parent" >out 2>err && + git pull -v "../parent" >out 2>err && test -s err && test_must_be_empty out) ' @@ -62,25 +62,25 @@ test_expect_success 'git pull -v --rebase' ' test_must_be_empty out) ' -test_expect_success 'git pull -v -q --no-rebase' ' +test_expect_success 'git pull -v -q' ' mkdir clonedvq && (cd clonedvq && git init && - git pull -v -q --no-rebase "../parent" >out 2>err && + git pull -v -q "../parent" >out 2>err && test_must_be_empty out && test_must_be_empty err) ' -test_expect_success 'git pull -q -v --no-rebase' ' +test_expect_success 'git pull -q -v' ' mkdir clonedqv && (cd clonedqv && git init && - git pull -q -v --no-rebase "../parent" >out 2>err && + git pull -q -v "../parent" >out 2>err && test_must_be_empty out && test -s err) ' test_expect_success 'git pull --cleanup errors early on invalid argument' ' mkdir clonedcleanup && (cd clonedcleanup && git init && - test_must_fail git pull --no-rebase --cleanup invalid "../parent" >out 2>err && + test_must_fail git pull --cleanup invalid "../parent" >out 2>err && test_must_be_empty out && test -s err) ' From patchwork Wed Nov 25 03:29:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930259 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 455F4C64E7B for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1DD720872 for ; Wed, 25 Nov 2020 03:30:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ugjUmvYn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727460AbgKYD3x (ORCPT ); Tue, 24 Nov 2020 22:29:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3x (ORCPT ); Tue, 24 Nov 2020 22:29:53 -0500 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FBCC0613D6 for ; Tue, 24 Nov 2020 19:29:53 -0800 (PST) Received: by mail-oo1-xc2b.google.com with SMTP id l10so169366oom.6 for ; Tue, 24 Nov 2020 19:29:53 -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=VwSOR7TtLX10jNB6vkoYgbT/6H2+sLaxG6xXL9lz/2I=; b=ugjUmvYnvrGfXypb3a70CD6bAvKWF21eayz/YHxHO7pdfbBPPL3+Qozljt2eoTWhXU 5+N6eVmjAdEd1XcrV4NuHPO8me6K/32yPaziwMeM4WqYjdGHmvbq8d9p61kgm8UB5yqc S1KC6/iKPIG/xleTWw4RZ+PZ2NNWaUboDQ8kyisPmDLOBRqOAM32h0NF/6tYem+dmyxm /Y23TZ7f0ii5Kuhmejaent1rsnapNCgplcfp5z27m/AmuG6Ra0RCLIojpMRz2b2nxrQp Yz9d+t0jrWulD78QZJgzon7XUQu+/lqamVKQMCP0orDmtq2SheUGFSmztZBr+A0ngbiG mzFQ== 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=VwSOR7TtLX10jNB6vkoYgbT/6H2+sLaxG6xXL9lz/2I=; b=P6lzPABM6OjCVF/sELTcla+oVP7wqqRmvD2naCMKg0l5dTyZtaE5IJRHxnpnSfLzMz 0pC4SksLBoExbj6jCByODRPZK7birLsp9ONYbb97zqPZ+OZDQ4YtCnTqgbhdjVFnIjSz Wi3E2LHZIpLAdmBTUJ+anLXHKBWfv5vhjNMK5SwA0U+q8rSSH0cbk0teukCGES1Db6Mm sXkPuEbmkzEABX3RYM+LuQkMkYNIno9TJ1a9fb4L1R2wY01b8waUbp4aDqoA6jwAF4N3 xN9shLW7vIqxlnPaD3tHGPqxVb3gCAEqjXjAdHETJVJotdR04IXh3NGZuynKQZ0NyUZV ro1g== X-Gm-Message-State: AOAM533wLfA7HGK98M/nWghHyfSTylbUmnJ9eslm6Nkltqhr4uNp0vxD lePSrgXZ9sCSArTnDPS8huWbNFvgKmVGqQ== X-Google-Smtp-Source: ABdhPJyss8e1nCjbUjIcZodVHo45VkDVdcXX3XxT8lZg9trrt5zCEkt1F71HxikxoEsyoyT7niKQrw== X-Received: by 2002:a4a:b409:: with SMTP id y9mr1280990oon.70.1606274992391; Tue, 24 Nov 2020 19:29:52 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id m109sm567356otc.30.2020.11.24.19.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:51 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 07/10] rebase: add REBASE_DEFAULT Date: Tue, 24 Nov 2020 21:29:35 -0600 Message-Id: <20201125032938.786393-8-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org So that we can distinguish when the user has forced an option. Signed-off-by: Felipe Contreras --- builtin/pull.c | 20 ++++++++------------ rebase.h | 3 ++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 479bdaf0ee..0df7d27343 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -27,8 +27,6 @@ #include "commit-reach.h" #include "sequencer.h" -static int default_mode; - /** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is @@ -346,9 +344,7 @@ static enum rebase_type config_get_rebase(void) if (!git_config_get_value("pull.rebase", &value)) return parse_config_rebase("pull.rebase", value, 1); - default_mode = 1; - - return REBASE_FALSE; + return REBASE_DEFAULT; } /** @@ -443,7 +439,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 +452,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 +467,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.")); @@ -948,7 +944,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; @@ -1008,12 +1004,12 @@ 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 (default_mode && !can_ff && opt_verbosity >= 0 && !opt_ff) { + if (!opt_rebase && !can_ff && opt_verbosity >= 0 && !opt_ff) { warning(_("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" @@ -1028,7 +1024,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) "invocation.\n")); } - if (opt_rebase) { + if (opt_rebase >= REBASE_TRUE) { int ret = 0; if ((recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && 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 Wed Nov 25 03:29:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930265 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 865DFC64E7C for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F3722075A for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n90SX3z1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727466AbgKYD3z (ORCPT ); Tue, 24 Nov 2020 22:29:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD3z (ORCPT ); Tue, 24 Nov 2020 22:29:55 -0500 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3537C0613D6 for ; Tue, 24 Nov 2020 19:29:54 -0800 (PST) Received: by mail-oo1-xc42.google.com with SMTP id l20so173517oot.3 for ; Tue, 24 Nov 2020 19:29:54 -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=qbX0dpazZDMnxB/FzgCb382HO7VHSEimPclHstmiyik=; b=n90SX3z1FYW121Omf68wK4Sd7tr/z9sP8tg+SCjuLZIHpSsUprhIjr+YuZJIG3FHvr Ras9S57HkqFax3O3vbp7t9kl1q2ru3JZGP9IVRkINzSuiyRbhxZasmypwTdmFagSOJI4 +GdzXnAsBkUfk+TtiOJNaTWICxxoDBtlzl/H+8TInLK3RtpmbhUjF6PuJ91HLwieAOPL zKx0OF20Jleo/R6VQ5AaKr8re8G4xqJqggnQF6bW0aiLyHAisJheqxSaW7q2lVGrX+yn ak+itLXqSlHu3okFKe3I327Mya2suaejVR7CYBI775WDZKRFzcA4IH65M5gq7IQGnaZk wK4g== 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=qbX0dpazZDMnxB/FzgCb382HO7VHSEimPclHstmiyik=; b=pc3u6kS8jIgzodM0p+vKihrv81FRXdVQSAIB3o7uxadMpY2EfCpMHmOymlw/6rPd6U xtZ5/pax8RZIvXHwUfY+XEedLe0V/nKwH8bpuB15pBqYAH9T2FazNDq4AubJ44d2Q4+w srd3aBYUbSVz3DJTYyiMp6hwqNFTrB/bILAOkMNi3ANVG6zyb5o+bakQmcHbdnvEF4Su 7b0AmvmDRXEkhHBgc7xLow012BFZBtbCzyVE15pwkIT3VHP7TcrvLVISlAmGwlMVzX6R QbQpLygUsN6Yg7LvbNPZQZ+M7iHGwj2qYjN+ZNXA/Ovnmwn48kaNLDDf4QdlcsqvTxaX BCQQ== X-Gm-Message-State: AOAM531ShJ1hk3VBR2xsV23Z5obaT27RJkR83OgnDjy7jV0M9jCM7uj/ Sz1XUoQr//6X555OdKTZZuAoaMbzfvyvGA== X-Google-Smtp-Source: ABdhPJyVEZKu5eBYvdDeijcuS000nLZ9+/lqhyFOvR3T2e19yfhrKyp6yicA1hFLLPZm92+q+MuVXQ== X-Received: by 2002:a4a:8582:: with SMTP id t2mr1268384ooh.89.1606274993885; Tue, 24 Nov 2020 19:29:53 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id j8sm674287oif.55.2020.11.24.19.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:53 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 08/10] pull: add pull.mode Date: Tue, 24 Nov 2020 21:29:36 -0600 Message-Id: <20201125032938.786393-9-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This way we can add more modes and the default can be something else, namely it can be set to "ff-only", so eventually we can reject non-fast-forward merges by default. Also 'branch..pullmode'. For now we simply override the rebase mode. Signed-off-by: Felipe Contreras --- Documentation/config/branch.txt | 6 ++++ Documentation/config/pull.txt | 6 ++++ builtin/pull.c | 57 ++++++++++++++++++++++++++++++--- builtin/remote.c | 19 ++++++++++- rebase.c | 10 ++++++ rebase.h | 9 ++++++ t/t5520-pull.sh | 42 ++++++++++++++++++++++++ t/t7601-merge-pull-config.sh | 7 ++++ 8 files changed, 151 insertions(+), 5 deletions(-) diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt index cc5f3249fc..94510a5184 100644 --- a/Documentation/config/branch.txt +++ b/Documentation/config/branch.txt @@ -96,6 +96,12 @@ mode. it unless you understand the implications (see linkgit:git-rebase[1] for details). +branch..pullmode:: + When "git pull" is run, this determines if it would either merge or + rebase the fetched branch. The possible values are 'merge', + 'rebase'. See "pull.mode" for doing this in a non + branch-specific manner. + branch..description:: Branch description, can be edited with `git branch --edit-description`. Branch description is diff --git a/Documentation/config/pull.txt b/Documentation/config/pull.txt index 5404830609..2606515fe4 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 doing + this in a non branch-specific manner. + pull.octopus:: The default merge strategy to use when pulling multiple branches at once. diff --git a/builtin/pull.c b/builtin/pull.c index 0df7d27343..feb9a7f6ee 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -49,6 +49,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(). */ @@ -75,6 +83,7 @@ static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; /* Options passed to git-merge or git-rebase */ static enum rebase_type opt_rebase = -1; +static enum pull_mode_type mode; static char *opt_diffstat; static char *opt_log; static char *opt_signoff; @@ -347,6 +356,29 @@ static enum rebase_type config_get_rebase(void) return REBASE_DEFAULT; } +static enum pull_mode_type config_get_pull_mode(void) +{ + struct branch *curr_branch = branch_get("HEAD"); + const char *value; + + if (curr_branch) { + char *key = xstrfmt("branch.%s.pullmode", curr_branch->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. */ @@ -932,8 +964,25 @@ 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(); + if (opt_rebase < 0) { + mode = config_get_pull_mode(); + switch (mode) { + case PULL_MODE_MERGE: + opt_rebase = REBASE_FALSE; + break; + case PULL_MODE_REBASE: + opt_rebase = config_get_rebase(); + if (!opt_rebase) opt_rebase = REBASE_TRUE; + break; + default: + opt_rebase = config_get_rebase(); + } + } + + if (!mode) { + if (opt_rebase) + mode = opt_rebase >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE; + } if (read_cache_unmerged()) die_resolve_conflict("pull"); @@ -1014,8 +1063,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix) "discouraged. You can squelch this message by running one of the following\n" "commands sometime before your next pull:\n" "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" + " git config pull.mode merge # (the default strategy)\n" + " git config pull.mode rebase\n" " git config pull.ff only # fast-forward only\n" "\n" "You can replace \"git config\" with \"git config --global\" to set a default\n" diff --git a/builtin/remote.c b/builtin/remote.c index c1b211b272..51b1e675e3 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -269,7 +269,7 @@ static int config_read_branches(const char *key, const char *value, void *cb) char *name; struct string_list_item *item; struct branch_info *info; - enum { REMOTE, MERGE, REBASE, PUSH_REMOTE } type; + enum { REMOTE, MERGE, REBASE, PUSH_REMOTE, PULL_MODE } type; size_t key_len; if (!starts_with(key, "branch.")) @@ -284,6 +284,8 @@ static int config_read_branches(const char *key, const char *value, void *cb) type = REBASE; else if (strip_suffix(key, ".pushremote", &key_len)) type = PUSH_REMOTE; + else if (strip_suffix(key, ".pullmode", &key_len)) + type = PULL_MODE; else return 0; name = xmemdupz(key, key_len); @@ -324,6 +326,21 @@ static int config_read_branches(const char *key, const char *value, void *cb) warning(_("more than one %s"), orig_key); info->push_remote_name = xstrdup(value); break; + case PULL_MODE: { + int mode = pull_mode_parse_value(value); + switch (mode) { + case PULL_MODE_MERGE: + info->rebase = REBASE_FALSE; + break; + case PULL_MODE_REBASE: + info->rebase = REBASE_TRUE; + break; + default: + info->rebase = REBASE_INVALID; + break; + } + break; + } default: BUG("unexpected type=%d", type); } 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..eb0086bd1c 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 @@ -523,6 +533,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 +573,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 +624,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 02e2a9b2c6..4a36ad30e2 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -39,6 +39,13 @@ test_expect_success 'pull.rebase not set (fast-forward)' ' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' +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' ' git reset --hard c2 && test_config pull.ff true && From patchwork Wed Nov 25 03:29:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930267 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 E0567C64E90 for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A21E82075A for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EsP7A6ik" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727535AbgKYD35 (ORCPT ); Tue, 24 Nov 2020 22:29:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD34 (ORCPT ); Tue, 24 Nov 2020 22:29:56 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 964BCC0613D4 for ; Tue, 24 Nov 2020 19:29:56 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id 92so994396otd.5 for ; Tue, 24 Nov 2020 19:29:56 -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=SCbiIjvrPL4MR84lIt92POutCrsCfn3bAgBiU+QO3ko=; b=EsP7A6ikiGco3xWykBAqMNHBVkna1YEFUyLLzaHnaPXwnYP3guPnyQvOO8yQrRHugQ 8B1lwIfHCw37OEmyagJHb8V8EfNpKLgHpD555dpvoGR5m8ANiWxfSpYFDKEvRUXyBeMa Aw80i1HMQTRDvdu/kS5cGN7D8XCNEDhpZX+OVi3kUKePhFt3E1kVXI452m3hZE5z9H9X pcZoaYdV4a/l2/peTsCI9W3EbbM8TvVrezAbs8Dey9m72MGkbtwV7HpezK2+Cyscp5Px T+U9GqWxHowqbgYK1b9W7Jcs/1xJJzWwXwqI1EkYXunII+dqOptE6bv/ux3w+SZU0umx 7rOA== 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=SCbiIjvrPL4MR84lIt92POutCrsCfn3bAgBiU+QO3ko=; b=O3jiO0P6NS6plHSLBjwOS2uIHRFFaBVvuei+IxCbbRlQeBydTgzlWqKywlzJLSQfVK 4BjA2/pjFL/nq0lcsxkoH3AoKXh3flSHEYcaixKaLSRXm8fzJJRGTaTklpxsyc/FcU13 YjRWjRxFavfYPwOL53p/NGssN5F1oIQ/ZzBeITlLlj2sYQKmzfqJb2dAoYxw0FoBtG3P GbJlsfh48Tzpnl5mZSmL/ud/On0yYUw3MA+EyYU1tDj8xmPd4DF6c7wQ4Xh4X1VFBylC OO9gxdbY0o5saV1/y29ttv7jh6PELpiKzng+h7AP76qaw+oA8bMjJGCio1xYBqrwvygd JHdA== X-Gm-Message-State: AOAM531qJCp2U3g0fNED3FmboyGv9a+kJhJAdS48vjeY6X7fKZ1tXKfI QuxAPeyatkjuO41qdf4kIndognIetwU0Xg== X-Google-Smtp-Source: ABdhPJyxcPW0yYtPRC4xYkkykCBoosx582TXMFbFMRW+3Bg4SAMcj01BYwFFZFOC/6nx8jZUaPZY8w== X-Received: by 2002:a9d:1f5:: with SMTP id e108mr1387354ote.309.1606274995638; Tue, 24 Nov 2020 19:29:55 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id k5sm649551oot.30.2020.11.24.19.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:54 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 09/10] pull: add pull.mode=ff-only Date: Tue, 24 Nov 2020 21:29:37 -0600 Message-Id: <20201125032938.786393-10-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-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; inadvertently 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 avoid 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 = ff-only. Later on this mode can be enabled by default. For the full discussion you can read: https://lore.kernel.org/git/5363BB9F.40102@xiplink.com/ Signed-off-by: Felipe Contreras --- Documentation/config/branch.txt | 2 +- Documentation/config/pull.txt | 2 +- builtin/pull.c | 10 +++++++-- builtin/remote.c | 3 +++ rebase.c | 2 ++ rebase.h | 3 ++- t/t5520-pull.sh | 36 +++++++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt index 94510a5184..39f60cd8f7 100644 --- a/Documentation/config/branch.txt +++ b/Documentation/config/branch.txt @@ -99,7 +99,7 @@ for details). branch..pullmode:: When "git pull" is run, this determines if it would either merge or rebase the fetched branch. The possible values are 'merge', - 'rebase'. See "pull.mode" for doing this in a non + 'rebase', and 'ff-only'. See "pull.mode" for doing this in a non branch-specific manner. branch..description:: diff --git a/Documentation/config/pull.txt b/Documentation/config/pull.txt index 2606515fe4..daa14f1170 100644 --- a/Documentation/config/pull.txt +++ b/Documentation/config/pull.txt @@ -32,7 +32,7 @@ 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 doing + 'rebase', and 'ff-only'. See "branch..pullmode" for doing this in a non branch-specific manner. pull.octopus:: diff --git a/builtin/pull.c b/builtin/pull.c index feb9a7f6ee..3aa7f56142 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -980,7 +980,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) } if (!mode) { - if (opt_rebase) + if (opt_ff && !strcmp(opt_ff, "--ff-only")) + mode = PULL_MODE_FF_ONLY; + else if (opt_rebase) mode = opt_rebase >= REBASE_TRUE ? PULL_MODE_REBASE : PULL_MODE_MERGE; } @@ -1065,7 +1067,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) "\n" " git config pull.mode merge # (the default strategy)\n" " git config pull.mode rebase\n" - " git config pull.ff only # fast-forward only\n" + " git config pull.mode ff-only # fast-forward only\n" "\n" "You can replace \"git config\" with \"git config --global\" to set a default\n" "preference for all repositories. You can also pass --rebase, --no-rebase,\n" @@ -1073,6 +1075,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) "invocation.\n")); } + if (mode == PULL_MODE_FF_ONLY && !can_ff) + die(_("The pull was not fast-forward, please either merge or rebase.\n" + "If unsure, run 'git pull --no-rebase'.")); + if (opt_rebase >= REBASE_TRUE) { int ret = 0; if ((recurse_submodules == RECURSE_SUBMODULES_ON || diff --git a/builtin/remote.c b/builtin/remote.c index 51b1e675e3..34d3ea9d38 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -335,6 +335,9 @@ static int config_read_branches(const char *key, const char *value, void *cb) case PULL_MODE_REBASE: info->rebase = REBASE_TRUE; break; + case PULL_MODE_FF_ONLY: + info->rebase = REBASE_TRUE; + break; default: info->rebase = REBASE_INVALID; break; diff --git a/rebase.c b/rebase.c index bdfca49886..c6233e888f 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, "ff-only") || !strcmp(value, "f")) + return PULL_MODE_FF_ONLY; return PULL_MODE_INVALID; } diff --git a/rebase.h b/rebase.h index 5ab8f4ddd5..432bcb55c4 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_FF_ONLY }; enum pull_mode_type pull_mode_parse_value(const char *value); diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index eb0086bd1c..ba78c16d73 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -861,4 +861,40 @@ test_expect_success 'git pull --rebase against local branch' ' test_cmp expect file2 ' +test_expect_success 'git pull fast-forward (ff-only)' ' + test_when_finished "git checkout master && git branch -D other test" && + test_config pull.mode ff-only && + git checkout -b other master && + >new && + git add new && + git commit -m new && + git checkout -b test -t other && + git reset --hard master && + git pull +' + +test_expect_success 'git pull non-fast-forward (ff-only)' ' + test_when_finished "git checkout master && git branch -D other test" && + test_config pull.mode ff-only && + git checkout -b other master^ && + >new && + git add new && + git commit -m new && + git checkout -b test -t other && + git reset --hard master && + test_must_fail git pull +' + +test_expect_success 'git pull non-fast-forward with merge (ff-only)' ' + test_when_finished "git checkout master && git branch -D other test" && + test_config pull.mode ff-only && + git checkout -b other master^ && + >new && + git add new && + git commit -m new && + git checkout -b test -t other && + git reset --hard master && + git pull --no-rebase +' + test_done From patchwork Wed Nov 25 03:29:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Contreras X-Patchwork-Id: 11930271 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 3C94FC64E8A for ; Wed, 25 Nov 2020 03:30:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5D1F2087C for ; Wed, 25 Nov 2020 03:30:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jLsj9Z4q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbgKYD36 (ORCPT ); Tue, 24 Nov 2020 22:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgKYD36 (ORCPT ); Tue, 24 Nov 2020 22:29:58 -0500 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DB05C0613D4 for ; Tue, 24 Nov 2020 19:29:58 -0800 (PST) Received: by mail-oo1-xc42.google.com with SMTP id i13so163963oou.11 for ; Tue, 24 Nov 2020 19:29:58 -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=XYCIFpTK1U85eu6FQaisrF9syunRmjF4tcFbFgkHA1c=; b=jLsj9Z4qDXX0pzI23Rv6YtZGheVetB4Lj8Y1B4xbLfJpINj4FXyF7vHxHAdWAOTsuh YY/3EYsdRe81BfOk0eDhlKA04KvzjaIxfr4BG5z6/szWxP35h0VtV7v8x6Om8i3sNAy4 fVG/FunbAxiLNh50WfkZ9BfgxbtsQTRgUorvlnWhMgu544WqjcJy2nFO0KFZH6bBDAV8 tY0S9p2By/+nu4W8CcZm5Mq0PTx2XEp/wdX/5sCTK2BHzLqm2In1DSTeEDMT9eJQT32Q w4EtEx+jw27nCYFKFQ6Vx5SPrI4AFzoQuvBrM8U/tOb5jpUMWoUuFyIJYcUeTASzj6rz ipxw== 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=XYCIFpTK1U85eu6FQaisrF9syunRmjF4tcFbFgkHA1c=; b=FTm9prdTmlcrK/9JM+Uxgf8u0AeJQp/6h055KCX6CwIGLAufI1DKeNddOhoAaFqarI QhztrwvSY0j0itgL7aTU6qXnG6VzIrCVGREq9QPiNzZFZkog2foPTRYxH5CXRKDRgq/P 8E8l8rM3xq/1NVT6yu3aM4j0FN/syJUNT5oHLq1kogmAhFVDZFq9kfNBiwkBp0xpYxFE 3JG4gBXiI0wJGrjU40AseXtTTTerXHKq/52PpwNG4w9POXjews4TL8Xv6rXZJ/Tb6NIe j7ESeu54LO0p8uxc9buUPD9K8I/3UfYipWun2ut8ZYIxIP8Ee1hnn0c6G4DB90WhFm99 x+kw== X-Gm-Message-State: AOAM5333595OHMXneSSny4WVPeJl2sPl/rLBZ8b44vpTygy9foduu39+ 5kxP/bUWpWkj0M6BCyA1AtasqoeGoS6aHg== X-Google-Smtp-Source: ABdhPJz7dxWbkVGV0/dyurRby1NfmMMgZzIa/Rm496KDF6A+Pv0DCinPIpqozuZVA+OlKlafhsEjzA== X-Received: by 2002:a4a:338d:: with SMTP id q135mr1281575ooq.21.1606274997282; Tue, 24 Nov 2020 19:29:57 -0800 (PST) Received: from localhost (189-209-26-110.static.axtel.net. [189.209.26.110]) by smtp.gmail.com with ESMTPSA id m2sm583987ots.11.2020.11.24.19.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 19:29:56 -0800 (PST) From: Felipe Contreras To: git@vger.kernel.org Cc: Alex Henrie , Jeff King , Junio C Hamano , Elijah Newren , Johannes Schindelin , John Keeping , Richard Hansen , Philip Oakley , "Brian M. Carlson" , "W. Trevor King" , Felipe Contreras Subject: [PATCH v8 10/10] pull: improve default warning Date: Tue, 24 Nov 2020 21:29:38 -0600 Message-Id: <20201125032938.786393-11-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com> References: <20201125032938.786393-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Also, use pull.mode to determine when to show it, and --ff/--no-ff shouldn't squelch the warning. Also, improve the documentation so "git pull --help" actually does explain what's going on. Signed-off-by: Felipe Contreras --- Documentation/git-pull.txt | 17 +++++++++++++++ builtin/pull.c | 34 +++++++++++++++--------------- t/t5520-pull.sh | 14 +++++++++++++ t/t7601-merge-pull-config.sh | 40 +++++++----------------------------- 4 files changed, 55 insertions(+), 50 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 5c3fb67c01..ad33d2472c 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -38,6 +38,20 @@ as set by linkgit:git-branch[1] `--track`. Assume the following history exists and the current branch is "`master`": +------------ + A---B---C master on origin + / + D---E master +------------ + +Then `git pull` will merge in a fast-foward way up to the new master. + +------------ + D---E---A---B---C master, origin/master +------------ + +However, a non-fast-foward case looks very different. + ------------ A---B---C master on origin / @@ -46,6 +60,9 @@ Assume the following history exists and the current branch is origin/master in your repository ------------ +By default `git pull` will warn about these situations, however, most likely +you would want to force a merge, which you can do with `git pull --no-rebase`. + 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 diff --git a/builtin/pull.c b/builtin/pull.c index 3aa7f56142..8e577b6322 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1060,25 +1060,25 @@ 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 && !can_ff && opt_verbosity >= 0 && !opt_ff) { - warning(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.mode merge # (the default strategy)\n" - " git config pull.mode rebase\n" - " git config pull.mode ff-only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); + if (!can_ff) { + if (mode == PULL_MODE_FF_ONLY) + die(_("The pull was not fast-forward, please either merge or rebase.\n" + "If unsure, run 'git pull --no-rebase'.")); + else if (!mode && opt_verbosity >= 0) { + warning(_("The pull was not fast-forward, in the future you will have to choose a merge, or a rebase.\n" + "To squelch this message and maintain the current behavior, use:\n" + "\n" + " git config --global pull.mode merge\n" + "\n" + "To squelch this message and adopt the new behavior now, use:\n" + "\n" + " git config --global push.mode ff-only\n" + "\n" + "Falling back to old style for now (merge).\n" + "Read 'git pull --help' for more information.")); + } } - if (mode == PULL_MODE_FF_ONLY && !can_ff) - die(_("The pull was not fast-forward, please either merge or rebase.\n" - "If unsure, run 'git pull --no-rebase'.")); - if (opt_rebase >= REBASE_TRUE) { int ret = 0; if ((recurse_submodules == RECURSE_SUBMODULES_ON || diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index ba78c16d73..29d44d000e 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -897,4 +897,18 @@ test_expect_success 'git pull non-fast-forward with merge (ff-only)' ' git pull --no-rebase ' +test_expect_success 'git pull non-fast-forward (default)' ' + test_when_finished "git checkout master && git branch -D other test" && + git checkout -b other master^ && + >new && + git add new && + git commit -m new && + git checkout -b test -t other && + git reset --hard master && + git pull 2> error && + cat error && + grep -q "The pull was not fast-forward" error && + grep -q "in the future you will have to choose" error +' + test_done diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 4a36ad30e2..8a93b37d87 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -30,71 +30,45 @@ test_expect_success 'setup' ' test_expect_success 'pull.rebase not set' ' git reset --hard c2 && git pull . c1 2>err && - test_i18ngrep "Pulling without specifying how to reconcile" err + test_i18ngrep "choose a merge, or a rebase" err ' test_expect_success 'pull.rebase not set (fast-forward)' ' git reset --hard c0 && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "choose a merge, or a rebase" err ' 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' ' - git reset --hard c2 && - test_config pull.ff true && - git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err -' - -test_expect_success 'pull.rebase not set and pull.ff=false' ' - git reset --hard c2 && - test_config pull.ff false && - git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "choose a merge, or a rebase" err ' test_expect_success 'pull.rebase not set and pull.ff=only' ' 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 ! "choose a merge, or a rebase" err ' test_expect_success 'pull.rebase not set and --rebase given' ' git reset --hard c2 && git pull --rebase . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "choose a merge, or a rebase" err ' test_expect_success 'pull.rebase not set and --no-rebase given' ' git reset --hard c2 && git pull --no-rebase . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err -' - -test_expect_success 'pull.rebase not set and --ff given' ' - git reset --hard c2 && - git pull --ff . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err -' - -test_expect_success 'pull.rebase not set and --no-ff given' ' - git reset --hard c2 && - git pull --no-ff . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "choose a merge, or a rebase" err ' test_expect_success 'pull.rebase not set and --ff-only given' ' 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 ! "choose a merge, or a rebase" err ' test_expect_success 'merge c1 with c2' '