From patchwork Wed Jul 21 01:42:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389849 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=-12.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 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 2B6FAC636C8 for ; Wed, 21 Jul 2021 01:43:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1160B610F7 for ; Wed, 21 Jul 2021 01:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbhGUBC1 (ORCPT ); Tue, 20 Jul 2021 21:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbhGUBB7 (ORCPT ); Tue, 20 Jul 2021 21:01:59 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A7AC061762 for ; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id y21-20020a7bc1950000b02902161fccabf1so2520673wmi.2 for ; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=KxJkBheq548xtQ4rZAGg4aLZc02uro/12/govHV5GFw=; b=fdUbF//thlGBdleQ02M/nxTjJMek1cPFRZCUlenXsOS+j/182B3oRND5OTbGW3UPPn tq0rjVOuaygoq4bknio/v49vT4wFTNr3QJSGs5UvpKmxKe2eWhKOZNpDXngr9Wa/gZP0 Hybu9a18MyuQtRhCDhMiwjCJ5eKLdlEVHdGw4mcQN+gcdL5Lf5N0OzugRjQ2nErkAEOt juhknVRifVrOuxXIFFlsJYN3BQmNLuiCPa1R5CWOgeX4IMcXGWIfCcaLYnrpFMml9FdR F1cOA2JXYAcuPS7lHHOut1z3v2f1RjfbsJ7t27NeLjDX6GsApSZtZndRnfftlRlbzblf Qy4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=KxJkBheq548xtQ4rZAGg4aLZc02uro/12/govHV5GFw=; b=pM3SlaKBM0CpBnFTYvhBnEF2+tHo0FrYvmW7qSGgWCZvHbz7CyBqoCoyuFlZpaVZu7 pUiuteYnzBnnrqx/GXmTA8tUXe8MZ/Zu2SO5oROymgxHlXuykG9rUzE/UrP5Mzy65Wtj b/SF6gpitxFFcie0reAC8Jj1Puve7iWFAVeb3/DkPcNyBdG+Iln4JUnz45UbTnbsicX+ OD+1PrS2jn+XTAo1dshi6HQOeVNgkwaF1vfYSYLyqCFOOUiYUVK/pED+tYLX1DRXfIk1 6BDtc/nnXX53EmZCgVZLaR6vEhvEhNUJUiO9J2NOHG8Y1ZSJB5yBiCskK0Mrv7sNy01H 9Sbg== X-Gm-Message-State: AOAM532uxNecW0mZQoUAQ3GkV4WbLVkAjBYDt54ES597o1LtW+ZzyQnR oWLXxoHadYk7qG+jqT2XNSxZYuTGrUQ= X-Google-Smtp-Source: ABdhPJwz5JQjwyPkYWqvLVjd73QvlTk8sbVGaHWtmf5GP1jyki1ZvKav080k85+TTMbrMVV1QGb1Dg== X-Received: by 2002:a05:600c:1d04:: with SMTP id l4mr1347955wms.130.1626831746857; Tue, 20 Jul 2021 18:42:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b15sm29680762wrr.27.2021.07.20.18.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:26 -0700 (PDT) Message-Id: <175609272110e4f8d71dce3e6c4e6ca010a8f366.1626831744.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:17 +0000 Subject: [PATCH v2 1/8] t7601: test interaction of merge/rebase/fast-forward flags and options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren The interaction of rebase and merge flags and options was not well tested. Add several tests to check for correct behavior from the following rules: * --ff-only vs. --[no-]rebase (and the related pull.ff=only vs. pull.rebase) * --rebase[=!false] vs. --no-ff and --ff (and the related pull.rebase=!false overrides pull.ff=!only) * command line flags take precedence over config, except: * --no-rebase heeds pull.ff=!only * pull.rebase=!false vs --no-ff and --ff For more details behind these rules and a larger table of individual cases, refer to https://lore.kernel.org/git/xmqqwnpqot4m.fsf@gitster.g/ and the links found therein. Signed-off-by: Elijah Newren --- t/t7601-merge-pull-config.sh | 182 +++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 52e8ccc933a..a44e6e69f2b 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -143,6 +143,188 @@ test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' test_i18ngrep ! "Pulling without specifying how to reconcile" err ' +test_does_rebase () { + git reset --hard c2 && + git "$@" . c1 && + # Check that we actually did a rebase + git rev-list --count HEAD >actual && + git rev-list --merges --count HEAD >>actual && + test_write_lines 3 0 >expect && + test_cmp expect actual && + rm actual expect +} + +# Prefers merge over fast-forward +test_does_merge_when_ff_possible () { + git reset --hard c0 && + git "$@" . c1 && + # Check that we actually did a merge + git rev-list --count HEAD >actual && + git rev-list --merges --count HEAD >>actual && + test_write_lines 3 1 >expect && + test_cmp expect actual && + rm actual expect +} + +# Prefers fast-forward over merge or rebase +test_does_fast_forward () { + git reset --hard c0 && + git "$@" . c1 && + + # Check that we did not get any merges + git rev-list --count HEAD >actual && + git rev-list --merges --count HEAD >>actual && + test_write_lines 2 0 >expect && + test_cmp expect actual && + + # Check that we ended up at c1 + git rev-parse HEAD >actual && + git rev-parse c1^{commit} >expect && + test_cmp actual expect && + + # Remove temporary files + rm actual expect +} + +# Doesn't fail when fast-forward not possible; does a merge +test_falls_back_to_full_merge () { + git reset --hard c2 && + git "$@" . c1 && + # Check that we actually did a merge + git rev-list --count HEAD >actual && + git rev-list --merges --count HEAD >>actual && + test_write_lines 4 1 >expect && + test_cmp expect actual && + rm actual expect +} + +# Attempts fast forward, which is impossible, and bails +test_attempts_fast_forward () { + git reset --hard c2 && + test_must_fail git "$@" . c1 2>err && + test_i18ngrep "Not possible to fast-forward, aborting" err +} + +# +# Group 1: Interaction of --ff-only with --[no-]rebase +# (And related interaction of pull.ff=only with pull.rebase) +# +test_expect_failure '--ff-only overrides --rebase' ' + test_attempts_fast_forward pull --rebase --ff-only +' + +test_expect_failure '--ff-only overrides --rebase even if first' ' + test_attempts_fast_forward pull --ff-only --rebase +' + +test_expect_success '--ff-only overrides --no-rebase' ' + test_attempts_fast_forward pull --ff-only --no-rebase +' + +test_expect_failure 'pull.ff=only overrides pull.rebase=true' ' + test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull +' + +test_expect_success 'pull.ff=only overrides pull.rebase=false' ' + test_attempts_fast_forward -c pull.ff=only -c pull.rebase=false pull +' + +# Group 2: --rebase=[!false] overrides --no-ff and --ff +# (And related interaction of pull.rebase=!false and pull.ff=!only) +test_expect_success '--rebase overrides --no-ff' ' + test_does_rebase pull --rebase --no-ff +' + +test_expect_success '--rebase overrides --ff' ' + test_does_rebase pull --rebase --ff +' + +test_expect_success '--rebase fast-forwards when possible' ' + test_does_fast_forward pull --rebase --ff +' + +test_expect_success 'pull.rebase=true overrides pull.ff=false' ' + test_does_rebase -c pull.rebase=true -c pull.ff=false pull +' + +test_expect_success 'pull.rebase=true overrides pull.ff=true' ' + test_does_rebase -c pull.rebase=true -c pull.ff=true pull +' + +# Group 3: command line flags take precedence over config +test_expect_failure '--ff-only takes precedence over pull.rebase=true' ' + test_attempts_fast_forward -c pull.rebase=true pull --ff-only +' + +test_expect_success '--ff-only takes precedence over pull.rebase=false' ' + test_attempts_fast_forward -c pull.rebase=false pull --ff-only +' + +test_expect_failure '--no-rebase takes precedence over pull.ff=only' ' + test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase +' + +test_expect_success '--rebase takes precedence over pull.ff=only' ' + test_does_rebase -c pull.ff=only pull --rebase +' + +test_expect_success '--rebase overrides pull.ff=true' ' + test_does_rebase -c pull.ff=true pull --rebase +' + +test_expect_success '--rebase overrides pull.ff=false' ' + test_does_rebase -c pull.ff=false pull --rebase +' + +test_expect_success '--rebase overrides pull.ff unset' ' + test_does_rebase pull --rebase +' + +# Group 4: --no-rebase heeds pull.ff=!only or explict --ff or --no-ff + +test_expect_success '--no-rebase works with --no-ff' ' + test_does_merge_when_ff_possible pull --no-rebase --no-ff +' + +test_expect_success '--no-rebase works with --ff' ' + test_does_fast_forward pull --no-rebase --ff +' + +test_expect_success '--no-rebase does ff if pull.ff unset' ' + test_does_fast_forward pull --no-rebase +' + +test_expect_success '--no-rebase heeds pull.ff=true' ' + test_does_fast_forward -c pull.ff=true pull --no-rebase +' + +test_expect_success '--no-rebase heeds pull.ff=false' ' + test_does_merge_when_ff_possible -c pull.ff=false pull --no-rebase +' + +# Group 5: pull.rebase=!false in combination with --no-ff or --ff +test_expect_success 'pull.rebase=true and --no-ff' ' + test_does_rebase -c pull.rebase=true pull --no-ff +' + +test_expect_success 'pull.rebase=true and --ff' ' + test_does_rebase -c pull.rebase=true pull --ff +' + +test_expect_success 'pull.rebase=false and --no-ff' ' + test_does_merge_when_ff_possible -c pull.rebase=false pull --no-ff +' + +test_expect_success 'pull.rebase=false and --ff, ff possible' ' + test_does_fast_forward -c pull.rebase=false pull --ff +' + +test_expect_success 'pull.rebase=false and --ff, ff not possible' ' + test_falls_back_to_full_merge -c pull.rebase=false pull --ff +' + +# End of groupings for conflicting merge vs. rebase flags/options + test_expect_success 'merge c1 with c2' ' git reset --hard c1 && test -f c0.c && From patchwork Wed Jul 21 01:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389851 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=-12.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 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 D4F65C07E9B for ; Wed, 21 Jul 2021 01:43:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B853661178 for ; Wed, 21 Jul 2021 01:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbhGUBCc (ORCPT ); Tue, 20 Jul 2021 21:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbhGUBB7 (ORCPT ); Tue, 20 Jul 2021 21:01:59 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2D99C061766 for ; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id r11so376211wro.9 for ; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=FatQESMdxjTv017icNsVsMBtN1cbyEjxJj/PZ8GgCvM=; b=osavVzMXoNfw54vDyqUkuu3WNsgQXZ7Cz2UF34VpbC3m4y3EuhGGdIVwgF+1bwJK8u twsoZpFvPWq2T2H4mByzPntl1Lzl1mMoDFOUSEUvPjjmLulaCqIzxwOPXb1MenjFHfvW 2tsovw0qEXf1yJcjo3DO0CEpax1nmqfHsCEOcL6gm9EFgSsAxUVDX0q1AbG86dc8p9yW 3El4o+RLa6ivIAqgHu3GAlGQBzBp5wCByRyBPAqpiZZMzPRhjiPfn5Jz8h4zXf+aq6dv SM0qXnc7kY/5pygIKR+HCxKNteeE8L+cp0i8SpL6PleVjZniD9Cc9Sux8iyu40i2aJn4 u2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=FatQESMdxjTv017icNsVsMBtN1cbyEjxJj/PZ8GgCvM=; b=t2jKlx8YZ4GPjCIaYVthT7oTuGgwzW684bGXpN0+WzW/0VuSNgcMWlCneBicbNPVbP MC278b6TV7SHGrcbXPaZ/s9vCDCAvSHFOwQrXfHPEpNW1xVG6ks9EiB58k4RRU2I5qAv cUZSoEIhqP50gN+0TUTvHp5m7TRXb07CJZguFEovpNFmdBMwYwmX6NCbXO95fF3Ih0jV Ts0hNA7QtIHtZc3ZzV+Bu5klKcKTpF6F9fRHhTybM0FGzEFuaygH21awHXDyIpqZFc6w hpWGY+ZIEeiuHT1zUxjPVyljhBXcuN69hLvkx6KaRf4xslzcgryh8GQxHvYo/Fy0hd7H g7kA== X-Gm-Message-State: AOAM530JxRvq+edobsMmA6775wsVIoY2vNY8/bw7U829Gprk7HJrM6me /NrwaoDQyLxuo/gXfWvFrJZr6OcMNcg= X-Google-Smtp-Source: ABdhPJwNhYrnXH3aYaE+c1VeJclswxl0HQDNmGcvEhKg2RQ1Oy12DnMqpmnF4vxsAXh12m9UJIZaEg== X-Received: by 2002:a5d:6ac8:: with SMTP id u8mr40306905wrw.30.1626831747438; Tue, 20 Jul 2021 18:42:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w18sm3245667wrs.44.2021.07.20.18.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:27 -0700 (PDT) Message-Id: <66fe7f7f9341c11bc72eaf4cfa7b1d6c658e31a8.1626831744.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:18 +0000 Subject: [PATCH v2 2/8] t7601: add tests of interactions with multiple merge heads and config Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren There were already code checking that --rebase was incompatible with a merge of multiple heads. However, we were sometimes throwing warnings about lack of specification of rebase vs. merge when given multiple heads. Since rebasing is disallowed with multiple merge heads, that seems like a poor warning to print; we should instead just assume merging is wanted. Add a few tests checking multiple merge head behavior. Signed-off-by: Elijah Newren --- t/t7601-merge-pull-config.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index a44e6e69f2b..21db1e9e14b 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -325,6 +325,28 @@ test_expect_success 'pull.rebase=false and --ff, ff not possible' ' # End of groupings for conflicting merge vs. rebase flags/options +test_expect_failure 'Multiple heads warns about inability to fast forward' ' + git reset --hard c1 && + test_must_fail git pull . c2 c3 2>err && + test_i18ngrep "Pulling without specifying how to reconcile" err +' + +test_expect_failure 'Multiple can never be fast forwarded' ' + git reset --hard c0 && + test_must_fail git -c pull.ff=only pull . c1 c2 c3 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err && + # In addition to calling out "cannot fast-forward", we very much + # want the "multiple branches" piece to be called out to users. + test_i18ngrep "Cannot fast-forward to multiple branches" err +' + +test_expect_success 'Cannot rebase with multiple heads' ' + git reset --hard c0 && + test_must_fail git -c pull.rebase=true pull . c1 c2 c3 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err && + test_i18ngrep "Cannot rebase onto multiple branches." err +' + test_expect_success 'merge c1 with c2' ' git reset --hard c1 && test -f c0.c && From patchwork Wed Jul 21 01:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12389847 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=-12.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 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 6126BC07E9B for ; Wed, 21 Jul 2021 01:42:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CD4E61175 for ; Wed, 21 Jul 2021 01:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbhGUBCI (ORCPT ); Tue, 20 Jul 2021 21:02:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbhGUBB7 (ORCPT ); Tue, 20 Jul 2021 21:01:59 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635C8C061767 for ; Tue, 20 Jul 2021 18:42:29 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id i94so395147wri.4 for ; Tue, 20 Jul 2021 18:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IFqFaKyXiAefTGKoC9snpcrEzuGy0Vkzel8b0+ws4a4=; b=a7/RUfnxWqWv5bB6hccXuHcfqNweelEdr08ZZPTJsIYT10L2RwIRhGKz7VJyNwLSQB IfEcqs6AqJDWhPJb1muRCkVXGsKGcT5VAhl1ykMS5S7ClG/D+9DiBOkO1g4RipzZLaU2 b8aba56365TLhfoMLajDhtikPyq3rWdc7caOtDV4cS0sT5lUCJe78vSt8H2e37itS6bd fjG6Mas20pdWevppchwa2RGgZRQGzkAQl3bB33HzqzVHZaq4uDgflaQAqPHJMPPzOUpq XHZ0Q7RkPchjpCLt8S5g5fW82FmxQYREiCgzI/4chA4J4EFDv4Gvc5Pw5K6ysYPb3Kd7 3Lig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IFqFaKyXiAefTGKoC9snpcrEzuGy0Vkzel8b0+ws4a4=; b=IsV2URm15RREM3MSuyuXe8CrzE/UuByxdpbXIGuByyS5YHtS3PmlvLjJrUJOX7IWjV PUJvR/7lR5oojN6cQcEHI2aM3FikeRjN2CMIB2/UeIu46LN0EqjzdVtbRQHtncosDQ7f 9svaRVAJeJS5y5Pa+Z+fHf1FaXIMyXa472LVIWjX/BaSiDfsBgSJBW34tti7Dcytoh/h q41LD8BB0h0YbEfSyqGbRTK5PdhpEjTM7sDzcndogY8quOLfUjfdZZYzjrLloqG9PPEJ FLicJQSksebp+4D747motsfH/vR7kfPQS+YniaXrHKJ7jGKutDXiHt6ksrmj2nWt0huK 7BDA== X-Gm-Message-State: AOAM530dvdZ/4q/i2bkS4Nt9za6wT8Fq1benbc5iPvo0NjduZc7IVKQw C4XSZpaLTbFc5FXCF1FFidwQsGHLKT4= X-Google-Smtp-Source: ABdhPJyRbxhu6TkPcvKXBrZ6JlaPHMeRlVxzwrfGxNFPh/bp7nkD/0NAW1qkOC+hGcXb72E50glKSg== X-Received: by 2002:a5d:634e:: with SMTP id b14mr38159531wrw.81.1626831748017; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h15sm24474285wrq.88.2021.07.20.18.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:27 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:19 +0000 Subject: [PATCH v2 3/8] pull: abort if --ff-only is given and fast-forwarding is impossible Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Alex Henrie Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alex Henrie From: Alex Henrie The warning about pulling without specifying how to reconcile divergent branches says that after setting pull.rebase to true, --ff-only can still be passed on the command line to require a fast-forward. Make that actually work. Signed-off-by: Alex Henrie [en: updated tests; note 3 fixes and 1 new failure] Signed-off-by: Elijah Newren --- advice.c | 5 +++++ advice.h | 1 + builtin/merge.c | 2 +- builtin/pull.c | 11 ++++++++--- t/t7601-merge-pull-config.sh | 10 +++++----- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/advice.c b/advice.c index 0b9c89c48ab..337e8f342bc 100644 --- a/advice.c +++ b/advice.c @@ -286,6 +286,11 @@ void NORETURN die_conclude_merge(void) die(_("Exiting because of unfinished merge.")); } +void NORETURN die_ff_impossible(void) +{ + die(_("Not possible to fast-forward, aborting.")); +} + void advise_on_updating_sparse_paths(struct string_list *pathspec_list) { struct string_list_item *item; diff --git a/advice.h b/advice.h index bd26c385d00..16240438387 100644 --- a/advice.h +++ b/advice.h @@ -95,6 +95,7 @@ void advise_if_enabled(enum advice_type type, const char *advice, ...); int error_resolve_conflict(const char *me); void NORETURN die_resolve_conflict(const char *me); void NORETURN die_conclude_merge(void); +void NORETURN die_ff_impossible(void); void advise_on_updating_sparse_paths(struct string_list *pathspec_list); void detach_advice(const char *new_name); diff --git a/builtin/merge.c b/builtin/merge.c index a8a843b1f54..aa920ac524f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1620,7 +1620,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) } if (fast_forward == FF_ONLY) - die(_("Not possible to fast-forward, aborting.")); + die_ff_impossible(); if (autostash) create_autostash(the_repository, diff --git a/builtin/pull.c b/builtin/pull.c index 3e13f810843..d9796604825 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1046,9 +1046,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix) 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(); + if (!can_ff) { + if (opt_ff) { + if (!strcmp(opt_ff, "--ff-only")) + die_ff_impossible(); + } else { + if (rebase_unspecified && opt_verbosity >= 0) + show_advice_pull_non_ff(); + } } if (opt_rebase) { diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 21db1e9e14b..d1f621725ad 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -209,11 +209,11 @@ test_attempts_fast_forward () { # Group 1: Interaction of --ff-only with --[no-]rebase # (And related interaction of pull.ff=only with pull.rebase) # -test_expect_failure '--ff-only overrides --rebase' ' +test_expect_success '--ff-only overrides --rebase' ' test_attempts_fast_forward pull --rebase --ff-only ' -test_expect_failure '--ff-only overrides --rebase even if first' ' +test_expect_success '--ff-only overrides --rebase even if first' ' test_attempts_fast_forward pull --ff-only --rebase ' @@ -221,7 +221,7 @@ test_expect_success '--ff-only overrides --no-rebase' ' test_attempts_fast_forward pull --ff-only --no-rebase ' -test_expect_failure 'pull.ff=only overrides pull.rebase=true' ' +test_expect_success 'pull.ff=only overrides pull.rebase=true' ' test_attempts_fast_forward -c pull.ff=only -c pull.rebase=true pull ' @@ -252,7 +252,7 @@ test_expect_success 'pull.rebase=true overrides pull.ff=true' ' ' # Group 3: command line flags take precedence over config -test_expect_failure '--ff-only takes precedence over pull.rebase=true' ' +test_expect_success '--ff-only takes precedence over pull.rebase=true' ' test_attempts_fast_forward -c pull.rebase=true pull --ff-only ' @@ -264,7 +264,7 @@ test_expect_failure '--no-rebase takes precedence over pull.ff=only' ' test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase ' -test_expect_success '--rebase takes precedence over pull.ff=only' ' +test_expect_failure '--rebase takes precedence over pull.ff=only' ' test_does_rebase -c pull.ff=only pull --rebase ' From patchwork Wed Jul 21 01:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389863 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=-12.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 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 486E1C636C9 for ; Wed, 21 Jul 2021 01:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33FFF610F7 for ; Wed, 21 Jul 2021 01:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231301AbhGUBDO (ORCPT ); Tue, 20 Jul 2021 21:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbhGUBCH (ORCPT ); Tue, 20 Jul 2021 21:02:07 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5674DC0613DB for ; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id x14-20020a7bc20e0000b0290249f2904453so44353wmi.1 for ; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1UCY7UForPBm5YSkc9esdo7zarpxMjwVtqmvE7a43wg=; b=n0OjsgxEucTmk7OMCaJpeIqEj5pJMV0Vj74/X7fgldcHnuJGcWUDVNsW7iig/xfFIJ H2vsgfQXAujY3FN/pgV/44Q6ipjLWSYbaNZOaQxzNep5UB1EFagCzDF3FvzT/c4DxT+/ 0sxNZnRM71Lv4rbgT+uwRrBgUiMtecdet8H7+9GZrUID8dEdaFQXKpa2CyyZD1zLBUgG pox9PxH3qc+P0iseLPo3r75+KvE6SoCWfY2RMdAvSTPaTxR7cHgWfNqyQLWUmyN0/h71 nlg4Kl473/krSyLyCw3UkcLPE5t7rGHZpwMlnCLzUjy/C8/f2hPnGOEco7L8wLK9Ic/B QiMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1UCY7UForPBm5YSkc9esdo7zarpxMjwVtqmvE7a43wg=; b=tHVKpPxTC5lVUAujUp6DywOf1+LtqaTS26faSA2K2t9bOELXcZUK1O7xCimFj0KqMu l7t6x4jpHqLlcULTsWYKMfIqjHNPK3J2L5kspE/SOaCqfZc3EljNlQJyq3uhkSUvsOml rtkjpm9Dv5/A7586rFiT4aYlqxZ6KoJ7exUT8oZZ6/Rnvfl8+HpFPrHsj8TLrfriXXZx fwA4lnCAjjurMlegiQNyauftx0HJ26NSMWJurr5gkGr3fGx0WZGvv2PAGpQxIvsZnafy ojofSBscfKXpd9jGSomeB3OyI2ZwkZNSpix/Mupmfphyn8T8QG4TMjgh7siIhQz9HN5T twTA== X-Gm-Message-State: AOAM530mfi1hwHaNDZk/AJOs/CPCdycSRRBUN9SEhGzy74WOsf7vl4bB 4+nAgIp+1a/7yctDHUyQYgkPaKQmxfs= X-Google-Smtp-Source: ABdhPJz2UieBcW78II3FwL1mmE79mC4PucW6+p52Y7Y81qPUtHbuuvN9oKaRsycwoXsliLPnlAeXpw== X-Received: by 2002:a7b:ca50:: with SMTP id m16mr1332253wml.140.1626831748621; Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g7sm3769578wmq.22.2021.07.20.18.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Message-Id: <1a821d3b1ddf22b62b14d3b573015c3d8c90e2de.1626831744.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:20 +0000 Subject: [PATCH v2 4/8] pull: since --ff-only overrides, handle it first Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren There are both merge and rebase branches in the logic, and previously both had to handle fast-forwarding. Merge handled that implicitly (because git merge handles it directly), while in rebase it was explicit. Given that the --ff-only flag is meant to override any --rebase or --no-rebase, make the code reflect that by handling --ff-only before the merge-vs-rebase logic. It turns out that this also fixes a bug for submodules. Previously, when --ff-only was given, the code would run `merge --ff-only` on the main module, and then run `submodule update --recursive --rebase` on the submodules. With this change, we still run `merge --ff-only` on the main module, but now run `submodule update --recursive --checkout` on the submodules. I believe this better reflects the intent of --ff-only to have it apply to both the main module and the submodules. (Sidenote: It is somewhat interesting that all merges pass `--checkout` to submodule update, even when `--no-ff` is specified, meaning that it will only do fast-forward merges for submodules. This was discussed in commit a6d7eb2c7a ("pull: optionally rebase submodules (remote submodule changes only)", 2017-06-23). The same limitations apply now as then, so we are not trying to fix this at this time.) Signed-off-by: Elijah Newren --- builtin/pull.c | 24 +++++++++--------------- t/t5520-pull.sh | 6 +++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index d9796604825..92150f976cd 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1046,15 +1046,15 @@ int cmd_pull(int argc, const char **argv, const char *prefix) can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); - if (!can_ff) { - if (opt_ff) { - if (!strcmp(opt_ff, "--ff-only")) - die_ff_impossible(); - } else { - if (rebase_unspecified && opt_verbosity >= 0) - show_advice_pull_non_ff(); - } + /* ff-only takes precedence over rebase */ + if (opt_ff && !strcmp(opt_ff, "--ff-only")) { + if (!can_ff) + die_ff_impossible(); + opt_rebase = REBASE_FALSE; } + /* If no action specified and we can't fast forward, then warn. */ + if (!opt_ff && rebase_unspecified && !can_ff) + show_advice_pull_non_ff(); if (opt_rebase) { int ret = 0; @@ -1069,13 +1069,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 (can_ff) { - /* we can fast-forward this without invoking rebase */ - opt_ff = "--ff-only"; - ret = run_merge(); - } else { - ret = run_rebase(&newbase, &upstream); - } + ret = run_rebase(&newbase, &upstream); if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index e2c0c510222..4b50488141f 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -295,7 +295,7 @@ test_expect_success '--rebase (merge) fast forward' ' # The above only validates the result. Did we actually bypass rebase? git reflog -1 >reflog.actual && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && - echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && + echo "OBJID HEAD@{0}: pull --rebase . ff (finish): returning to refs/heads/to-rebase" >reflog.expected && test_cmp reflog.expected reflog.fuzzy ' @@ -307,8 +307,8 @@ test_expect_success '--rebase (am) fast forward' ' # The above only validates the result. Did we actually bypass rebase? git reflog -1 >reflog.actual && - sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && - echo "OBJID HEAD@{0}: pull --rebase . ff: Fast-forward" >reflog.expected && + sed -e "s/^[0-9a-f][0-9a-f]*/OBJID/" -e "s/[0-9a-f][0-9a-f]*$/OBJID/" reflog.actual >reflog.fuzzy && + echo "OBJID HEAD@{0}: rebase finished: refs/heads/to-rebase onto OBJID" >reflog.expected && test_cmp reflog.expected reflog.fuzzy ' From patchwork Wed Jul 21 01:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389853 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=-12.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 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 66815C07E9B for ; Wed, 21 Jul 2021 01:43:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C3AD61175 for ; Wed, 21 Jul 2021 01:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbhGUBCq (ORCPT ); Tue, 20 Jul 2021 21:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230173AbhGUBB7 (ORCPT ); Tue, 20 Jul 2021 21:01:59 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D7EAC061768 for ; Tue, 20 Jul 2021 18:42:30 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id m2so403206wrq.2 for ; Tue, 20 Jul 2021 18:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2xRQIKYaSNZjQO64KokUzEw19VQR81HQ8kMdXsa/6cY=; b=SscHMNtFYuAtL/uT11vT09335wCYMzIZfeLC+Q/0PKwDCqi7f84iNJgrHPJt1A2NB/ S0KubTi3vGTb8twLcqwZu0HgLifbNNZGAAv1pDzz8CDybn8uoQIaBGSnVgeWeCAb/78d 6hOU7gGa8nWmDgePa7r5JlDJcNkMewoN87FIXx4VSFb6bA/a+TLzZ+gtFIEsysmwSNWd zq2pzHP1UcSYAYEASck1uLmpkECi4ubbIxSFfaltY/4KNUOWHbiNiQ2Run9GPGq0/K7l 8eKcpMglq52asrDA1buzh7NVLI+CSGMNbJ2/+N3JZsYpxARStob+9et4/j03fQLJI/sv aPhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2xRQIKYaSNZjQO64KokUzEw19VQR81HQ8kMdXsa/6cY=; b=ftqOjBlBc2ndsyxygq2bl9YSTJH55igrgi/SgORyuWyv5Lxx7JSSk6zi/N3KeuTb4A X2ryklgDNGdfKRl49o0IE3ODrZfrNSvkE7eFRqB2O6x8kOtSEvaQJtaAUK4mq7VpqOEq ZsEHA4VEq3x3kV9NUuvBkDTalqeoxBWzKjV0G0v2g+kCpafu2CbxK+/5sRFH9cCMiYBp S1hMMSCFawB3zmODnh3aasVYQutK+2PxURvYNCI1pZSlcqYi5DMfbq5D4hGYFdhoVPFV hNhdsrK803S9HAwTY0ItftFIVFvfYkJUOGSVvqs33VGfcDjsMP/F9yBmBWhZVtHlCjwP JsvQ== X-Gm-Message-State: AOAM533iJ1WFmHGPkY448eGI6QxdxesF4bL7o+uLg49G+yq84CirBPHO 9FG1D6XI/ynkh+OIHt8jAUc6c3UPqQA= X-Google-Smtp-Source: ABdhPJxMLDuVQxYx5dLuON9jVyhr+7AOogCL1X0L8NA95QGWmYTSh9HmA5NR46QlaOeZu8nPcXFf2A== X-Received: by 2002:adf:f50e:: with SMTP id q14mr39392171wro.183.1626831749295; Tue, 20 Jul 2021 18:42:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g18sm20813753wmk.37.2021.07.20.18.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:28 -0700 (PDT) Message-Id: <9b116f3d284840052945292f73c47bacdb2f86d6.1626831744.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:21 +0000 Subject: [PATCH v2 5/8] pull: make --rebase and --no-rebase override pull.ff=only Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Fix the last few precedence tests failing in t7601 by now implementing the logic to have --[no-]rebase override a pull.ff=only config setting. Signed-off-by: Elijah Newren --- builtin/pull.c | 16 +++++++++++++++- t/t7601-merge-pull-config.sh | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 92150f976cd..da1d4b19666 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -966,8 +966,22 @@ int cmd_pull(int argc, const char **argv, const char *prefix) parse_repo_refspecs(argc, argv, &repo, &refspecs); - if (!opt_ff) + if (!opt_ff) { opt_ff = xstrdup_or_null(config_get_ff()); + /* + * A subtle point: opt_ff was set on the line above via + * reading from config. opt_rebase, in contrast, is set + * before this point via command line options. The setting + * of opt_rebase via reading from config (using + * config_get_rebase()) does not happen until later. We + * are relying on the next if-condition happening before + * the config_get_rebase() call so that an explicit + * "--rebase" can override a config setting of + * pull.ff=only. + */ + if (opt_rebase >= 0 && opt_ff && !strcmp(opt_ff, "--ff-only")) + opt_ff = "--ff"; + } if (opt_rebase < 0) opt_rebase = config_get_rebase(&rebase_unspecified); diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index d1f621725ad..0c0dfecd2a3 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -260,11 +260,11 @@ test_expect_success '--ff-only takes precedence over pull.rebase=false' ' test_attempts_fast_forward -c pull.rebase=false pull --ff-only ' -test_expect_failure '--no-rebase takes precedence over pull.ff=only' ' +test_expect_success '--no-rebase takes precedence over pull.ff=only' ' test_falls_back_to_full_merge -c pull.ff=only pull --no-rebase ' -test_expect_failure '--rebase takes precedence over pull.ff=only' ' +test_expect_success '--rebase takes precedence over pull.ff=only' ' test_does_rebase -c pull.ff=only pull --rebase ' From patchwork Wed Jul 21 01:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389861 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=-12.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 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 D1FE6C07E9B for ; Wed, 21 Jul 2021 01:43:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6EB661175 for ; Wed, 21 Jul 2021 01:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbhGUBDK (ORCPT ); Tue, 20 Jul 2021 21:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbhGUBCH (ORCPT ); Tue, 20 Jul 2021 21:02:07 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D7A2C0613DC for ; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id q18-20020a1ce9120000b02901f259f3a250so61952wmc.2 for ; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qb6Qv/QTG8TQipZzjrlI6gWR2sPxI5Lvdl6+RVCYh7k=; b=QPTliYvBu2KbbK1nQWe4iywH7gRDYk1ke09J4F2jAIszy1svprRl6gXBWj78nBgh9F 4wNzEe/2rB220r1L/ug1tDJCJHrK8/IaunpgjscsDCxzBn0tbSpQYAEKxxMlKWLmRKgX x5G+7Hv45cdcDafDSjgW7B5H74lg+LtgDiVjedU1YYYJzAAEi8oNr6D1QRyQTNgCnogi UW4j/8E7piehkurlFNuBOpE+NMnOHckMKNxY5vVzuNPxJTZed2U4OweJw/0eiZYtaTeB IfVxakB3OdO0noGXBM36/2RY92pd+Y9DXiiTZRXj9JYM6Dcpii8RTr81zT+xMYHUwDzR wE1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qb6Qv/QTG8TQipZzjrlI6gWR2sPxI5Lvdl6+RVCYh7k=; b=L/h0bT0vHJ9tzLnsQvlL4dFrvdOdBxTWb/PJklhIbK4hKbUo7/GvY2O6EtsRo1q0kZ 118D2jtC1i3spab3f9ddWdyQvTaMkFkr1ubNSG8R0ZzFfMFsZV3b1mNzOtghyDn3J10M rMJa6mXOpKLC9NfR2l3eRDNM/GCnHC/Oq/7T5l05ixWkILPi+bd8gcP54u0sEhcX8I2p LrZp3czdh3+Tly9JeQFFCbR0wxtmDng6tGywHXhGpSi0MSq1j3+Sl+rJakPO/BXq0vyg J9htp3scRvbMqM7zZxUOxPnAd5D/iTRN0eGRGUNM18DC7Y7aumoGv693YEkDvGX15DiE HLnA== X-Gm-Message-State: AOAM532c+kXj3UOFPJHT+9Hroe0CbYsMNsdskuQBZ224k6YRuw+KMEtI 7hZ4B5EldTVAa9RP7CLXAnqUV16SSWk= X-Google-Smtp-Source: ABdhPJzGKAPoTvLN6qNPE0Bv7afb4KAIXvtiHnm4gJPe7qjzZ+1SBm2Zcj5vF893nIbseqkxfrHUKg== X-Received: by 2002:a7b:ce8b:: with SMTP id q11mr33595022wmj.80.1626831749929; Tue, 20 Jul 2021 18:42:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s4sm23839976wmh.41.2021.07.20.18.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:29 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:22 +0000 Subject: [PATCH v2 6/8] pull: abort by default when fast-forwarding is not possible Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren We have for some time shown a long warning when the user does not specify how to reconcile divergent branches with git pull. Make it an error now. Initial-patch-by: Alex Henrie Signed-off-by: Elijah Newren --- Documentation/git-pull.txt | 20 +++++++++------ builtin/pull.c | 10 +++++--- t/t4013-diff-various.sh | 2 +- t/t5520-pull.sh | 20 +++++++-------- t/t5521-pull-options.sh | 4 +-- t/t5524-pull-msg.sh | 4 +-- t/t5553-set-upstream.sh | 14 +++++----- t/t5604-clone-reference.sh | 4 +-- t/t6402-merge-rename.sh | 18 ++++++------- t/t6409-merge-subtree.sh | 6 ++--- t/t6417-merge-ours-theirs.sh | 10 ++++---- t/t7601-merge-pull-config.sh | 48 +++++++++++++++++------------------ t/t7603-merge-reduce-heads.sh | 2 +- 13 files changed, 84 insertions(+), 78 deletions(-) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index 5c3fb67c014..cad3f6bfcee 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -15,14 +15,18 @@ SYNOPSIS DESCRIPTION ----------- -Incorporates changes from a remote repository into the current -branch. In its default mode, `git pull` is shorthand for -`git fetch` followed by `git merge FETCH_HEAD`. - -More precisely, 'git pull' runs 'git fetch' with the given -parameters and calls 'git merge' to merge the retrieved branch -heads into the current branch. -With `--rebase`, it runs 'git rebase' instead of 'git merge'. +Incorporates changes from a remote repository into the current branch. +If the current branch is behind the remote, then by default it will +fast-forward the current branch to match the remote. If the current +branch and the remote have diverged, the user needs to specify how to +reconcile the divergent branches with `--no-ff`, `--ff`, or `--rebase` +(or the corresponding configuration options in `pull.ff` or +`pull.rebase`). + +More precisely, `git pull` runs `git fetch` with the given parameters +and then depending on configuration options or command line flags, +will call either `git merge` or `git rebase` to reconcile diverging +branches. should be the name of a remote repository as passed to linkgit:git-fetch[1]. can name an diff --git a/builtin/pull.c b/builtin/pull.c index da1d4b19666..94464ca196f 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -927,9 +927,9 @@ static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_ static void show_advice_pull_non_ff(void) { - advise(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" + advise(_("You have divergent branches and need to specify how to reconcile them.\n" + "You can do so by running one of the following commands sometime before\n" + "your next pull:\n" "\n" " git config pull.rebase false # merge (the default strategy)\n" " git config pull.rebase true # rebase\n" @@ -1067,8 +1067,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) opt_rebase = REBASE_FALSE; } /* If no action specified and we can't fast forward, then warn. */ - if (!opt_ff && rebase_unspecified && !can_ff) + if (!opt_ff && rebase_unspecified && !can_ff) { show_advice_pull_non_ff(); + die(_("Need to specify how to reconcile divergent branches.")); + } if (opt_rebase) { int ret = 0; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 7fadc985ccc..eb989f7f191 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -65,7 +65,7 @@ test_expect_success setup ' export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && git checkout master && - git pull -s ours . side && + git pull -s ours --no-rebase . side && GIT_AUTHOR_DATE="2006-06-26 00:05:00 +0000" && GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 4b50488141f..56f5864b269 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -136,12 +136,12 @@ test_expect_success 'the default remote . should not break explicit pull' ' git reset --hard HEAD^ && echo file >expect && test_cmp expect file && - git pull . second && + git pull --no-rebase . second && echo modified >expect && test_cmp expect file && git reflog -1 >reflog.actual && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && - echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected && + echo "OBJID HEAD@{0}: pull --no-rebase . second: Fast-forward" >reflog.expected && test_cmp reflog.expected reflog.fuzzy ' @@ -226,7 +226,7 @@ test_expect_success 'fail if the index has unresolved entries' ' test_commit modified2 file && git ls-files -u >unmerged && test_must_be_empty unmerged && - test_must_fail git pull . second && + test_must_fail git pull --no-rebase . second && git ls-files -u >unmerged && test_file_not_empty unmerged && cp file expected && @@ -409,37 +409,37 @@ test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' ' test_expect_success 'pull succeeds with dirty working directory and merge.autostash set' ' test_config merge.autostash true && - test_pull_autostash 2 + test_pull_autostash 2 --no-rebase ' test_expect_success 'pull --autostash & merge.autostash=true' ' test_config merge.autostash true && - test_pull_autostash 2 --autostash + test_pull_autostash 2 --autostash --no-rebase ' test_expect_success 'pull --autostash & merge.autostash=false' ' test_config merge.autostash false && - test_pull_autostash 2 --autostash + test_pull_autostash 2 --autostash --no-rebase ' test_expect_success 'pull --autostash & merge.autostash unset' ' test_unconfig merge.autostash && - test_pull_autostash 2 --autostash + test_pull_autostash 2 --autostash --no-rebase ' test_expect_success 'pull --no-autostash & merge.autostash=true' ' test_config merge.autostash true && - test_pull_autostash_fail --no-autostash + test_pull_autostash_fail --no-autostash --no-rebase ' test_expect_success 'pull --no-autostash & merge.autostash=false' ' test_config merge.autostash false && - test_pull_autostash_fail --no-autostash + test_pull_autostash_fail --no-autostash --no-rebase ' test_expect_success 'pull --no-autostash & merge.autostash unset' ' test_unconfig merge.autostash && - test_pull_autostash_fail --no-autostash + test_pull_autostash_fail --no-autostash --no-rebase ' test_expect_success 'pull.rebase' ' diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index 63a688bdbf5..7601c919fdc 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -113,7 +113,7 @@ test_expect_success 'git pull --force' ' git pull two && test_commit A && git branch -f origin && - git pull --all --force + git pull --no-rebase --all --force ) ' @@ -179,7 +179,7 @@ test_expect_success 'git pull --allow-unrelated-histories' ' ( cd dst && test_must_fail git pull ../src side && - git pull --allow-unrelated-histories ../src side + git pull --no-rebase --allow-unrelated-histories ../src side ) ' diff --git a/t/t5524-pull-msg.sh b/t/t5524-pull-msg.sh index c278adaa5a2..b2be3605f5a 100755 --- a/t/t5524-pull-msg.sh +++ b/t/t5524-pull-msg.sh @@ -28,7 +28,7 @@ test_expect_success setup ' test_expect_success pull ' ( cd cloned && - git pull --log && + git pull --no-rebase --log && git log -2 && git cat-file commit HEAD >result && grep Dollar result @@ -41,7 +41,7 @@ test_expect_success '--log=1 limits shortlog length' ' git reset --hard HEAD^ && test "$(cat afile)" = original && test "$(cat bfile)" = added && - git pull --log=1 && + git pull --no-rebase --log=1 && git log -3 && git cat-file commit HEAD >result && grep Dollar result && diff --git a/t/t5553-set-upstream.sh b/t/t5553-set-upstream.sh index b1d614ce18c..9c12c0f8c32 100755 --- a/t/t5553-set-upstream.sh +++ b/t/t5553-set-upstream.sh @@ -108,27 +108,27 @@ test_expect_success 'setup commit on main and other pull' ' test_expect_success 'pull --set-upstream upstream main sets branch main but not other' ' clear_config main other && - git pull --set-upstream upstream main && + git pull --no-rebase --set-upstream upstream main && check_config main upstream refs/heads/main && check_config_missing other ' test_expect_success 'pull --set-upstream main:other2 does not set the branch other2' ' clear_config other2 && - git pull --set-upstream upstream main:other2 && + git pull --no-rebase --set-upstream upstream main:other2 && check_config_missing other2 ' test_expect_success 'pull --set-upstream upstream other sets branch main' ' clear_config main other && - git pull --set-upstream upstream other && + git pull --no-rebase --set-upstream upstream other && check_config main upstream refs/heads/other && check_config_missing other ' test_expect_success 'pull --set-upstream upstream tag does not set the tag' ' clear_config three && - git pull --tags --set-upstream upstream three && + git pull --no-rebase --tags --set-upstream upstream three && check_config_missing three ' @@ -144,16 +144,16 @@ test_expect_success 'pull --set-upstream http://nosuchdomain.example.com fails w test_expect_success 'pull --set-upstream upstream HEAD sets branch HEAD' ' clear_config main other && - git pull --set-upstream upstream HEAD && + git pull --no-rebase --set-upstream upstream HEAD && check_config main upstream HEAD && git checkout other && - git pull --set-upstream upstream HEAD && + git pull --no-rebase --set-upstream upstream HEAD && check_config other upstream HEAD ' test_expect_success 'pull --set-upstream upstream with more than one branch does nothing' ' clear_config main three && - git pull --set-upstream upstream main three && + git pull --no-rebase --set-upstream upstream main three && check_config_missing main && check_config_missing three ' diff --git a/t/t5604-clone-reference.sh b/t/t5604-clone-reference.sh index e845d621f61..24340e6d56e 100755 --- a/t/t5604-clone-reference.sh +++ b/t/t5604-clone-reference.sh @@ -87,7 +87,7 @@ test_expect_success 'updating origin' ' ' test_expect_success 'pulling changes from origin' ' - git -C C pull origin + git -C C pull --no-rebase origin ' # the 2 local objects are commit and tree from the merge @@ -96,7 +96,7 @@ test_expect_success 'that alternate to origin gets used' ' ' test_expect_success 'pulling changes from origin' ' - git -C D pull origin + git -C D pull --no-rebase origin ' # the 5 local objects are expected; file3 blob, commit in A to add it diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh index 3da2896e3bc..3a32b1a45cf 100755 --- a/t/t6402-merge-rename.sh +++ b/t/t6402-merge-rename.sh @@ -103,7 +103,7 @@ test_expect_success 'setup' ' test_expect_success 'pull renaming branch into unrenaming one' \ ' git show-branch && - test_expect_code 1 git pull . white && + test_expect_code 1 git pull --no-rebase . white && git ls-files -s && test_stdout_line_count = 3 git ls-files -u B && test_stdout_line_count = 1 git ls-files -s N && @@ -119,7 +119,7 @@ test_expect_success 'pull renaming branch into another renaming one' \ rm -f B && git reset --hard && git checkout red && - test_expect_code 1 git pull . white && + test_expect_code 1 git pull --no-rebase . white && test_stdout_line_count = 3 git ls-files -u B && test_stdout_line_count = 1 git ls-files -s N && sed -ne "/^g/{ @@ -133,7 +133,7 @@ test_expect_success 'pull unrenaming branch into renaming one' \ ' git reset --hard && git show-branch && - test_expect_code 1 git pull . main && + test_expect_code 1 git pull --no-rebase . main && test_stdout_line_count = 3 git ls-files -u B && test_stdout_line_count = 1 git ls-files -s N && sed -ne "/^g/{ @@ -147,7 +147,7 @@ test_expect_success 'pull conflicting renames' \ ' git reset --hard && git show-branch && - test_expect_code 1 git pull . blue && + test_expect_code 1 git pull --no-rebase . blue && test_stdout_line_count = 1 git ls-files -u A && test_stdout_line_count = 1 git ls-files -u B && test_stdout_line_count = 1 git ls-files -u C && @@ -163,7 +163,7 @@ test_expect_success 'interference with untracked working tree file' ' git reset --hard && git show-branch && echo >A this file should not matter && - test_expect_code 1 git pull . white && + test_expect_code 1 git pull --no-rebase . white && test_path_is_file A ' @@ -173,7 +173,7 @@ test_expect_success 'interference with untracked working tree file' ' git show-branch && rm -f A && echo >A this file should not matter && - test_expect_code 1 git pull . red && + test_expect_code 1 git pull --no-rebase . red && test_path_is_file A ' @@ -183,7 +183,7 @@ test_expect_success 'interference with untracked working tree file' ' git checkout -f main && git tag -f anchor && git show-branch && - git pull . yellow && + git pull --no-rebase . yellow && test_path_is_missing M && git reset --hard anchor ' @@ -210,7 +210,7 @@ test_expect_success 'updated working tree file should prevent the merge' ' echo >>M one line addition && cat M >M.saved && git update-index M && - test_expect_code 128 git pull . yellow && + test_expect_code 128 git pull --no-rebase . yellow && test_cmp M M.saved && rm -f M.saved ' @@ -222,7 +222,7 @@ test_expect_success 'interference with untracked working tree file' ' git tag -f anchor && git show-branch && echo >M this file should not matter && - git pull . main && + git pull --no-rebase . main && test_path_is_file M && ! { git ls-files -s | diff --git a/t/t6409-merge-subtree.sh b/t/t6409-merge-subtree.sh index d406b2343cb..ba7890ec521 100755 --- a/t/t6409-merge-subtree.sh +++ b/t/t6409-merge-subtree.sh @@ -100,7 +100,7 @@ test_expect_success 'merge update' ' git checkout -b topic_2 && git commit -m "update git-gui" && cd ../git && - git pull -s subtree gui topic_2 && + git pull --no-rebase -s subtree gui topic_2 && git ls-files -s >actual && ( echo "100644 $o3 0 git-gui/git-gui.sh" && @@ -129,7 +129,7 @@ test_expect_success 'initial ambiguous subtree' ' test_expect_success 'merge using explicit' ' cd ../git && git reset --hard topic_2 && - git pull -Xsubtree=git-gui gui topic_2 && + git pull --no-rebase -Xsubtree=git-gui gui topic_2 && git ls-files -s >actual && ( echo "100644 $o3 0 git-gui/git-gui.sh" && @@ -142,7 +142,7 @@ test_expect_success 'merge using explicit' ' test_expect_success 'merge2 using explicit' ' cd ../git && git reset --hard topic_2 && - git pull -Xsubtree=git-gui2 gui topic_2 && + git pull --no-rebase -Xsubtree=git-gui2 gui topic_2 && git ls-files -s >actual && ( echo "100644 $o1 0 git-gui/git-gui.sh" && diff --git a/t/t6417-merge-ours-theirs.sh b/t/t6417-merge-ours-theirs.sh index ac9aee9a662..ec065d6a658 100755 --- a/t/t6417-merge-ours-theirs.sh +++ b/t/t6417-merge-ours-theirs.sh @@ -69,11 +69,11 @@ test_expect_success 'binary file with -Xours/-Xtheirs' ' ' test_expect_success 'pull passes -X to underlying merge' ' - git reset --hard main && git pull -s recursive -Xours . side && - git reset --hard main && git pull -s recursive -X ours . side && - git reset --hard main && git pull -s recursive -Xtheirs . side && - git reset --hard main && git pull -s recursive -X theirs . side && - git reset --hard main && test_must_fail git pull -s recursive -X bork . side + git reset --hard main && git pull --no-rebase -s recursive -Xours . side && + git reset --hard main && git pull --no-rebase -s recursive -X ours . side && + git reset --hard main && git pull --no-rebase -s recursive -Xtheirs . side && + git reset --hard main && git pull --no-rebase -s recursive -X theirs . side && + git reset --hard main && test_must_fail git pull --no-rebase -s recursive -X bork . side ' test_expect_success SYMLINKS 'symlink with -Xours/-Xtheirs' ' diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 0c0dfecd2a3..742ed3981c7 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -27,120 +27,120 @@ test_expect_success 'setup' ' git tag c3 ' -test_expect_success 'pull.rebase not set' ' +test_expect_success 'pull.rebase not set, ff possible' ' git reset --hard c0 && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and pull.ff=true' ' git reset --hard c0 && test_config pull.ff true && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and pull.ff=false' ' git reset --hard c0 && test_config pull.ff false && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and pull.ff=only' ' git reset --hard c0 && test_config pull.ff only && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --rebase given' ' git reset --hard c0 && git pull --rebase . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --no-rebase given' ' git reset --hard c0 && git pull --no-rebase . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --ff given' ' git reset --hard c0 && git pull --ff . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --no-ff given' ' git reset --hard c0 && git pull --no-ff . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --ff-only given' ' git reset --hard c0 && git pull --ff-only . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" 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_must_fail 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_i18ngrep "You have divergent branches" 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_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and pull.ff=false (not-fast-forward)' ' git reset --hard c2 && test_config pull.ff false && git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and pull.ff=only (not-fast-forward)' ' git reset --hard c2 && test_config pull.ff only && test_must_fail git pull . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" 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_i18ngrep ! "You have divergent branches" 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_i18ngrep ! "You have divergent branches" 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_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --no-ff given (not-fast-forward)' ' git reset --hard c2 && git pull --no-ff . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_expect_success 'pull.rebase not set and --ff-only given (not-fast-forward)' ' git reset --hard c2 && test_must_fail git pull --ff-only . c1 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err + test_i18ngrep ! "You have divergent branches" err ' test_does_rebase () { @@ -325,16 +325,16 @@ test_expect_success 'pull.rebase=false and --ff, ff not possible' ' # End of groupings for conflicting merge vs. rebase flags/options -test_expect_failure 'Multiple heads warns about inability to fast forward' ' +test_expect_success 'Multiple heads warns about inability to fast forward' ' git reset --hard c1 && test_must_fail git pull . c2 c3 2>err && - test_i18ngrep "Pulling without specifying how to reconcile" err + test_i18ngrep "You have divergent branches" err ' test_expect_failure 'Multiple can never be fast forwarded' ' git reset --hard c0 && test_must_fail git -c pull.ff=only pull . c1 c2 c3 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err && + test_i18ngrep ! "You have divergent branches" err && # In addition to calling out "cannot fast-forward", we very much # want the "multiple branches" piece to be called out to users. test_i18ngrep "Cannot fast-forward to multiple branches" err @@ -343,7 +343,7 @@ test_expect_failure 'Multiple can never be fast forwarded' ' test_expect_success 'Cannot rebase with multiple heads' ' git reset --hard c0 && test_must_fail git -c pull.rebase=true pull . c1 c2 c3 2>err && - test_i18ngrep ! "Pulling without specifying how to reconcile" err && + test_i18ngrep ! "You have divergent branches" err && test_i18ngrep "Cannot rebase onto multiple branches." err ' diff --git a/t/t7603-merge-reduce-heads.sh b/t/t7603-merge-reduce-heads.sh index 98948955ae5..27cd94ad6f7 100755 --- a/t/t7603-merge-reduce-heads.sh +++ b/t/t7603-merge-reduce-heads.sh @@ -68,7 +68,7 @@ test_expect_success 'merge c1 with c2, c3, c4, c5' ' test_expect_success 'pull c2, c3, c4, c5 into c1' ' git reset --hard c1 && - git pull . c2 c3 c4 c5 && + git pull --no-rebase . c2 c3 c4 c5 && test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" && test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" && From patchwork Wed Jul 21 01:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389859 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=-12.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 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 44B33C07E9B for ; Wed, 21 Jul 2021 01:43:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B64661178 for ; Wed, 21 Jul 2021 01:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbhGUBDC (ORCPT ); Tue, 20 Jul 2021 21:03:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbhGUBCH (ORCPT ); Tue, 20 Jul 2021 21:02:07 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05791C0613DD for ; Tue, 20 Jul 2021 18:42:32 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id f9so368560wrq.11 for ; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=rcHy2kpyRrd2ur35EtZQmqWsp1/MLlYIB4KAKIEEBjM=; b=eU1EWz33nouYslDTpYCHVv0P6NQboYwyg+Zwyvt8sBwhjsT7KcfiLAj3baonoVTbl0 JVOz/XxPXkusQf6XslmkdoU0SeZxdpNZvj4Y+QggrR16E/of45wrKs4aRUkwkPeGDy8m 4WzbnNsa9GJanq8weo0UEwkP/8WoLlQYotB+eMjD28wGmSn1XqwPa2Rb1nE2MQlZ6Cv/ ofe6107oXlZLnjSPH21bX+zFhMADZpr0yAeM4Bl0gSzLQjUJCPTnr58/ueKD2FTgldNR XGgRDeb4/3dExXNSCRWBAZ9mprwwod51eP9qvVALFV2qPwFQXS/VasOyLmCS3HK/YU5V mCng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=rcHy2kpyRrd2ur35EtZQmqWsp1/MLlYIB4KAKIEEBjM=; b=POiPZOR0H7r06S02xrELtYMtge/PDQrUItI9yC01csIkoIps5qQVP2Q9oXjEhBHlwS esh1K1ZiZ7595Whle3LgHnu+s5/d92ixooAV1JmIBTZC8wvv5cfGRiqMfNdItgNyxN9y SfWI42uFMImADwKUTf+iXpY+bi2bY3I6cckicm8kCCFhswTYYmciWb6fEpkxSMNheQnY DNqEelY1upLV2wNtiLntZWozeltvqPVcXaWcF+iBDhsGz6CxOW9vEsq2KwABuWMEB5Dw vK0Bhi9sRAlcgkZZ59DqzX73kfqQ1ezXKX5XCRN30ty/Er6KWPz5bJeBvWAk+6Mheqy2 nq6Q== X-Gm-Message-State: AOAM5304ivxcCs7/j5pOZGS0UEqtSSVOQto9tB2j8Dntb9h+PG1R9Qag hSRvzrrZADSIrVBxN4pkxNhlZ7IHs9A= X-Google-Smtp-Source: ABdhPJxNyfTbippKaxHZXuT6pDPJlhIpiLvSFimHANYYR2A4s6oEloN4HaI1ivujLOBQcszQl7pNZg== X-Received: by 2002:a5d:65cb:: with SMTP id e11mr41159927wrw.105.1626831750558; Tue, 20 Jul 2021 18:42:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n18sm24382199wrt.89.2021.07.20.18.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:30 -0700 (PDT) Message-Id: <90d49e0fb7897512d7386a72787bb15c3f23a4f6.1626831744.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:23 +0000 Subject: [PATCH v2 7/8] pull: update docs & code for option compatibility with rebasing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren git-pull.txt includes merge-options.txt, which is written assuming merges will happen. git-pull has allowed rebases for many years; update the documentation to reflect that. While at it, pass any `--signoff` flag through to the rebase backend too so that we don't have to document it as merge-specific. Rebase has supported the --signoff flag for years now as well. Signed-off-by: Elijah Newren --- Documentation/git-merge.txt | 2 ++ Documentation/git-pull.txt | 9 ++++---- Documentation/merge-options.txt | 40 +++++++++++++++++++++++++++++++++ builtin/pull.c | 2 ++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index 3819fadac1f..e4f3352eb58 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -61,6 +61,8 @@ merge has resulted in conflicts. OPTIONS ------- +:git-merge: 1 + include::merge-options.txt[] -m :: diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index cad3f6bfcee..077961dfa1f 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -19,13 +19,12 @@ Incorporates changes from a remote repository into the current branch. If the current branch is behind the remote, then by default it will fast-forward the current branch to match the remote. If the current branch and the remote have diverged, the user needs to specify how to -reconcile the divergent branches with `--no-ff`, `--ff`, or `--rebase` -(or the corresponding configuration options in `pull.ff` or -`pull.rebase`). +reconcile the divergent branches with `--rebase` or `--no-rebase` (or +the corresponding configuration option in `pull.rebase`). More precisely, `git pull` runs `git fetch` with the given parameters and then depending on configuration options or command line flags, -will call either `git merge` or `git rebase` to reconcile diverging +will call either `git rebase` or `git merge` to reconcile diverging branches. should be the name of a remote repository as @@ -136,7 +135,7 @@ published that history already. Do *not* use this option unless you have read linkgit:git-rebase[1] carefully. --no-rebase:: - Override earlier --rebase. + This is shorthand for --rebase=false. Options related to fetching ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index eb0aabd396f..907327bf759 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -2,6 +2,9 @@ --no-commit:: Perform the merge and commit the result. This option can be used to override --no-commit. +ifdef::git-pull[] + Only useful when merging. +endif::git-pull[] + With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further @@ -39,6 +42,7 @@ set to `no` at the beginning of them. to `MERGE_MSG` before being passed on to the commit machinery in the case of a merge conflict. +ifdef::git-merge[] --ff:: --no-ff:: --ff-only:: @@ -47,6 +51,22 @@ set to `no` at the beginning of them. default unless merging an annotated (and possibly signed) tag that is not stored in its natural place in the `refs/tags/` hierarchy, in which case `--no-ff` is assumed. +endif::git-merge[] +ifdef::git-pull[] +--ff-only:: + Only update to the new history if there is no divergent local + history. This is the default when no method for reconciling + divergent histories is provided (via the --rebase=* flags). + +--ff:: +--no-ff:: + When merging rather than rebasing, specifies how a merge is + handled when the merged-in history is already a descendant of + the current history. If merging is requested, `--ff` is the + default unless merging an annotated (and possibly signed) tag + that is not stored in its natural place in the `refs/tags/` + hierarchy, in which case `--no-ff` is assumed. +endif::git-pull[] + With `--ff`, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a @@ -55,9 +75,11 @@ descendant of the current history), create a merge commit. + With `--no-ff`, create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward. +ifdef::git-merge[] + With `--ff-only`, resolve the merge as a fast-forward when possible. When not possible, refuse to merge and exit with a non-zero status. +endif::git-merge[] -S[]:: --gpg-sign[=]:: @@ -73,6 +95,9 @@ When not possible, refuse to merge and exit with a non-zero status. In addition to branch names, populate the log message with one-line descriptions from at most actual commits that are being merged. See also linkgit:git-fmt-merge-msg[1]. +ifdef::git-pull[] + Only useful when merging. +endif::git-pull[] + With --no-log do not list one-line descriptions from the actual commits being merged. @@ -102,10 +127,17 @@ With --no-squash perform the merge and commit the result. This option can be used to override --squash. + With --squash, --commit is not allowed, and will fail. +ifdef::git-pull[] ++ +Only useful when merging. +endif::git-pull[] --no-verify:: This option bypasses the pre-merge and commit-msg hooks. See also linkgit:githooks[5]. +ifdef::git-pull[] + Only useful when merging. +endif::git-pull[] -s :: --strategy=:: @@ -127,6 +159,10 @@ With --squash, --commit is not allowed, and will fail. default trust model, this means the signing key has been signed by a trusted key. If the tip commit of the side branch is not signed with a valid key, the merge is aborted. +ifdef::git-pull[] ++ +Only useful when merging. +endif::git-pull[] --summary:: --no-summary:: @@ -166,3 +202,7 @@ endif::git-pull[] projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added. +ifdef::git-pull[] ++ +Only useful when merging. +endif::git-pull[] diff --git a/builtin/pull.c b/builtin/pull.c index 94464ca196f..a15d4154093 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -893,6 +893,8 @@ static int run_rebase(const struct object_id *newbase, strvec_pushv(&args, opt_strategy_opts.v); if (opt_gpg_sign) strvec_push(&args, opt_gpg_sign); + if (opt_signoff) + strvec_push(&args, opt_signoff); if (opt_autostash == 0) strvec_push(&args, "--no-autostash"); else if (opt_autostash == 1) From patchwork Wed Jul 21 01:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12389857 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=-12.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 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 ACA6AC636C8 for ; Wed, 21 Jul 2021 01:43:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90D0C6113B for ; Wed, 21 Jul 2021 01:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbhGUBCx (ORCPT ); Tue, 20 Jul 2021 21:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbhGUBCH (ORCPT ); Tue, 20 Jul 2021 21:02:07 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF59C0613DE for ; Tue, 20 Jul 2021 18:42:32 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id k4so380319wrc.8 for ; Tue, 20 Jul 2021 18:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HiROisDT4T5MvSgx7njmc0Y7ZYyNM7DadaK7YGuEV+0=; b=XyJElbFgpiM2qGyoqm+Z+9FnvVS17JGRWgGWE086eMjtq53uaJDFWEmZX1obX1xFoH T1YkzLT9N63RWM8yBUF7Igl6nhYYwSZI+Bnybl73u96JrvhmzykSsUhaZlazXnHqIRnb HSRk0rLhsBw+2Ib70TX9P0DsI64T4jnAnmtCTQDEh+HClH94Sl4nEFaoCWE3c0S9hhlo g0cZ/PoJUcBIIo0c8mlyUftrvpRLE7HTI3leILrRzVhYnRwCxC84Y0ey8P7BTCbYjjjI OrT0L3oo/Jj7pofUSqZ3KJYX22o30tIZxZowB1u9ZqQRFq8hfDry1aU8lmM063B7JL9l eTcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HiROisDT4T5MvSgx7njmc0Y7ZYyNM7DadaK7YGuEV+0=; b=Jw2HYaiN43T4l7T4C1ixUcXO+22NZ7UCEX5UQmWEMtuKt2lQJ26FlBkMrE5TPK86cT llqkjhsn2kQTAdkQ4dxU4SQ1FFkMzpaNvtcwkipD9ZS+AGxFmHLPghAVvavQPVdWSYUJ 3OVZZr4pg8MSASQKwSsPjz2czPqXSqvC9jBLOMgfhzKSJXA5sc/MQM26mFsl5djb1cNi C+JLdvqPfTAPvLCc3eK8M6G8eYWBkiBfCzAsEP6sHw7qL2aptub7jhspXdNxYsZplSQl MjI0frdoPfDWPa5KvhRaNAFGFijDTVyZN+YFrfCCmDQQSuqVaqJ0GGYVggLuJlimld4Y m97A== X-Gm-Message-State: AOAM532meSW5BbkH4KDG6cbUQ9CUo5LIr864XWq0l4ZyuQGbL1opysmM N/ZbcQOn4LSSwTpwMbvEZGn7vUQs1Jk= X-Google-Smtp-Source: ABdhPJwKGsNpD5D330I8FcIXviCCnc8puHxvzp5sUfYgHHwy1YJe+TCg9+X8SuKkSFNGHsG09aDxQQ== X-Received: by 2002:adf:d1c3:: with SMTP id b3mr20746125wrd.4.1626831751140; Tue, 20 Jul 2021 18:42:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u2sm20498426wmc.42.2021.07.20.18.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 18:42:30 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 21 Jul 2021 01:42:24 +0000 Subject: [PATCH v2 8/8] pull: fix handling of multiple heads Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Alex Henrie , Son Luong Ngoc , Matthias Baumgarten , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren With multiple heads, we should not allow rebasing or fast-forwarding. Make sure any fast-forward request calls out specifically the fact that multiple branches are in play. Also, since we cannot fast-forward to multiple branches, fix our computation of can_ff. Signed-off-by: Elijah Newren --- builtin/pull.c | 18 ++++++++++++++---- t/t7601-merge-pull-config.sh | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index a15d4154093..d6631d23d17 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -913,12 +913,18 @@ 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) +static int get_can_ff(struct object_id *orig_head, + struct oid_array *merge_heads) { int ret; struct commit_list *list = NULL; struct commit *merge_head, *head; + struct object_id *orig_merge_head; + if (merge_heads->nr > 1) + return 0; + + orig_merge_head = &merge_heads->oid[0]; head = lookup_commit_reference(the_repository, orig_head); commit_list_insert(head, &list); merge_head = lookup_commit_reference(the_repository, orig_merge_head); @@ -1057,10 +1063,14 @@ 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) - die(_("Cannot rebase onto multiple branches.")); + if (merge_heads.nr > 1) { + if (opt_rebase) + die(_("Cannot rebase onto multiple branches.")); + if (opt_ff && !strcmp(opt_ff, "--ff-only")) + die(_("Cannot fast-forward to multiple branches.")); + } - can_ff = get_can_ff(&orig_head, &merge_heads.oid[0]); + can_ff = get_can_ff(&orig_head, &merge_heads); /* ff-only takes precedence over rebase */ if (opt_ff && !strcmp(opt_ff, "--ff-only")) { diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 742ed3981c7..1f652f433ee 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -331,7 +331,7 @@ test_expect_success 'Multiple heads warns about inability to fast forward' ' test_i18ngrep "You have divergent branches" err ' -test_expect_failure 'Multiple can never be fast forwarded' ' +test_expect_success 'Multiple can never be fast forwarded' ' git reset --hard c0 && test_must_fail git -c pull.ff=only pull . c1 c2 c3 2>err && test_i18ngrep ! "You have divergent branches" err &&