From patchwork Sat Nov 14 00:34:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11905185 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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 8ABD4C55ABD for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 522892225E for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H8jOZtHr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726107AbgKNAet (ORCPT ); Fri, 13 Nov 2020 19:34:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbgKNAes (ORCPT ); Fri, 13 Nov 2020 19:34:48 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 749BDC0617A6 for ; Fri, 13 Nov 2020 16:34:48 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id c17so12082171wrc.11 for ; Fri, 13 Nov 2020 16:34:48 -0800 (PST) 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=UVeF//q+7/vEAexPlhXSoTaBVDx8d+zrKUSEMsoruVo=; b=H8jOZtHrtLCwV7XJ7l7xyyYqTTSk722zkFi0drKAuc7KGfH+UG4HiRXwlOh35WJ/8T QsyF9rgFF5I8w8sS4ShJnOGJvm9YQUcCB0sOwKR7J2Zxtzbcm7vSLzeCUbM6XpOTEYg6 CFqDZQE5c3AttbPX7EZL6iln114h1aXGKoYtxS/AyFJafcEl1juUTFoMSwVlnVlkzc2U wSSIovL1tTUQO7KMyBD4xhFW2babvcc/A4GNcpSPc73lHfzuwKfEC53YHqS8Tx4nWqtF VsqFYxXHx3nTfJDudojDQlFEom6l59kLYQyrFOFNuxvpIyfpnb/urEH99k/eYlh/c7Zl b6pg== 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=UVeF//q+7/vEAexPlhXSoTaBVDx8d+zrKUSEMsoruVo=; b=F1SVkIIl35l0nsHaIg8BYtD/W8XDY4fS/fPP7Tk0xgZUMsOVLcZPI/353adH30iNpf ajck2HBe81NlfvLplwVsC2D/Ll/Oy2E7YBBqMJprX2t9l5UZ2pFFEkB2W9juyQ7qzDPM ioNmBiqMRJx+wDoHyZ7pXlyoT2bSAivu2iC5aj/Wz384PKmyQfT90bOrDiPF2cAQXAjj R3AhfuRRU4aekaU6chkutssQJPyxHL4QzLlpWhg5VALVWehH63tk3lUq8vShfqQVbQXn aRUGJBFi+/izUmcIvsUVJOQJqlqU/O00ps6501ifyU7qIZVjBX63kHOdwcD8u9ARBzf5 iaXw== X-Gm-Message-State: AOAM533GfphEyvfTnvCbXN+TManWAuSuuySGIdZ6Qws19o2r+QSKcrSz bC5S6FUCPutRAnu8tYOFlZdm6K0Y68I= X-Google-Smtp-Source: ABdhPJxQA2etciXDKPRbJnTe7UsA6EM6lZJLP13CuUndyuJPTyDCeAw4Qq2iGlF28W9mCKDZHzATFA== X-Received: by 2002:a5d:6751:: with SMTP id l17mr6616076wrw.109.1605314087051; Fri, 13 Nov 2020 16:34:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a15sm13031918wrn.75.2020.11.13.16.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 16:34:46 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 14 Nov 2020 00:34:42 +0000 Subject: [PATCH 1/4] pull --rebase: compute rebase arguments in separate function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Stefan Beller , Brandon Williams , Brice Goglin , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain The function 'run_rebase' is responsible for constructing the command line to be passed to 'git rebase'. This includes both forwarding pass-through options given to 'git pull' as well computing the and arguments to 'git rebase'. A following commit will need to access the argument in 'cmd_pull' to fix a bug with 'git pull --rebase --recurse-submodules'. In order to do so, refactor the code so that the and commits are computed in a new, separate function, 'get_rebase_newbase_and_upstream'. Signed-off-by: Philippe Blain --- builtin/pull.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/builtin/pull.c b/builtin/pull.c index 17aa63cd35..ac6ef650ab 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -852,21 +852,42 @@ static int get_octopus_merge_base(struct object_id *merge_base, /** * Given the current HEAD oid, the merge head returned from git-fetch and the - * fork point calculated by get_rebase_fork_point(), runs git-rebase with the - * appropriate arguments and returns its exit status. + * fork point calculated by get_rebase_fork_point(), compute the and + * arguments to use for the upcoming git-rebase invocation. */ -static int run_rebase(const struct object_id *curr_head, +static int get_rebase_newbase_and_upstream(struct object_id *newbase, + struct object_id *upstream, + const struct object_id *curr_head, const struct object_id *merge_head, const struct object_id *fork_point) { - int ret; struct object_id oct_merge_base; - struct strvec args = STRVEC_INIT; if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point)) if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point)) fork_point = NULL; + if (fork_point && !is_null_oid(fork_point)) + oidcpy(upstream, fork_point); + else + oidcpy(upstream, merge_head); + + oidcpy(newbase, merge_head); + + return 0; +} + +/** + * Given the and calculated by + * get_rebase_newbase_and_upstream(), runs git-rebase with the + * appropriate arguments and returns its exit status. + */ +static int run_rebase(const struct object_id *newbase, + const struct object_id *upstream) +{ + int ret; + struct strvec args = STRVEC_INIT; + strvec_push(&args, "rebase"); /* Shared options */ @@ -894,12 +915,9 @@ static int run_rebase(const struct object_id *curr_head, warning(_("ignoring --verify-signatures for rebase")); strvec_push(&args, "--onto"); - strvec_push(&args, oid_to_hex(merge_head)); + strvec_push(&args, oid_to_hex(newbase)); - if (fork_point && !is_null_oid(fork_point)) - strvec_push(&args, oid_to_hex(fork_point)); - else - strvec_push(&args, oid_to_hex(merge_head)); + strvec_push(&args, oid_to_hex(upstream)); ret = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); @@ -1011,6 +1029,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if (opt_rebase) { int ret = 0; int ran_ff = 0; + + struct object_id newbase; + struct object_id upstream; + get_rebase_newbase_and_upstream(&newbase, &upstream, &curr_head, + merge_heads.oid, &rebase_fork_point); + if ((recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) @@ -1034,7 +1058,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) free_commit_list(list); } if (!ran_ff) - ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point); + ret = run_rebase(&newbase, &upstream); if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) From patchwork Sat Nov 14 00:34:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11905191 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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 B3B4FC63699 for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75D2F22267 for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gV24JFhC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726156AbgKNAet (ORCPT ); Fri, 13 Nov 2020 19:34:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726113AbgKNAet (ORCPT ); Fri, 13 Nov 2020 19:34:49 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0EEC0617A6 for ; Fri, 13 Nov 2020 16:34:49 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id k2so12158487wrx.2 for ; Fri, 13 Nov 2020 16:34:49 -0800 (PST) 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=gWDz9/SWZ7N7h4GNphEYMJIZWtymw4ByXjkmREoQWWo=; b=gV24JFhCE8xRJihBdBiJst9DvGtWod1UFh9xrOswBco3SuEB/mX2S6vuAwVhb64kli GOIHqPOss6d0X5j7fk11WopX0rHJR4LWOBfrjMXOoJUnEHEzsFsTljvv9Z6EaBJNuyls j04lbWshhVFABDWPJEnfNcWap9r63wN+vgsEXWoMAl0RdWDYbQmfhe2020hgtZbWKLwC +SFrxWpVwS26/r2s4cNe/kdxxfeQtLB853Bvns3GrczlqcJFPMSF6+pWMwC8iumkRbJE BG7f9ajbdgYLqWvzhGuDtlc3TvmVcRaNbY98eyziSexiHvdjJ0zOeFepwrVqf2yU9E8c qtTQ== 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=gWDz9/SWZ7N7h4GNphEYMJIZWtymw4ByXjkmREoQWWo=; b=fIGyjO4NjZL7iEwkK1LNOGJ8m+s/r8ev2Heg4beVYG+8RDp6Jptbtybks5eBZuu3Qs dYDv5+VLBRo3Z+4xEOHtUaJ+9cYIMxa43d7MzVkKh1RPgaEVq7BKxPGFVXIgsRkHbj5g gWPUxX6mUWGGtt3Ga4V9x6wSZ9W54obAtSUu7QYdFD1nU7wT7OYkMMYMwUEkBqZl7heT +rDcQ7mjHc3cz5rgHBAh/OPMCe+CC/oU/P0LZ0D8dAcyN0nVnaf761NjWmycyYVni3Sr KPgwIOeffk1r4FPjDuFzGfH/2z1F/hgNL0HI38kzfszb8QxaVp8tCFJ61w2CpbkimEDj hV5w== X-Gm-Message-State: AOAM533KlunyLM9V2CTUdwmpcJFN8SWi9hxe84KQIApJkoE7uCvsAJ+q vH+DE7Rk5559Idi6kXB/tbM7ZYJ7jko= X-Google-Smtp-Source: ABdhPJwLCC/OIzbh8fBZradce00tJf6voAbfiShyGOE92u7FbGrovJwLOY+Reo3wXiKADSXSr9sX7w== X-Received: by 2002:a5d:4e07:: with SMTP id p7mr6540479wrt.63.1605314087808; Fri, 13 Nov 2020 16:34:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 89sm13046586wrp.58.2020.11.13.16.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 16:34:47 -0800 (PST) Message-Id: <85c5766556e53f780b9a3ac677a0c758c51baae2.1605314085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 14 Nov 2020 00:34:43 +0000 Subject: [PATCH 2/4] t5572: add notes on a peculiar test Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Stefan Beller , Brandon Williams , Brice Goglin , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Test 5572.63 ("branch has no merge base with remote-tracking counterpart") was introduced in 4d36f88be7 (submodule: do not pass null OID to setup_revisions, 2018-05-24), as a regression test for the bug this commit was fixing (preventing a 'fatal: bad object' error when the current branch and the remote-tracking branch we are pulling have no merge-base). However, the commit message for 4d36f88be7 does not describe in which real-life situation this bug was encountered. The brief discussion on the mailing list [1] does not either. The regression test is not really representative of a real-life scenario: both the local repository and its upstream have only a single commit, and the "no merge-base" scenario is simulated by recreating this root commit in the local repository using 'git commit-tree' before calling 'git pull --rebase --recurse-submodules'. The rebase succeeds and results in the local branch being reset to the same root commit as the upstream branch. The fix in 4d36f88be7 modifies 'submodule.c::submodule_touches_in_range' so that if 'excl_oid' is null, which is the case when the 'git merge-base --fork-point' invocation in 'builtin/pull.c::get_rebase_fork_point' errors (no fork-point), then instead of 'incl_oid --not excl_oid' being passed to setup_revisions, only 'incl_oid' is passed, and 'submodule_touches_in_range' examines 'incl_oid' and all its ancestors to verify that they do not touch the submodule. In test 5572.63, the recreated lone root commit in the local repository is thus the only commit being examined by 'submodule_touches_in_range', and this commit *adds* the submodule. However, 'submodule_touches_in_range' *succeeds* because 'combine-diff.c::diff_tree_combined' (see the backtrace below) returns early since this commit is the root commit and has no parents. #0 diff_tree_combined at combine-diff.c:1494 #1 0x0000000100150cbe in diff_tree_combined_merge at combine-diff.c:1649 #2 0x00000001002c7147 in collect_changed_submodules at submodule.c:869 #3 0x00000001002c7d6f in submodule_touches_in_range at submodule.c:1268 #4 0x00000001000ad58b in cmd_pull at builtin/pull.c:1040 In light of all this, add a note in t5572 documenting this peculiar test. [1] https://lore.kernel.org/git/20180524204729.19896-1-jonathantanmy@google.com/t/#u Signed-off-by: Philippe Blain --- t/t5572-pull-submodule.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index 1d75e3b12b..7f658dba6d 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -136,6 +136,21 @@ test_expect_success 'pull rebase recursing fails with conflicts' ' test_i18ngrep "locally recorded submodule modifications" err ' +# NOTE: +# +# This test is particular because there is only a single commit in the upstream superproject +# 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject +# ('child') hard-resets its branch to a new root commit with the same tree as the one +# from the upstream superproject, so that its branch has no merge-base with its +# remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'. +# The result is that the local branch is reset to the remote-tracking branch (as it was +# originally before the hard-reset). + +# The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and +# passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit, +# which adds the submodule. +# However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule) +# because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents. test_expect_success 'branch has no merge base with remote-tracking counterpart' ' rm -rf parent child && From patchwork Sat Nov 14 00:34:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11905187 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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 F3FEAC6369E for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C337222267 for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qgMLZzXd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbgKNAew (ORCPT ); Fri, 13 Nov 2020 19:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbgKNAeu (ORCPT ); Fri, 13 Nov 2020 19:34:50 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDCEFC0613D1 for ; Fri, 13 Nov 2020 16:34:49 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id w24so13536689wmi.0 for ; Fri, 13 Nov 2020 16:34:49 -0800 (PST) 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=tli/2DVPWhBZTlOxbzWYQvd2w5EWfJsrm0epbkKGYY4=; b=qgMLZzXdbiQiq2YcgKN9hE3+1czr/OFtlwQIBUnrECFLEwzW4gCXFFP9IMubpR2Ov/ EziAy3qOAXnveqHpPehN5yIavzo9fCkE+Wf+RFmgVpLioMO2hYQrNbN5IuF5rJHIhe3X 2fazC6hMkabUF8nzN7NnaK2X98QqxCPCMzOYEXggWGU5ejN3NPK2PRnsTtF2P2reVj8m xrOOV7R8jBa4oAIfA1laV13mXAVg4hROjiPs8V7ofdNVf3eWYVkFBoZmaebLaI0rcaxy I4POEVRW2mrz3ynIbgdScq5jjQQY9fLDsYJZERjx00t51HRNy6tGdw71VOuUGZagQ5N2 Sagg== 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=tli/2DVPWhBZTlOxbzWYQvd2w5EWfJsrm0epbkKGYY4=; b=jylmrRmp4ntyYye4I6VTmBxMZ1NFt1vmupMr7chPh5MXS6SHeShJd+1GqsT5CakEAR 0C7WMI78ktjUx1JQy+uVI002xi1ltu4bhUdmlB6tfJIbyuW+sgLAJEWa1hTcBYoK5olW TJCFfjWLqwOAXtseqMR0OpqUK3yG9bm97MhL6XtFNdCLFk99fLflvR8ziuV0dl5oU99f kLH8qiC90PGUwe2Ojf5VIAyLCM/Y4c14Db8Hrn3YlaGBfjl2QbW3RVI0LmGBPY8jtNxd BRhIvVGHENejjY22y0l9D8v6I3agbj61Mj3LGPkYTCxE5jX9qx9lumOl5c1doBbKx7VJ Mw0Q== X-Gm-Message-State: AOAM5326TllOxPsDU9vmgol18Et9keskgsq3GYS7JE+5bGHnWbIqO7Zi xrhtfet5KPY8Olw9mJN2FoPMNyFDwQE= X-Google-Smtp-Source: ABdhPJyQVJzCyJwCcqMMAzXnWYSW4I4O/fT3Mqpl9Sj+g1mRLlDJGhaIA7KqoQk/b4I9uhbjjdAKRg== X-Received: by 2002:a1c:7d03:: with SMTP id y3mr4974827wmc.58.1605314088506; Fri, 13 Nov 2020 16:34:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 71sm13457195wrm.20.2020.11.13.16.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 16:34:48 -0800 (PST) Message-Id: <4a124031400c38d7b44298a3328e4e81d756b637.1605314085.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 14 Nov 2020 00:34:44 +0000 Subject: [PATCH 3/4] t5572: describe '--rebase' tests a little more Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Stefan Beller , Brandon Williams , Brice Goglin , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain It can be hard at first glance to distinguish what is different between the two tests 'recursive rebasing pull' and 'pull rebase recursing fails with conflicts' in 't5572-pull-submodule.sh', and to understand how they relate to the scenarios described in a6d7eb2c7a (pull: optionally rebase submodules (remote submodule changes only), 2017-06-23), which implemented '--recurse-submodules' for 'git pull' and added these tests. Rename the tests to be more descriptive and add some bullet points comments describing the different scenarios. Signed-off-by: Philippe Blain --- t/t5572-pull-submodule.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index 7f658dba6d..7d9e12df4d 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -101,7 +101,12 @@ test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' test_path_is_file super/sub/merge_strategy_4.t ' -test_expect_success 'recursive rebasing pull' ' +test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' + # This tests the following scenario : + # - local submodule has new commits + # - local superproject does not have new commits + # - upstream superproject has new commits that change the submodule pointer + # change upstream test_commit -C child rebase_strategy && git -C parent submodule update --remote && @@ -116,7 +121,10 @@ test_expect_success 'recursive rebasing pull' ' test_path_is_file super/sub/local_stuff.t ' -test_expect_success 'pull rebase recursing fails with conflicts' ' +test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' ' + # This tests the following scenario : + # - local superproject has new commits that change the submodule pointer + # - upstream superproject has new commits that change the submodule pointer # local changes in submodule recorded in superproject: test_commit -C super/sub local_stuff_2 && From patchwork Sat Nov 14 00:34:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 11905189 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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 26FA4C63798 for ; Sat, 14 Nov 2020 00:35:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E95372225E for ; Sat, 14 Nov 2020 00:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q71fw6wZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726189AbgKNAew (ORCPT ); Fri, 13 Nov 2020 19:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726181AbgKNAew (ORCPT ); Fri, 13 Nov 2020 19:34:52 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2470C0613D1 for ; Fri, 13 Nov 2020 16:34:51 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id a3so13506906wmb.5 for ; Fri, 13 Nov 2020 16:34:51 -0800 (PST) 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=y+2H8e0PGgPoV+ewCQtlbWHgAxojGisT2unNKis/JvU=; b=q71fw6wZOsJ8BX7U92KBNeSfcLfnwN9BrBR+XTzHGa9+aTYP65+Wcd8y+S+TtUkHmz 2+Dau4dZCmRwwryIurIV6p/vBbmVgiwOtDZ2Sfz6keEq7jxNlyyeefDhFEE7fItgDi9j MRnh8HLZgL1eWPG54Qr9LE11b0KNquMxkouFSIllvAHYbM/rjy+/WIHZ5aurD/CbjlRE zXl7zVL+RCqw16imnqKq/4PxEVjHzXSlBldXS5Km9m7LRmbBWV2xpwJC/diK3KkhOcM3 O95YuBkW+EAyKPMTL5kH9PySSObkY/U09FievY4OV0+TWvoGbntwuyY4EcaTQkZAk9za MseQ== 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=y+2H8e0PGgPoV+ewCQtlbWHgAxojGisT2unNKis/JvU=; b=mRZA/HkO2ex/YLzh6LedPYq0xUMX7xbHW2buvUr/69b6mBrrRzx/cjZfq4chV65c3B tRICRy8zf/T3Y5YTjpWafCNfjopLZHjlMt2VHvjo0YU3m3NDRZ84DE0oFUvM57/wppFP Ejww+uwrtyei+7rjQaKsN//l4GvVkxC4zF5VyI80Ss/VhsltF7+2UXuyh21/++LWpAFd z5eCojCKlKIGAY3DhB8KXJfuY0QB66zoRIZWz7rKLLTRo44Yfa88gGmM4zTmkJM6ow60 rBAnnbMk/bElENOLZLu6HuDoQorN7IaZstBbSIk8JjpUbKXGawHuw8n0SO8q2tF0XEt4 AmcQ== X-Gm-Message-State: AOAM532/Qfu4P562b3ZKD82XOqtVP3daj08hT0Qm7veNm0jhxmDGHmAy ZJ6Dc5Ov3VFIRo1zI/CoFxHJnmAq0XE= X-Google-Smtp-Source: ABdhPJw0XDop72BXtbNEzC68qPR3VLN7YTOS//I/eeYMMlFbSk9cs1EVYDSTx7br4p0ZFSaL84W56A== X-Received: by 2002:a1c:3d44:: with SMTP id k65mr4633330wma.147.1605314089295; Fri, 13 Nov 2020 16:34:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y16sm12396020wrt.25.2020.11.13.16.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 16:34:48 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 14 Nov 2020 00:34:45 +0000 Subject: [PATCH 4/4] pull: check for local submodule modifications with the right range Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Tan , Stefan Beller , Brandon Williams , Brice Goglin , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Ever since 'git pull' learned '--recurse-submodules' in a6d7eb2c7a (pull: optionally rebase submodules (remote submodule changes only), 2017-06-23), we check if there are local submodule modifications by checking the revision range 'curr_head --not rebase_fork_point'. The goal of this check is to abort the pull if there are submodule modifications in the local commits being rebased, since this scenario is not supported. However, the actual range of commits being rebased is not 'rebase_fork_point..curr_head', as the logic in 'get_rebase_newbase_and_upstream' reveals, it is 'upstream..curr_head'. If the 'git merge-base --fork-point' invocation in 'get_rebase_fork_point' fails to find a fork point between the current branch and the remote-tracking branch we are pulling from, 'rebase_fork_point' is null and since 4d36f88be7 (submodule: do not pass null OID to setup_revisions, 2018-05-24), 'submodule_touches_in_range' checks 'curr_head' and all its ancestors for submodule modifications. Since it is highly likely that there are submodule modifications in this range (which is in effect the whole history of the current branch), this prevents 'git pull --rebase --recurse-submodules' from succeeding if no fork point exists between the current branch and the remote-tracking branch being pulled. This can happen, for example, when the current branch was forked from a commit which was never recorded in the reflog of the remote-tracking branch we are pulling, as the last two paragraphs of the "Discussion on fork-point mode" section in git-merge-base(1) explain. Fix this bug by passing 'upstream' instead of 'rebase_fork_point' as the 'excl_oid' argument to 'submodule_touches_in_range'. Reported-by: Brice Goglin Signed-off-by: Philippe Blain --- builtin/pull.c | 2 +- t/t5572-pull-submodule.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin/pull.c b/builtin/pull.c index ac6ef650ab..b7c87b87ea 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -1037,7 +1037,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) if ((recurse_submodules == RECURSE_SUBMODULES_ON || recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && - submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) + submodule_touches_in_range(the_repository, &upstream, &curr_head)) die(_("cannot rebase with locally recorded submodule modifications")); if (!autostash) { struct commit_list *list = NULL; diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index 7d9e12df4d..37fd06b0be 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -144,6 +144,35 @@ test_expect_success 'pull --rebase --recurse-submodules fails if both sides reco test_i18ngrep "locally recorded submodule modifications" err ' +test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' ' + # This tests the following scenario : + # - local submodule does not have new commits + # - local superproject has new commits that *do not* change the submodule pointer + # - upstream superproject has new commits that *do not* change the submodule pointer + # - local superproject branch has no fork-point with its remote-tracking counter-part + + # create upstream superproject + test_create_repo submodule && + test_commit -C submodule first_in_sub && + + test_create_repo superprojet && + test_commit -C superprojet first_in_super && + git -C superprojet submodule add ../submodule && + git -C superprojet commit -m "add submodule" && + test_commit -C superprojet third_in_super && + + # clone superproject + git clone --recurse-submodules superprojet superclone && + + # add commits upstream + test_commit -C superprojet fourth_in_super && + + # create topic branch in clone, not based on any remote-tracking branch + git -C superclone checkout -b feat HEAD~1 && + test_commit -C superclone first_on_feat && + git -C superclone pull --rebase --recurse-submodules origin master +' + # NOTE: # # This test is particular because there is only a single commit in the upstream superproject