From patchwork Mon Dec 14 20:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11972993 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 75F19C2BB40 for ; Mon, 14 Dec 2020 20:29:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 320D122286 for ; Mon, 14 Dec 2020 20:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502878AbgLNU2B (ORCPT ); Mon, 14 Dec 2020 15:28:01 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:50427 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503312AbgLNU1h (ORCPT ); Mon, 14 Dec 2020 15:27:37 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 526B3A9C96; Mon, 14 Dec 2020 15:26:52 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=aIM9HvvFmJETyR6a09BMuhuqm Ak=; b=S5VjkUasZR7d//V4VxmgL2qp+JciK8QJuKDwQQkBKs5U5qvFrKXlf/kMf aVuVE9tfo+2LCrBrL8Juq0v73Zz0nZPDlwYgNyW0EKt9lNe8CHzCvhJwyHVJbprT XDITMtKmNCFoSLmw6Hm9BJ55J1V7YZrYsbn2lOeDIsCCdsq5II= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=dMlTwD6qyi4JvinuIFQ a0f4JKlRMSGdjBkdT8WkSfiCQzMs+Wnar3lsRXQH2Nv+SFzgq6GpFNO3LX5kEdCH zcZrS5VeDKQNNZDqASGpAX1hff9l5w5ji48j3FG672rq9XGjRQl42zmfM0mlFgME rNee+X5T3xVYxeMAcC45oRyU= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 4A719A9C95; Mon, 14 Dec 2020 15:26:52 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id C47B3A9C94; Mon, 14 Dec 2020 15:26:51 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v7 1/5] pull: refactor fast-forward check Date: Mon, 14 Dec 2020 12:26:43 -0800 Message-Id: <20201214202647.3340193-2-gitster@pobox.com> X-Mailer: git-send-email 2.30.0-rc0-186-g20447144ec In-Reply-To: <20201214202647.3340193-1-gitster@pobox.com> References: <20201214202647.3340193-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B31952C0-3E4A-11EB-8FE5-D152C8D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Felipe Contreras We would like to be able to make this check before the decision to rebase is made in a future step. Besides, using a separate helper makes the code easier to follow. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/pull.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index aa56ebcdd0..03e6d53243 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -924,6 +924,20 @@ static int run_rebase(const struct object_id *newbase, return ret; } +static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_head) +{ + int ret; + struct commit_list *list = NULL; + struct commit *merge_head, *head; + + head = lookup_commit_reference(the_repository, orig_head); + commit_list_insert(head, &list); + merge_head = lookup_commit_reference(the_repository, orig_merge_head); + ret = repo_is_descendant_of(the_repository, merge_head, list); + free_commit_list(list); + return ret; +} + int cmd_pull(int argc, const char **argv, const char *prefix) { const char *repo, **refspecs; @@ -1040,22 +1054,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { - struct commit_list *list = NULL; - struct commit *merge_head, *head; - - head = lookup_commit_reference(the_repository, - &orig_head); - commit_list_insert(head, &list); - merge_head = lookup_commit_reference(the_repository, - &merge_heads.oid[0]); - if (repo_is_descendant_of(the_repository, - merge_head, list)) { + if (get_can_ff(&orig_head, &merge_heads.oid[0])) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ran_ff = 1; ret = run_merge(); } - free_commit_list(list); } if (!ran_ff) ret = run_rebase(&newbase, &upstream); From patchwork Mon Dec 14 20:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11972987 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 6BF48C4361B for ; Mon, 14 Dec 2020 20:28:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3732C21D42 for ; Mon, 14 Dec 2020 20:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503192AbgLNU15 (ORCPT ); Mon, 14 Dec 2020 15:27:57 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:59105 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503226AbgLNU1i (ORCPT ); Mon, 14 Dec 2020 15:27:38 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 7ACEC10D1C4; Mon, 14 Dec 2020 15:26:56 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=sV14A2od3IZ9n4ja+1tpapWNe hY=; b=lbLSsXZ8udY6hypNF8gX+4RMsKFhMgoqs85XZGbgbaQm0izcEWZmcX5kN 386i7WgUr5BsqgO2kBELjVK7awpiZPe3nAQu0dqxrdCBOk2SszYkqKCnSAS1xZj2 gL7UJv5s3btv4ZqsIeHz6rIzhfx6UPCwTVIBBTrfWjgy4mSYL0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=TE/LmJ5eOZQhSUuAYG9 kd8mZQ/vdEkm5DlKL7aSmRRQvWcyQ1WehsCbwEO3yTfoNoWf+n7eFAf5fYYaUEWY 8Pe4fvpES2FGnM0OTO4JFHbVGqlf9T0hvGzk+hbrCSh3uPqxHh8mSW41TCh+Y4XJ xJ8HIVLnm70CIz3vTiurmszg= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 5C46A10D1C3; Mon, 14 Dec 2020 15:26:56 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id A5AAA10D1BF; Mon, 14 Dec 2020 15:26:53 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v7 2/5] pull: give the advice for choosing rebase/merge much later Date: Mon, 14 Dec 2020 12:26:44 -0800 Message-Id: <20201214202647.3340193-3-gitster@pobox.com> X-Mailer: git-send-email 2.30.0-rc0-186-g20447144ec In-Reply-To: <20201214202647.3340193-1-gitster@pobox.com> References: <20201214202647.3340193-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B436ED2A-3E4A-11EB-A5F9-E43E2BB96649-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Felipe Contreras Eventually we want to be omit the advice when we can fast-forward in which case there is no reason to require the user to choose between rebase or merge. In order to do so, we need to delay giving the advice up to the point where we can check if we can fast-forward or not. Additionally, config_get_rebase() was probably never its true home. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/pull.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 03e6d53243..ff8e3ce137 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -27,6 +27,8 @@ #include "commit-reach.h" #include "sequencer.h" +static int default_mode; + /** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is @@ -344,20 +346,7 @@ static enum rebase_type config_get_rebase(void) if (!git_config_get_value("pull.rebase", &value)) return parse_config_rebase("pull.rebase", value, 1); - if (opt_verbosity >= 0 && !opt_ff) { - advise(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" - " git config pull.ff only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); - } + default_mode = 1; return REBASE_FALSE; } @@ -1040,6 +1029,21 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); + if (default_mode && opt_verbosity >= 0 && !opt_ff) { + advise(_("Pulling without specifying how to reconcile divergent branches is\n" + "discouraged. You can squelch this message by running one of the following\n" + "commands sometime before your next pull:\n" + "\n" + " git config pull.rebase false # merge (the default strategy)\n" + " git config pull.rebase true # rebase\n" + " git config pull.ff only # fast-forward only\n" + "\n" + "You can replace \"git config\" with \"git config --global\" to set a default\n" + "preference for all repositories. You can also pass --rebase, --no-rebase,\n" + "or --ff-only on the command line to override the configured default per\n" + "invocation.\n")); + } + if (opt_rebase) { int ret = 0; int ran_ff = 0; From patchwork Mon Dec 14 20:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11972989 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 122F2C4361B for ; Mon, 14 Dec 2020 20:28:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CECD7221EF for ; Mon, 14 Dec 2020 20:28:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503140AbgLNU2O (ORCPT ); Mon, 14 Dec 2020 15:28:14 -0500 Received: from pb-smtp21.pobox.com ([173.228.157.53]:52095 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503314AbgLNU1l (ORCPT ); Mon, 14 Dec 2020 15:27:41 -0500 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id E4A7211A3DD; Mon, 14 Dec 2020 15:26:59 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=OWphhU9qsw54QbAf1wFR6s8CY UU=; b=Hpx0KFDJCL5V7Elrn+iQ2RewgwxpXioNOTPdSyhMnrTMNRDo3d7iI4JEV L/3fdaRTUL9Og8xuYyzEAzun11Sghn9lVdvXdg2pI+cMQwzWxQjmJYNjKBb3S1qv 1FvbKFzb5VUAJoZgSgq98nBnVVm5FhAi73luvf7yr3yplb+ja0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=qamtzKOlYBpaZPWp+6E LEapwRshw/ocwkyzMMFwvTI/bNrPWL42KiTOf6VPRQ5uReluXWrSBHDDzgmrV5w9 4oaI/UggRNNc2sCi2smYgwKYVlQEAwsQ3vxWmD5dLM8QaFPvwhJaRCER/Vbpum1c uk+93haU6TQyBfyEtgsUnNIg= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id DD88511A3DC; Mon, 14 Dec 2020 15:26:59 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 28CFF11A3D9; Mon, 14 Dec 2020 15:26:57 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v7 3/5] pull: get rid of unnecessary global variable Date: Mon, 14 Dec 2020 12:26:45 -0800 Message-Id: <20201214202647.3340193-4-gitster@pobox.com> X-Mailer: git-send-email 2.30.0-rc0-186-g20447144ec In-Reply-To: <20201214202647.3340193-1-gitster@pobox.com> References: <20201214202647.3340193-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B64AEBF2-3E4A-11EB-AE97-D609E328BF65-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org It is easy enough to do, gives a more descriptive name to the variable, and there is no reason to make the code deliberately worse by ignoring improvement offered on the list. Signed-off-by: Junio C Hamano --- builtin/pull.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index ff8e3ce137..2976b8e5cb 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 @@ -326,7 +324,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(void) +static enum rebase_type config_get_rebase(int *rebase_unspecified) { struct branch *curr_branch = branch_get("HEAD"); const char *value; @@ -346,7 +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; + *rebase_unspecified = 1; return REBASE_FALSE; } @@ -934,6 +932,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct object_id orig_head, curr_head; struct object_id rebase_fork_point; int autostash; + int rebase_unspecified = 0; if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -955,7 +954,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) opt_ff = xstrdup_or_null(config_get_ff()); if (opt_rebase < 0) - opt_rebase = config_get_rebase(); + opt_rebase = config_get_rebase(&rebase_unspecified); if (read_cache_unmerged()) die_resolve_conflict("pull"); @@ -1029,7 +1028,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); - if (default_mode && opt_verbosity >= 0 && !opt_ff) { + if (rebase_unspecified && opt_verbosity >= 0 && !opt_ff) { advise(_("Pulling without specifying how to reconcile divergent branches is\n" "discouraged. You can squelch this message by running one of the following\n" "commands sometime before your next pull:\n" From patchwork Mon Dec 14 20:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11972991 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 C5F19C4361B for ; Mon, 14 Dec 2020 20:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 904E1221EF for ; Mon, 14 Dec 2020 20:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502964AbgLNU2Z (ORCPT ); Mon, 14 Dec 2020 15:28:25 -0500 Received: from pb-smtp2.pobox.com ([64.147.108.71]:61499 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503316AbgLNU1s (ORCPT ); Mon, 14 Dec 2020 15:27:48 -0500 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id ABA7B93DD7; Mon, 14 Dec 2020 15:27:00 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=oilOWwehxT95ihjLN24qVBjKt M0=; b=Cqu+42LtPlqSXOjmJxIyQqhke4ev24mBMwy5wf8BIq8A6YqNR0bB0oHEt ASOqWu7/ycopf8Rxuu9YftelmMZLfSpkwy+Gr/5bIgpTxVBIf0xXq4pjTtBz6bPL H3UK2mucbExVYLqvtvZNin5E8MRCCRx/HghHeTGez3jCOuMuTk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=EI6HwNGCwPzci4AiRqr TXS9d3CwQPCFNFLFGf/niHXM6YmLkvyS9sLhthhQnUprVUg7OHJe3/RhR2RlT17S qzobQTWqQbry/kIxJCs5Xs8tGK++7SyHEZQV5cQ3Bzcc7VE/rl0/Yx1g9yqIWKwe yJcQRbHOCYtIENVLkabSkXfw= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 510FE93DD6; Mon, 14 Dec 2020 15:27:00 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id A780093DD5; Mon, 14 Dec 2020 15:26:59 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v7 4/5] pull: correct condition to trigger non-ff advice Date: Mon, 14 Dec 2020 12:26:46 -0800 Message-Id: <20201214202647.3340193-5-gitster@pobox.com> X-Mailer: git-send-email 2.30.0-rc0-186-g20447144ec In-Reply-To: <20201214202647.3340193-1-gitster@pobox.com> References: <20201214202647.3340193-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B7CBFFAC-3E4A-11EB-B8FA-74DE23BA3BAF-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the advise() call that teaches users how they can choose between merge and rebase into a helper function. This revealed that the caller's logic needs to be further clarified to allow future actions (like "erroring out" instead of the current "go ahead and merge anyway") that should happen whether the advice message is squelched out. Signed-off-by: Junio C Hamano --- builtin/pull.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 2976b8e5cb..1b87ea95eb 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -925,6 +925,22 @@ static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_ return ret; } +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" + "\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")); +} + int cmd_pull(int argc, const char **argv, const char *prefix) { const char *repo, **refspecs; @@ -1028,19 +1044,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); - if (rebase_unspecified && opt_verbosity >= 0 && !opt_ff) { - advise(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" - " git config pull.ff only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); + if (rebase_unspecified && !opt_ff) { + if (opt_verbosity >= 0) + show_advice_pull_non_ff(); } if (opt_rebase) { From patchwork Mon Dec 14 20:26:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11972995 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 60D56C4361B for ; Mon, 14 Dec 2020 20:29:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 127EB2226A for ; Mon, 14 Dec 2020 20:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503145AbgLNU2e (ORCPT ); Mon, 14 Dec 2020 15:28:34 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:56830 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503317AbgLNU1t (ORCPT ); Mon, 14 Dec 2020 15:27:49 -0500 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 7B1CAA9C9E; Mon, 14 Dec 2020 15:27:01 -0500 (EST) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=uYw5/HbGkNxvemBvndopmIZaE Mg=; b=JlQNzFwxi609QguxhNMHJ37wgu3SrzdZgnITM37ijQroDxOAuzGCCnVse lvCQC5546vktuQS3n1ywnETKg5fnJnPEIzK6kSp7YW9gWVIsSYUWub2IEl4cCA0d lF17L9PkdHgKlnI4w6vRP9/F3b0ipeSilmW3bXv5IDxdMPrNQg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=LP3FMQhkNn1G4CV95gM T7iiLpoABEGXet62klbDSVFduzEx4dh7Wt93k6QN31O1XqdtnLaSqXGNTRFNry+n 0gnifJntZ2Jmfxvug5jx+ANF8I5tMwSJMITfMSxsRtihEuaj27BzTyIDRXtjrQ09 rj5Xvwvri6qh7YNhevul+LAU= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6FE19A9C9D; Mon, 14 Dec 2020 15:27:01 -0500 (EST) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 990B0A9C9C; Mon, 14 Dec 2020 15:27:00 -0500 (EST) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v7 5/5] pull: display default warning only when non-ff Date: Mon, 14 Dec 2020 12:26:47 -0800 Message-Id: <20201214202647.3340193-6-gitster@pobox.com> X-Mailer: git-send-email 2.30.0-rc0-186-g20447144ec In-Reply-To: <20201214202647.3340193-1-gitster@pobox.com> References: <20201214202647.3340193-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: B85B8172-3E4A-11EB-B494-D152C8D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Felipe Contreras There's no need to display the annoying warning on every pull... only the ones that are not fast-forward. The current warning tests still pass, but not because of the arguments or the configuration, but because they are all fast-forward. We need to test non-fast-forward situations now. Suggestions-by: Junio C Hamano Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin/pull.c | 7 ++-- t/t7601-merge-pull-config.sh | 66 +++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 1b87ea95eb..e8927fc2ff 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -949,6 +949,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct object_id rebase_fork_point; int autostash; int rebase_unspecified = 0; + int can_ff; if (!getenv("GIT_REFLOG_ACTION")) set_reflog_message(argc, argv); @@ -1044,7 +1045,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase && merge_heads.nr > 1) die(_("Cannot rebase onto multiple branches.")); - if (rebase_unspecified && !opt_ff) { + can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); + + if (rebase_unspecified && !opt_ff && !can_ff) { if (opt_verbosity >= 0) show_advice_pull_non_ff(); } @@ -1063,7 +1066,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { - if (get_can_ff(&orig_head, &merge_heads.oid[0])) { + if (can_ff) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; ran_ff = 1; diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 6774e9d86f..52e8ccc933 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -29,11 +29,8 @@ test_expect_success 'setup' ' test_expect_success 'pull.rebase not set' ' git reset --hard c0 && - git -c color.advice=always pull . c1 2>err && - test_decode_color decoded && - test_i18ngrep "hint: " decoded && - test_i18ngrep "Pulling without specifying how to reconcile" decoded - + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err ' test_expect_success 'pull.rebase not set and pull.ff=true' ' @@ -87,6 +84,65 @@ test_expect_success 'pull.rebase not set and --ff-only given' ' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' +test_expect_success 'pull.rebase not set (not-fast-forward)' ' + git reset --hard c2 && + git -c color.advice=always pull . c1 2>err && + test_decode_color decoded && + test_i18ngrep "hint: " decoded && + test_i18ngrep "Pulling without specifying how to reconcile" decoded +' + +test_expect_success 'pull.rebase not set and pull.ff=true (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff true && + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff false && + git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' ' + git reset --hard c2 && + test_config pull.ff only && + test_must_fail git pull . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --rebase given (not-fast-forward)' ' + git reset --hard c2 && + git pull --rebase . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --no-rebase given (not-fast-forward)' ' + git reset --hard c2 && + git pull --no-rebase . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --ff given (not-fast-forward)' ' + git reset --hard c2 && + git pull --ff . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' ' + git reset --hard c2 && + git pull --no-ff . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' ' + git reset --hard c2 && + test_must_fail git pull --ff-only . c1 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + test_expect_success 'merge c1 with c2' ' git reset --hard c1 && test -f c0.c &&