From patchwork Sat Jul 17 15:41:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383693 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 3FCF7C636CA for ; Sat, 17 Jul 2021 15:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F09A61159 for ; Sat, 17 Jul 2021 15:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235220AbhGQPov (ORCPT ); Sat, 17 Jul 2021 11:44:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234952AbhGQPot (ORCPT ); Sat, 17 Jul 2021 11:44:49 -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 5AEAFC061764 for ; Sat, 17 Jul 2021 08:41:51 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id f9so15601052wrq.11 for ; Sat, 17 Jul 2021 08:41:51 -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=Bu1IrFBWIYKDh8eiAos2GhYRtXhHrFLYtKO7mu5ln8g=; b=S5E/Zu4cWi5zUdKESzAQeCSmU2zMjJ2Wo55IOHAgcwOVZkobb1yW9w0hL5QP2CazJx Ljjy2MUH4MH/fWtff7AaSOfaDI/O6f/WavLDbmlN9cCoUWC26rTvdwW4zdhxgwaE8nEs JMuOD493lyH4dVAerPuWjBaV5GCCIs8Pv9i11UWiUCctN35JZN92BviLUUS9b2xdkaLC RqUCpptiApj4wjUYoFKQerd8IxSsH3mkGpXEspRKCtMNFEA1s+4YuT8Runj9IMykCoSM 0hO43OcVj1Ie2vsY8oGZKfsUqVHAGLS/xlpsCcKpm52tvQN4RRO8lXpzICB0t/oTUT9o qrqQ== 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=Bu1IrFBWIYKDh8eiAos2GhYRtXhHrFLYtKO7mu5ln8g=; b=Am9VWvWdT2NQxAL87BMtt7xglnnJSIeTRhA7xNSalsoZ+r6eRU9Xnx1lNw9zxYLn3V q/6/bweVmH7jrDQMWcEWfM4+9RueW8SNYuXP/XYoPL5p6Sq3wOT7IYFBLrPkiDYPAFJs +RI+Q19rSpX5+d/Zb90ygz9zlcmtrTPAguhTCEyvM0NE1NcPhUoQEq2HB2oCO73DKKYR YpRgGkQxwkeHF8V87J3/UE20yoIS4mjXaR9pdA2E+KO6tmpynvvfmbS0AfyexxGhu7LS ix81zKEN8HPbdAyIJAiJ5yRNin2ud/OMzys9MbsFWa8LLbKDF7uWtKo0fKW0WJwTdCG9 PTEQ== X-Gm-Message-State: AOAM533x5yUfUfUBMvjHNu6OuAjuHMI17O2E25rg6dJdk+uIdxhDFEuc 55t5cuwfx2S3SbItFKM7OTqUj1+EOEY= X-Google-Smtp-Source: ABdhPJxAXM6/458aRwv27m1Nc+NxEhSEsnHrqa8rxVZKH3YdDVcBD2MJ5llfYlXUgi5ja23TFg3KJw== X-Received: by 2002:adf:eed0:: with SMTP id a16mr18753246wrp.324.1626536509994; Sat, 17 Jul 2021 08:41:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b12sm14195719wro.1.2021.07.17.08.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:49 -0700 (PDT) Message-Id: <6cb771297f5f7d5bb0c6734bcb3fe6d3b8bb4c88.1626536508.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:39 +0000 Subject: [PATCH 1/9] t7601: add relative precedence tests for merge and rebase flags/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 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 takes precedence over --[no-]rebase * Corollary: pull.ff=only overrides pull.rebase * --rebase[=!false] takes precedence over --no-ff and --ff * Corollary: pull.rebase=!false overrides pull.ff=!only * command line flags take precedence over config, except: * --no-rebase heeds pull.ff=!only * pull.rebase=!false takes precedence over --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 | 154 +++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 52e8ccc933a..b24c98cc1b6 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -143,6 +143,160 @@ 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 +} + +test_does_merge_noff() { + 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 +} + +test_does_merge_ff() { + 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 2 0 >expect && + test_cmp expect actual && + rm actual expect +} + +test_does_need_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 +} + +test_attempts_fast_forward() { + git reset --hard c2 && + test_must_fail git "$@" . c1 2>err && + test_i18ngrep "Not possible to fast-forward, aborting" err +} + +# +# Rule 1: --ff-only takes precedence over --[no-]rebase +# (Corollary: pull.ff=only overrides pull.rebase) +# +test_expect_failure '--ff-only takes precedence over --rebase' ' + test_attempts_fast_forward pull --rebase --ff-only +' + +test_expect_failure '--ff-only takes precedence over --rebase even if first' ' + test_attempts_fast_forward pull --ff-only --rebase +' + +test_expect_success '--ff-only takes precedence over --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 +' + +# Rule 2: --rebase=[!false] takes precedence over --no-ff and --ff +# (Corollary: pull.rebase=!false overrides pull.ff=!only) +test_expect_success '--rebase takes precedence over --no-ff' ' + test_does_rebase pull --rebase --no-ff +' + +test_expect_success '--rebase takes precedence over --ff' ' + test_does_rebase pull --rebase --ff +' + +test_expect_success 'pull.rebase=true takes precedence over pull.ff=false' ' + test_does_rebase -c pull.rebase=true -c pull.ff=false pull +' + +test_expect_success 'pull.rebase=true takes precedence over pull.ff=true' ' + test_does_rebase -c pull.rebase=true -c pull.ff=true pull +' + +# Rule 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 overrides pull.ff=only' ' + test_does_need_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 takes precedence over pull.ff=true' ' + test_does_rebase -c pull.ff=true pull --rebase +' + +test_expect_success '--rebase takes precedence over pull.ff=false' ' + test_does_rebase -c pull.ff=false pull --rebase +' + +test_expect_success '--rebase takes precedence over pull.ff unset' ' + test_does_rebase pull --rebase +' + +# Rule 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_noff pull --no-rebase --no-ff +' + +test_expect_success '--no-rebase works with --ff' ' + test_does_merge_ff pull --no-rebase --ff +' + +test_expect_success '--no-rebase does ff if pull.ff unset' ' + test_does_merge_ff pull --no-rebase +' + +test_expect_success '--no-rebase heeds pull.ff=true' ' + test_does_merge_ff -c pull.ff=true pull --no-rebase +' + +test_expect_success '--no-rebase heeds pull.ff=false' ' + test_does_merge_noff -c pull.ff=false pull --no-rebase +' + +# Rule 5: pull.rebase=!false takes precedence over --no-ff and --ff +test_expect_success 'pull.rebase=true takes precedence over --no-ff' ' + test_does_rebase -c pull.rebase=true pull --no-ff +' + +test_expect_success 'pull.rebase=true takes precedence over --ff' ' + test_does_rebase -c pull.rebase=true pull --ff +' + +# End of precedence rules + test_expect_success 'merge c1 with c2' ' git reset --hard c1 && test -f c0.c && From patchwork Sat Jul 17 15:41:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383691 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 DCA8FC636CB for ; Sat, 17 Jul 2021 15:41:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2BB76115C for ; Sat, 17 Jul 2021 15:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235261AbhGQPou (ORCPT ); Sat, 17 Jul 2021 11:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234930AbhGQPos (ORCPT ); Sat, 17 Jul 2021 11:44:48 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 076B9C06175F for ; Sat, 17 Jul 2021 08:41:52 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id f190so6013489wmf.4 for ; Sat, 17 Jul 2021 08:41:51 -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=3oE4NgXE1czZEdifxCLZiX0mFiAVGTk013xlWr3qtH4=; b=rgEgq1S2srsJpM8KZFzIVH4fMjcbUJQs0ibZx0FfKS0lDK4UiuSZHFDXESI5L0ynaZ FaIKg/R5zkUJ1uezIZLV3RYT+HUN6ogaOfIkftrt5afAKOMHtF23DDlxZ9Lxt3c6kTsW a/OzFT4/rrxpFWX+uvJV/+5ivMOH/q5IaZ+ViU04v4kRSC6vA8V84iLR4uwQy3awsvw5 0a9kw+RqumtCd8KQiW0+hysjlAt0kYu9aK6jxeSh3POAu1LyruEWFvyIZos2mSbjvArm e1P4x+VNFPlTGmIPZ/68KaJTRPE7RjjNnE4z4CMT5HGLdNQ/rN/zZS/rw8+DOaGsKffT MYTA== 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=3oE4NgXE1czZEdifxCLZiX0mFiAVGTk013xlWr3qtH4=; b=qSZPhjyoj1biGLMI2xhSEU5APxnRVDfWjw6cldtZEPNsdPm+G3W62/tt6pQ8VPhpzi auVybK207GkemrRXk79J2PboAlosmgsnwSR4ARoqs/tBu2pTR4rdekOn33pr4n7W9HC+ KrMnvCPR4Gf1yTeART/9JYJE9qwgdhDHrEnQWb5YhIiUsY4bDvtJc4CKFYRmfrZAnlcg fEY8u6CemEFoCfmottvKD6kSLcCa+EMnkMfQ37fWuznixx/cp4NyBU5ZIvKrFqNbqHZ4 NxyaDVmlAb6Dk1oCCZmqak5Cu2cI9o0Ww4F5FJvx4I0aqerxn3owFiCx/FoNOyR3WS0U GWaw== X-Gm-Message-State: AOAM532U/hgN/8kBwCT9teHPhTAugQjv+ZiOj9+6aED3G2UELXc2Qjuq eCJfxBKQtpQKupUi3FGeNyzLcrMptrA= X-Google-Smtp-Source: ABdhPJwmmSk10xSqYD1xux60RJo+upqgKkWa6MZb/tzBId7H9jnV2DBORnDXlAfo+aHF6jSvSYq0dQ== X-Received: by 2002:a05:600c:214a:: with SMTP id v10mr17288189wml.67.1626536510582; Sat, 17 Jul 2021 08:41:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d8sm14533247wrv.20.2021.07.17.08.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:50 -0700 (PDT) Message-Id: <329802382bfa24241c2333bd38284aa77e3eb9f0.1626536508.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:40 +0000 Subject: [PATCH 2/9] 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 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index b24c98cc1b6..40d8fb95113 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -297,6 +297,26 @@ test_expect_success 'pull.rebase=true takes precedence over --ff' ' # End of precedence rules +test_expect_failure 'Multiple heads does not warn about fast forwarding' ' + git reset --hard c1 && + git pull . c2 c3 2>err && + test_i18ngrep ! "Pulling without specifying how to reconcile" err +' + +test_expect_success 'Cannot fast-forward with multiple heads' ' + 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 "Not possible to fast-forward, aborting" 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 Sat Jul 17 15:41:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Henrie X-Patchwork-Id: 12383695 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 7B469C636CB for ; Sat, 17 Jul 2021 15:41:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 649A061179 for ; Sat, 17 Jul 2021 15:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235346AbhGQPox (ORCPT ); Sat, 17 Jul 2021 11:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235250AbhGQPou (ORCPT ); Sat, 17 Jul 2021 11:44:50 -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 B788DC06175F for ; Sat, 17 Jul 2021 08:41:52 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id a13so15591544wrf.10 for ; Sat, 17 Jul 2021 08:41:52 -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=JGp7s4pCml5nfXimznQtdu5QRUOVTkZhzOC/BjyS3Ug=; b=eP2VIWCuLGfDkG9hSoYh56dav3guc1l3HI0tIbbzuDUD3iJlTcBzdzZjYRFhPs235K Ya+jTpQYpvypH7LlKRhgCGdMX8dNahKke/FVeMY+kucnftqRU/xaK2ZP/18W7YdYtApz C5Oq1GJXr46mH/jH462rW9Q9dNn+tVrpA7vskhQ39MGS6Y8KvjnGo0sOJFOXRltFS/iU nJFjkgG5x2iFRsK1GcW/5Wb8ZVzqJYSiqvoFsux8YN2aa3n++onPtcQ30aZ93BY4lxT/ kXYAv7UhWtaDN7XQDBhv63H1E/jFVm8ArE8T3Zg6KjfMrYDahhNUET2eTYe526/PhXBp MYxQ== 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=JGp7s4pCml5nfXimznQtdu5QRUOVTkZhzOC/BjyS3Ug=; b=uB97l+tJPOQ3kR1iVY4iOyTtn7xzf9M0gHoEPcgF5yhP03B1Idz2zv3lMRJPV5Mcw5 4li9mB/YOSsYBRClsmlW1lTnuXO1E6mlZzD1cKgZne5ZylLxiWtXkwIi+t9cg0ri/oDM PwC4TG8RklH0MEAgG5Pmwuhwae2JVlHUsJeWOFkSb1RS/FjmOGlPRyFl8nX1iJ0Ph7CV sg+FgyCcubILllYabQHQ086osoiXOVOfIEr3p63hr3IrrVOfJzIGbYyibW6j3kY9cVxH pxep+KQfWeiYoPGZh4v3kZm17sCpMl6TT7RoXZsICtJ4kKq/9hPiyQUI0MYerjd5Gi+X IJLw== X-Gm-Message-State: AOAM5316D7Vft52Lp9K8zAPWpyULo8/1KYw1R1camzowiRh/g4oMGHpr sKSEl9ro9uy1ul3QKhcQEY7+uxXgnB0= X-Google-Smtp-Source: ABdhPJx0GYbrTF3Dbdmdn/+oU5Qsg2uXrb2w7jzqkjsmh0CyaCuRtiaiKOxumclHppzip5qk06oL5g== X-Received: by 2002:adf:ce83:: with SMTP id r3mr19635830wrn.204.1626536511377; Sat, 17 Jul 2021 08:41:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g15sm11088254wmh.44.2021.07.17.08.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:41 +0000 Subject: [PATCH 3/9] 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 , 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 40d8fb95113..23a1fbc17b3 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -197,11 +197,11 @@ test_attempts_fast_forward() { # Rule 1: --ff-only takes precedence over --[no-]rebase # (Corollary: pull.ff=only overrides pull.rebase) # -test_expect_failure '--ff-only takes precedence over --rebase' ' +test_expect_success '--ff-only takes precedence over --rebase' ' test_attempts_fast_forward pull --rebase --ff-only ' -test_expect_failure '--ff-only takes precedence over --rebase even if first' ' +test_expect_success '--ff-only takes precedence over --rebase even if first' ' test_attempts_fast_forward pull --ff-only --rebase ' @@ -209,7 +209,7 @@ test_expect_success '--ff-only takes precedence over --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 ' @@ -236,7 +236,7 @@ test_expect_success 'pull.rebase=true takes precedence over pull.ff=true' ' ' # Rule 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 ' @@ -248,7 +248,7 @@ test_expect_failure '--no-rebase overrides pull.ff=only' ' test_does_need_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 Sat Jul 17 15:41:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383697 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 DA3B9C636CA for ; Sat, 17 Jul 2021 15:41:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C57426115C for ; Sat, 17 Jul 2021 15:41:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235356AbhGQPoz (ORCPT ); Sat, 17 Jul 2021 11:44:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234930AbhGQPou (ORCPT ); Sat, 17 Jul 2021 11:44:50 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 040CCC061764 for ; Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id k4so15595159wrc.8 for ; Sat, 17 Jul 2021 08:41:53 -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=Oz+gR5ZaJqyzXvto4nobi5lD/J9jrUp0NPZJ8hG60bE=; b=j8hBqoO41ljM/h2DIrSVqBv/Ori/716a7KTa1Ct5CkXGEU+FKWnqmQxEuoeVLk1QJe L1m7nKlXpAUbRNObZ3ylm5Q0ckcFlXfN0EJ47rkjU++k/dbJ1/PYuzKre4eVoCGpodOu VB1S7ullSvOpFm29vX/i0m0sM2CAihOadXIT+xIrcROehnuXCLYpPf2QDyliGshoSrrk sfCy1qgHbypEEYILhDsA/cR92zsVr5biU4kv101EEon81S4DHvJ48S2cHFwVB8ObaE1D tTHo7InV9zRQ2FnmvSrNu5Xe8CWIcK0+xXU9TIg3e/96VqcY731ABPvhs6q1S6Q/FFMC Q0XQ== 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=Oz+gR5ZaJqyzXvto4nobi5lD/J9jrUp0NPZJ8hG60bE=; b=UnJdfRww5ktFtSX6x5XWiHR4dbeSqjrNGEDnbKs9LSMfo5QBjj3YCgDMrfU3oBiweC dZ2wqvvOqRJtlKzqvOsvkUgPfFrDyNQ2J8ImmVzqKrAzSqb+XOMgd3cpWGphote+1gFS exOUC5NCsFVJm7BPnC3kVPuZMoiQ32Gzuxs17mJlB9ZP8VQ8FVpUA4Tf5WO8UWylEy+v fWyftflkd5dOUmJwrnCYsTQ4fZuZ//9K5A7gowe8fACLVLuO6XKEHgM/LIwOdAB1iwfd RD9nDXiUIRSqRiAq0HDqvfOvrAuVkSr90jZlaWxWpvlPmi8HG7xQYrCiqhSXwPvRwTvt pERQ== X-Gm-Message-State: AOAM532GirVES2Jh2+lAJFP540LPJXpQkgBfCDFnRN1sPMWUVJyej6nS KQxlpfizZa1UrXhAaTOSv4yyVVunTcI= X-Google-Smtp-Source: ABdhPJzBc7MoVtjlB5MqSXURJqP9se5ixcI5Truyv/157bYNRQZSfeAkCvcja9D+G+pxb4RaDmedOA== X-Received: by 2002:adf:f60a:: with SMTP id t10mr18894684wrp.127.1626536512041; Sat, 17 Jul 2021 08:41:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id j16sm13475662wrw.62.2021.07.17.08.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:42 +0000 Subject: [PATCH 4/9] 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 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. No functional changes, just making it easier to verify that the codeflow matches our precedence rules. Signed-off-by: Elijah Newren --- builtin/pull.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index d9796604825..5c9cbea37c9 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1046,15 +1046,16 @@ 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(); + else + return run_merge(); } + /* 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; From patchwork Sat Jul 17 15:41:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383699 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 00A98C636C9 for ; Sat, 17 Jul 2021 15:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC8666115C for ; Sat, 17 Jul 2021 15:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235065AbhGQPo4 (ORCPT ); Sat, 17 Jul 2021 11:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235272AbhGQPov (ORCPT ); Sat, 17 Jul 2021 11:44:51 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32923C061762 for ; Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id n4so7592401wms.1 for ; Sat, 17 Jul 2021 08:41:54 -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=6nmzd1WY5d008MKBiZdP3xj2FvDspd9va7AIkNv7CdQ=; b=sF8BMJeExnLLLD5dTomTyIrYsFrnyDbsvKNwsuOn3fQWfvfyLae5pJbindXKrJcSg5 x7NIlpQ8Fcyy0LRxZphkHP4G+PY5hDfui8qqnNNPB2gzrXq1js0McXk/XGwQlKtpIQ9K 8NHAmkSOWQDNjll1jBOX8CKqoCwXMjehQV7vlVQNRpLmXFAZejtLIsV3kIj+/+jP0gxx HdLYQAmvoGig7AZms4oNOY7ULKC+0pQqRyK/kqcelscFVAKyxhFG3H3TRopinBs+cbpO wWzkYBD55eWtq5G26fJFVpCAPO/lHaCVsbnCRwc+8kv6/hyxu+/3aFX6I/ktt2EOSNbE OenA== 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=6nmzd1WY5d008MKBiZdP3xj2FvDspd9va7AIkNv7CdQ=; b=mmp+L+KuwWBDDm0kaCUtc6jVL/MkaOjpMrjlZXfUgA7bnRq7VIOatRfFBTD7M4ZunN YkOm9FB2/cyQ2YOkrJkvNI/i+1uMbZ2MEsfIoVG9kQWYgEmXTxFG6BZ4vUIKTupTqjR1 Ry2si/QwFtZLDYyBvTY8yVMgecM06m7jEFtpktgAiM9QnAyCcAnfPwl+l5JywZTN1F8+ cPKB/65iqllwOOf2/tiq7DzvhNdG7fXIKVaqDr9nz062ajxAwwX/ownMx+QKtgnl5ab+ rHY1FjCE9p0zGWORIU9jm/igXA0RlvHiFFvxRToiS8oBhhizlxp7m427lExis3djy0kp CLKg== X-Gm-Message-State: AOAM532im/RiY7cN3CBP1Q9T055P12V5K6N702VtO4T4uQ/Ch4WJCxFc Umkysbqj/g/HZvJDpwchQBqyNnBco/E= X-Google-Smtp-Source: ABdhPJw33BD0z9jJF8HAu7FybAVlGt0yZtxEvqCqcbSplae+72ZI1iUjIO6pIw8zs9IMzAyyQGcdwA== X-Received: by 2002:a05:600c:3786:: with SMTP id o6mr22976781wmr.155.1626536512806; Sat, 17 Jul 2021 08:41:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u2sm10934450wmc.42.2021.07.17.08.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:52 -0700 (PDT) Message-Id: <3d9ff69198e5a604b124bf861df4d6ecf6eb661e.1626536508.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:43 +0000 Subject: [PATCH 5/9] pull: ensure --rebase overrides ability to ff 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 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Now that the handling of fast-forward-only in combination with rebases has been moved before the merge-vs-rebase logic, we have an unnecessary special fast-forward case left within the rebase logic. Actually, more than unnecessary, it's actually a violation of the rules. As per https://lore.kernel.org/git/xmqqwnpqot4m.fsf@gitster.g/, --rebase is supposed to override all ff flags other than an explicit --ff-only. Ensure that it does so by removing the fast-forward special case that exists within the rebase logic. Signed-off-by: Elijah Newren --- builtin/pull.c | 8 +------- t/t5520-pull.sh | 6 +++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 5c9cbea37c9..5ba376a7487 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1070,13 +1070,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 Sat Jul 17 15:41:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383701 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 89AF6C636CB for ; Sat, 17 Jul 2021 15:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 771816115C for ; Sat, 17 Jul 2021 15:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235334AbhGQPo5 (ORCPT ); Sat, 17 Jul 2021 11:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235308AbhGQPow (ORCPT ); Sat, 17 Jul 2021 11:44:52 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9AA0C061766 for ; Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v5so15655003wrt.3 for ; Sat, 17 Jul 2021 08:41:54 -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=B3nermyozy4HDsTP/jJeyO4D9u7bViI0FyP3u3Sl+ac=; b=YuxmoTrRXIbaS39XQ6fv6LNJJuP56/L7+pd+6k/V/q2LwKKkjKWmrnqZrLwK5w4fkk pFYWqWkWg3O2PMxzockgqdOIp4yU+pEMdpXMXf6zzzN4BRrIrBkjBMAwo9ypNNW0jHjS /f7puYoEyFd7KTRa/TNLMQKqWgy6yPpNnvdWZ2EGY4dpyl+LG2ltzGm8L502ycl2AxEY 0cxFvsiZGhvaJ7Zv328q3kTonRiPOURC8zw+kd8Ykvrhuia126Dz+yu9wS0RcCFbQj3z XBjFS9QQPXR6FAia1bSg9WxYLsdu0wp4gR0EHZfbmVGkMlwUOKO8uILZ+EbofCSBU90h tzvg== 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=B3nermyozy4HDsTP/jJeyO4D9u7bViI0FyP3u3Sl+ac=; b=lD9oSJyJy5PDusSayHpYu3xkY1s0++ZSDL4Ce4XKitQ9jGxSkSCDKAboPkPrYeFQro 1/HF6/vdM7EYM7R3gMhBGehMobsiF1/56VZEKG28HpMzTXupsrUfYqC2FPSjBoekuj9n ygj+KiKBbTszJsU9xo+R5PWirYnZlgiE1rMEue44hpuoDRRH2LYFUfbcNoPVBHQgKipR CiiDP3MB67AZ68f+TEpOQoDGFZRFSwSsuTxu8p4eJmMd7wEHTViY1EClFC8IFveF9nvA cFY9xx45DNXQdK8EHg21RqR2BPBxOr8DDEXv0t/WsNm3uE2qvbkmmVh2IPCHoFsDL/7h /NMg== X-Gm-Message-State: AOAM532fiLVgvZa7e7IlpWqRWxqoWqMXD0pn6BW77jrQUXQU0VUHuAWl vXTWfxLe8G084nk3E+4ZQlB6lrxL4HM= X-Google-Smtp-Source: ABdhPJyTDO9vUIhU+E+jXhm5exIyIb6KvO+U6dRgT60AaqTqN3eVzG0yR21TPw4oQgG9Q+xBSEu+tg== X-Received: by 2002:a5d:420b:: with SMTP id n11mr19457350wrq.395.1626536513332; Sat, 17 Jul 2021 08:41:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m32sm13988502wms.23.2021.07.17.08.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:53 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:44 +0000 Subject: [PATCH 6/9] 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 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 | 5 ++++- t/t7601-merge-pull-config.sh | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 5ba376a7487..7e7c90f6a10 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -966,8 +966,11 @@ 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()); + 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 23a1fbc17b3..12787d07289 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -244,11 +244,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 overrides pull.ff=only' ' +test_expect_success '--no-rebase overrides pull.ff=only' ' test_does_need_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 Sat Jul 17 15:41:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383705 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 C0887C636C9 for ; Sat, 17 Jul 2021 15:42:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A717D61159 for ; Sat, 17 Jul 2021 15:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235364AbhGQPo6 (ORCPT ); Sat, 17 Jul 2021 11:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235361AbhGQPoz (ORCPT ); Sat, 17 Jul 2021 11:44:55 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD9EFC0613DC for ; Sat, 17 Jul 2021 08:41:55 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id r11so15607378wro.9 for ; Sat, 17 Jul 2021 08:41:55 -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=1wobEcbm+Jf9WybKWhfAfxo2HD5LrqQZ3DD9f05SbaE=; b=SooPPCdH1LEkdKQIhp7liA/onPw7Jjha55QDUU7wYZvrg2GCMKRu6QG58rvWim3k2H quWMYnOr0W0jie2TcgbE7grvJ1AmfODvnrGoFjLqYzBHgxuW1G+ZLZgcTEZ0GZDPJw/n F2jdQdHTQ439RJXOOo3yCvbh7s+oCb8cukgb9xktzFOJGf8aZQCIiwMLr3TIO9R3b1Pd Zoenv8zsSfuKpMTGGgrVogv1cm6OgHKuhnES4VulfWFkoV6BpDT6oLf/1c81HzLawH5c w/PVP19zme4Qxo91zRoISpAZaGn6c8XsA7qiV626fwie2RhsJc0AXnW/Hh3Hy41FSOzh FNmw== 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=1wobEcbm+Jf9WybKWhfAfxo2HD5LrqQZ3DD9f05SbaE=; b=B5Yf9a+zwIF9aGFgsC05o24pblrIXPrD5/HXsKoFnmWxleACH1O5quw1Ayhw4+BjZu P1yEPxc10OfLZwRnmSa8djngTX0y0WCdHP1x4ijxqMwd5+hhI1PU4hVHLU5m/oPpb3nQ yJcOQLsBamfOMwVAb3+Mwa68CCv87DC7Af2+W9zVPWHj7f0SZEKaJKqBL1wxPcxiE1+h yND1wjo8mEwKpN6BkfQyIxVgkOGfAWH39Gmu9uwqS296kSLply6C5w11MnrmDlrFifor 5DmoNNNkydm/T7R4+xf4C/1uxpRbvUeJoXh2Crr7HAGotTmPwaT4LS0LveK+RDEuG9xD 7bFA== X-Gm-Message-State: AOAM530+h8z0HPeFlID6L+BhRcUH+mizwKHTAS6YJnysZsNFOj2oSmDH jsCR7hZnIuxvSLC31AKUvTwLHIi93kY= X-Google-Smtp-Source: ABdhPJyPbf8zO+eawboL4nT/SjYp+IxImMWMYEVQiwJMTILEA0L3BHGDZFpBu/ZG9p7oq7ZbwvFDsA== X-Received: by 2002:adf:f60a:: with SMTP id t10mr18894799wrp.127.1626536514114; Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v21sm14505509wml.5.2021.07.17.08.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:53 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:45 +0000 Subject: [PATCH 7/9] 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 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 | 40 +++++++++++++++++------------------ t/t7603-merge-reduce-heads.sh | 2 +- 13 files changed, 80 insertions(+), 74 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 7e7c90f6a10..2d7f2d765ab 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" @@ -1057,8 +1057,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix) return run_merge(); } /* 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 425dad97d54..02a842697b8 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 && git ls-files -u B >b.stages && test_line_count = 3 b.stages && @@ -121,7 +121,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 && git ls-files -u B >b.stages && test_line_count = 3 b.stages && git ls-files -s N >n.stages && @@ -137,7 +137,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 && git ls-files -u B >b.stages && test_line_count = 3 b.stages && git ls-files -s N >n.stages && @@ -153,7 +153,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 && git ls-files -u A >a.stages && test_line_count = 1 a.stages && git ls-files -u B >b.stages && @@ -173,7 +173,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 ' @@ -183,7 +183,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 ' @@ -193,7 +193,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 ' @@ -220,7 +220,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 ' @@ -232,7 +232,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 12787d07289..673b92afbab 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() { 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 Sat Jul 17 15:41:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383703 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 27FF3C636CE for ; Sat, 17 Jul 2021 15:42:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09E816115C for ; Sat, 17 Jul 2021 15:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235389AbhGQPo5 (ORCPT ); Sat, 17 Jul 2021 11:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235363AbhGQPoz (ORCPT ); Sat, 17 Jul 2021 11:44:55 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2679BC0613DD for ; Sat, 17 Jul 2021 08:41:56 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id v5so15655056wrt.3 for ; Sat, 17 Jul 2021 08:41:56 -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=0pmhaTGW/c37alOWpa7m/pGWqT9mj8SFk5KGs1Vt7Ew=; b=m10jUUy4Hb9Q1otSIRuwkQF2jpps/ejlrkBW0/HES/4daxYbk74xvPZO7AebB5x3KI 4MEgzIy2gcdDi6BLeUQCEtomgwWpCAO1XmZkSJktNUcJKQTepz7TGz4h2sBS7lGQzcSP 5d1GbONUglIGGJ21icHvqm2JeYdqSP3hoppyMt00W2TRKfEqNezTvmL5fmZNA0fHJ7g2 QwKu5lMWDe6A/i70SHpVMFDoqBk/FK1EW+Fzo+V7niaiHpPjenJRtaMygGsEOi5LuyCZ VVuH8SvAFGk8XOM62DccsKZXNHFttW5OWPvjcMTj8kAk/8XF9vwvtJZzi/H87eQ5O+4Q wO8w== 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=0pmhaTGW/c37alOWpa7m/pGWqT9mj8SFk5KGs1Vt7Ew=; b=QOW3JsIObVa/zKV1xoIC1ZfXfVCn/6EDiWyCQlP1OB/iwUzOHS47Q6YWFeL9CsxQsu JOjZdTHC4NdNIc3WB+4uhS8jY9pJ08t/lz1VENq6i46Zpv4uD+ZKWMfJNA/OkAIcWn65 W/6938AQv8PUcAwoYhsHTT9SkkgcokO9L+cQlA9dlYrTKoWHZQT0wAG9pYQAdLOO4D2/ zMQNakUbjxuM1vL8eg3xSjzjRsX3z+Mb02/QvC/wYXrjP8JYav3HRrwqtbzBsKEOaAOm TXsrW41Ozuks8zV/UGz1h5urMCxQ+eW2XN6401U9BTkijJUT+I/fwWpfA+O1yhjAIbI8 eUxA== X-Gm-Message-State: AOAM532/nKVTD0NZloVlALphCm3aMqqWVLiGH1F5jX99UMUzeOBneNvM IcY1bs8nnGHRUNAAzoXzqIogmjCvzxA= X-Google-Smtp-Source: ABdhPJzn3fx9UK6cavtykUND6KnPZsWw1quliWaI7GgplbnhrpU+jDZBeigMKpgJf4/xefTIow67rw== X-Received: by 2002:a5d:400c:: with SMTP id n12mr19420064wrp.257.1626536514732; Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o19sm14247241wmc.12.2021.07.17.08.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:54 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:46 +0000 Subject: [PATCH 8/9] 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 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-pull.txt | 2 ++ Documentation/merge-options.txt | 25 +++++++++++++++++++++++++ builtin/pull.c | 2 ++ 3 files changed, 29 insertions(+) diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt index cad3f6bfcee..6e6e95a7595 100644 --- a/Documentation/git-pull.txt +++ b/Documentation/git-pull.txt @@ -125,6 +125,8 @@ When false, merge the current branch into the upstream branch. + When `interactive`, enable the interactive mode of rebase. + +Note that `--ff-only` takes precedence over any `--rebase` flag. ++ See `pull.rebase`, `branch..rebase` and `branch.autoSetupRebase` in linkgit:git-config[1] if you want to make `git pull` always use `--rebase` instead of merging. diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index eb0aabd396f..3b70abf3c87 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 @@ -58,6 +61,10 @@ could instead be resolved as a fast-forward. + 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. +ifdef::git-pull[] ++ +Note that `--no-ff` and `--ff` are ignored when rebasing is requested. +endif::git-pull[] -S[]:: --gpg-sign[=]:: @@ -73,6 +80,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 +112,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 +144,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 +187,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 2d7f2d765ab..3a61b92f328 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 Sat Jul 17 15:41:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12383707 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 763C9C636CB for ; Sat, 17 Jul 2021 15:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CF946115C for ; Sat, 17 Jul 2021 15:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235452AbhGQPpA (ORCPT ); Sat, 17 Jul 2021 11:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235411AbhGQPo4 (ORCPT ); Sat, 17 Jul 2021 11:44:56 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF25BC0613DE for ; Sat, 17 Jul 2021 08:41:56 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id f9so15601234wrq.11 for ; Sat, 17 Jul 2021 08:41:56 -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=7bvgnX1UOwK2YlUbgGPz6WdTxUzk++lvjU1X/6Tqioc=; b=Z8uAs249tzRejZgWmm2a7xCiPxVkqZoOcnhwNyMa5daLtfQnzqrYkBvIV9884WsZeJ uojEBC6WtjpYgxUHmuVKBXPZ9zBLYUL3P+xxsVYSzYb0Y8zaA4c4dr04bueOyXKBeAFa rU1gkllrwf9NT1NLOHJQnZaNmjrq18qiwYS+kv1zt7B3mZMKBlqsp78/CMUTdmBgJKgV /BmAPkco/4bKnrOJMnxUit12/NUpUvoFI/lLzHHBQJ2QApiPcYLyTdxO8UZHxmdsIogk sSNoK4/qQW1DIZBfnM2CjDXh30sW4egWfRVsJqG2eokIFzqjTlQ/nRIX42Lg7MO00AOs wP8g== 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=7bvgnX1UOwK2YlUbgGPz6WdTxUzk++lvjU1X/6Tqioc=; b=i03Q+CVceECLlFIzUKjZakTgvzown0NDeuAE+x7BaBtuFBcuXRUGWk3mZMQhkaww8v ry0Z/4ZvUJhGfRIT06e60WY8X1nCb4TQ/m2Zym54LSl+6hBQfxfBIoju7q1Nt2aFNiy7 oNRahNV6tbFaIQwTw1O886ubCIrjicklHnT39lFHi4UrIzfJJE5KvxYpXG36yAofKhJa hccawVmpud/Jp6xQyP2wlJ5sChCne2ZT7FsbUU3/57DL3vEzNaF8pLKVx1sMqEesUF6s RgrHAUFdFHQQjDiDF50+wrg/u+QGPO5CcI2O/G0nchaOCUBPJhMjQLirBWXHn9BclaEF ZU7w== X-Gm-Message-State: AOAM530xI660DdAOfF2D+J9Kk4XJDJBJNPSyrd7vhWk8VTb60kwZAm5o rxudAwZ0dniyax5xr4SHpaJKlpbijMY= X-Google-Smtp-Source: ABdhPJwf0H9h78n1cNxoxzr3CU3kR2Wi7bzN0MxyAYrWcWF9VrLE9hhCD60juUDkWT4tKeHGkOUI+w== X-Received: by 2002:adf:90e2:: with SMTP id i89mr20103163wri.338.1626536515352; Sat, 17 Jul 2021 08:41:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p4sm14211606wrt.23.2021.07.17.08.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jul 2021 08:41:55 -0700 (PDT) Message-Id: <3d8df24677269ddc379e0bfe5a6acc7f1dfd4fee.1626536508.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 17 Jul 2021 15:41:47 +0000 Subject: [PATCH 9/9] 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 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. Also, it seems wrong to have our can_ff computation return true, so fix that while we are at it too (we won't actually use the can_ff flag due to setting opt_ff to "--no-ff", but it's confusing to leave it as computed to be true). Signed-off-by: Elijah Newren --- builtin/pull.c | 20 ++++++++++++++++---- t/t7601-merge-pull-config.sh | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 3a61b92f328..beaf6ee0653 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); @@ -1046,10 +1052,16 @@ 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.")); + if (!opt_ff) + opt_ff = "--no-ff"; + } - 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 673b92afbab..29105b5b1ed 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -297,7 +297,7 @@ test_expect_success 'pull.rebase=true takes precedence over --ff' ' # End of precedence rules -test_expect_failure 'Multiple heads does not warn about fast forwarding' ' +test_expect_success 'Multiple heads does not warn about fast forwarding' ' git reset --hard c1 && git pull . c2 c3 2>err && test_i18ngrep ! "Pulling without specifying how to reconcile" err @@ -307,7 +307,7 @@ test_expect_success 'Cannot fast-forward with multiple heads' ' 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 "Not possible to fast-forward, aborting" err + test_i18ngrep "Cannot fast-forward to multiple branches" err ' test_expect_success 'Cannot rebase with multiple heads' '