From patchwork Tue Jul 12 13:06:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12914963 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63EDAC433EF for ; Tue, 12 Jul 2022 13:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232750AbiGLNHO (ORCPT ); Tue, 12 Jul 2022 09:07:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiGLNHM (ORCPT ); Tue, 12 Jul 2022 09:07:12 -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 AA673B4BD2 for ; Tue, 12 Jul 2022 06:07:11 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id c131-20020a1c3589000000b003a2cc290135so5178400wma.2 for ; Tue, 12 Jul 2022 06:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=B2UUSkn8ScIFAe2WU+SPqQszPoZhEEitNoSzZ6/SYFg=; b=MmIvAlYsGbE5o2HWWSVsSpILrra1q+bVzO90inbqf0e3luVYilOlo4bcAoEHh08XZN AYMgRf3G7GhrNUHSSSzwCIL7UCTvfP1TK7eFnxR/zIKINxf1cXCpBYZZRG1GrDAnBDid WHeT/14UKtjaAL0FQzdTSFcyW19K9w1Dc1FKswpimeRnfwF/pZ18GjBjAgjhrBFs+4NU Aruzf22xRbTXl5w+OFvx0TxG0ZRi5WQAZQKKHiG9q6iiiMr4WENwO5TdXslitAQ6wpwu wDfunlY5dwTa7AbcO9lzXvX1id738XpxjgBXNnv97GRHya5pJrrbMywhyCVYgocWRzGF /51w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=B2UUSkn8ScIFAe2WU+SPqQszPoZhEEitNoSzZ6/SYFg=; b=6wharE3f1uGSPj4NJYHsodKjn6c8HjEaFr/YES/1yDEKHkL8VEgcg3PhuzPB2jp737 9dlZIQgYsym82eGtXROL7989gks0jgAiS5/49YWWNw62bGCe9nBGkhkSN3rfJQzMU43w O32ZhOl4OBiQxxL6zrqjxtrZSydS77KghrnwRcxgP8dS0KTqEUAe+ihHUE5s85BUMxHR /wm3mrk3uQJGbB295kpOGs9WwLqzU1ENkIsRtizM2r1XIYJVuFT/IpWu9H1RBZ5SJ+km i09I8C+qDERasq14ThXWkG31VRlFHGaWUkluXL4W4tFHcNVBOjH1jvUaArRMO8istbnC 4PDQ== X-Gm-Message-State: AJIora9HUjkleSyNxrekVVWAyK3+vLejxBPoBs3qknaU5cfVqrl2wQQA En43qSN5rYyAiMpRM6BUDFBxN99FhCA= X-Google-Smtp-Source: AGRyM1ug4IKWAUGndOLKJ/iIXg/HE3mmTiOlHfnJp0b01DEG+DR2VjR8K4ZwzerGsKGCAyZ30Or1rg== X-Received: by 2002:a05:600c:34c9:b0:3a0:5072:9abe with SMTP id d9-20020a05600c34c900b003a050729abemr3722538wmq.8.1657631229932; Tue, 12 Jul 2022 06:07:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ay38-20020a05600c1e2600b003a2cf1ba9e2sm9865084wmb.6.2022.07.12.06.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:07:08 -0700 (PDT) Message-Id: <9e53a27017ac18eefef2c077a905efecab07861d.1657631226.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 12 Jul 2022 13:06:54 +0000 Subject: [PATCH v4 01/12] t2407: test bisect and rebase as black-boxes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, me@ttaylorr.com, Jeff Hostetler , Phillip Wood , Elijah Newren , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The tests added by d2ba271aad0 (branch: check for bisects and rebases, 2022-06-14) modified hidden state to verify the branch_checked_out() helper. While this indeed checks that the method implementation is _as designed_, it doesn't show that it is _correct_. Specifically, if 'git bisect' or 'git rebase' change their back-end for preserving refs, then these tests do not demonstrate that drift as a bug in branch_checked_out(). Modify the tests in t2407 to actually rely on a paused bisect or rebase. This requires adding the !SANITIZE_LEAK prereq for tests using those builtins. The logic is still tested for leaks in the final test which does set up that back-end directly for an error state that should not be possible using Git commands. Reported-by: Junio C Hamano Signed-off-by: Derrick Stolee --- t/t2407-worktree-heads.sh | 57 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh index b6be42f74a2..100ab286d5c 100755 --- a/t/t2407-worktree-heads.sh +++ b/t/t2407-worktree-heads.sh @@ -7,13 +7,18 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success 'setup' ' test_commit init && - git branch -f fake-1 && - git branch -f fake-2 && for i in 1 2 3 4 do + git checkout -b conflict-$i && + echo "not I" >$i.t && + git add $i.t && + git commit -m "will conflict" && + + git checkout - && test_commit $i && git branch wt-$i && + git branch fake-$i && git worktree add wt-$i wt-$i || return 1 done && @@ -44,26 +49,26 @@ test_expect_success 'refuse to overwrite: checked out in worktree' ' done ' -test_expect_success 'refuse to overwrite: worktree in bisect' ' - test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* && +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' ' + test_when_finished git -C wt-4 bisect reset && - touch .git/worktrees/wt-4/BISECT_LOG && - echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START && + # Set up a bisect so HEAD no longer points to wt-4. + git -C wt-4 bisect start && + git -C wt-4 bisect bad wt-4 && + git -C wt-4 bisect good wt-1 && - test_must_fail git branch -f fake-2 HEAD 2>err && - grep "cannot force update the branch '\''fake-2'\'' checked out at.*wt-4" err + test_must_fail git branch -f wt-4 HEAD 2>err && + grep "cannot force update the branch '\''wt-4'\'' checked out at.*wt-4" err ' -test_expect_success 'refuse to overwrite: worktree in rebase' ' - test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge && +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase' ' + test_when_finished git -C wt-2 rebase --abort && - mkdir -p .git/worktrees/wt-3/rebase-merge && - touch .git/worktrees/wt-3/rebase-merge/interactive && - echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name && - echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto && + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-2 rebase conflict-2 && - test_must_fail git branch -f fake-1 HEAD 2>err && - grep "cannot force update the branch '\''fake-1'\'' checked out at.*wt-3" err + test_must_fail git branch -f wt-2 HEAD 2>err && + grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err ' test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' ' @@ -77,24 +82,24 @@ test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' ' ' test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' ' - test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* && + test_when_finished git -C wt-4 bisect reset && - touch .git/worktrees/wt-4/BISECT_LOG && - echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START && + # Set up a bisect so HEAD no longer points to wt-4. + git -C wt-4 bisect start && + git -C wt-4 bisect bad wt-4 && + git -C wt-4 bisect good wt-1 && - test_must_fail git fetch server +refs/heads/fake-2:refs/heads/fake-2 2>err && + test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err && grep "refusing to fetch into branch" err ' test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' ' - test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge && + test_when_finished git -C wt-3 rebase --abort && - mkdir -p .git/worktrees/wt-4/rebase-merge && - touch .git/worktrees/wt-4/rebase-merge/interactive && - echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/head-name && - echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/onto && + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-3 rebase conflict-3 && - test_must_fail git fetch server +refs/heads/fake-1:refs/heads/fake-1 2>err && + test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && grep "refusing to fetch into branch" err ' From patchwork Tue Jul 12 13:06:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12914965 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C33D7C433EF for ; Tue, 12 Jul 2022 13:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232756AbiGLNHQ (ORCPT ); Tue, 12 Jul 2022 09:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbiGLNHO (ORCPT ); Tue, 12 Jul 2022 09:07:14 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8A2B41BB for ; Tue, 12 Jul 2022 06:07:13 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r10so4938305wrv.4 for ; Tue, 12 Jul 2022 06:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2uRRWueLbS1MmS8wlJxUl94o4kalllPCtK153o7kM6c=; b=OZpEKTbTmHhiJs3e/4Wb8pw3/reHslTgjO6Ll8wtm2w41gILvxfcCxZl9vwm9gCEor Ap3/iuaam9x1S2haFwYuE8Rv5Th5DOk6Bz50Rr7ja1GEtbPq3kwCyE1AC8tGZ27mFRBL z4t4vfzJnwlMNv/YtqWpnKwpT886cJrtbBLjluMdm2mMhHYTQV8mXhWUwgnNutkCZwF0 7k5lj2yEr91gI+UUbZkSLhPq6VCAMWYeloZEyYUjKE3Nh6afcl8ANddlz6T6gUGyBL5v LyX7zPm/z5+p6yXw52Y0YjKW+O2fr4DV8c7J4lXFmw03SbtwlKieF6cEQn78PbogLlyb B4oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2uRRWueLbS1MmS8wlJxUl94o4kalllPCtK153o7kM6c=; b=H7ViyeQbFHV0Cn8F/zPOWMTFBKq0cQSJRVoEy4KisC1cIzvG4XemuSH3jEv3QF4yc1 w3wLbyO8L+ScuEoqcLliJdhZD8NTcKuYorXdADQ7msrB1VAMutaLD50jURNy2uCo6124 KO861HwC9KEt0pAcFt5CkgVbWb6e13DIKegvAEnFxPqzeb+W+1tk5Bw73Y0PaN9weDgY U8/9H1yBoSi9FLgP/NESmQ/ZYZScNg8rYBTcJAf31uCUpnM2ppLMZNG7S8fXZgaTW9v+ DX71zGN6f2t2yVt/JS9NcNSI74W2I30/tz7gYbul7dAA7P+/1gwjrpEEaU2g6KM9JL8t DQ+g== X-Gm-Message-State: AJIora+pvJzM0tV/tw6KpcB5oFDkGj88r1IXo1NtwBRbAN5FizsYUmhB glZs+1QKeQ4gaUEVGnn9BIKdnx43Rf8= X-Google-Smtp-Source: AGRyM1ulUpPGmPHktoDO0acf9avutGvulSbf6ZXiA76fj14Ncii7d0lVZYctmabcG63d6fvVjRhx7g== X-Received: by 2002:a05:6000:88:b0:21d:691c:38d5 with SMTP id m8-20020a056000008800b0021d691c38d5mr22297205wrx.450.1657631231470; Tue, 12 Jul 2022 06:07:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n33-20020a05600c3ba100b0039c5cecf206sm9521566wms.4.2022.07.12.06.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:07:10 -0700 (PDT) Message-Id: <540a3be256f8a0ca57ae0ed90cc04190a28e91e1.1657631226.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 12 Jul 2022 13:06:55 +0000 Subject: [PATCH v4 02/12] t2407: test branches currently using apply backend Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, me@ttaylorr.com, Jeff Hostetler , Phillip Wood , Elijah Newren , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The tests in t2407 that verify the branch_checked_out() helper in the case of bisects and rebases were added by 9347303db89 (branch: check for bisects and rebases, 2022-06-08). However, that commit failed to check for rebases that are using the 'apply' backend. Add a test that checks the apply backend. The implementation was already correct here, but it is good to have regression tests before modifying the implementation further. Signed-off-by: Derrick Stolee --- t/t2407-worktree-heads.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh index 100ab286d5c..a67ce5fb003 100755 --- a/t/t2407-worktree-heads.sh +++ b/t/t2407-worktree-heads.sh @@ -61,7 +61,17 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' ' grep "cannot force update the branch '\''wt-4'\'' checked out at.*wt-4" err ' -test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase' ' +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (apply)' ' + test_when_finished git -C wt-2 rebase --abort && + + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-2 rebase --apply conflict-2 && + + test_must_fail git branch -f wt-2 HEAD 2>err && + grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (merge)' ' test_when_finished git -C wt-2 rebase --abort && # This will fail part-way through due to a conflict. From patchwork Tue Jul 12 13:06:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12914966 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 350D9C433EF for ; Tue, 12 Jul 2022 13:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232902AbiGLNH3 (ORCPT ); Tue, 12 Jul 2022 09:07:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbiGLNHS (ORCPT ); Tue, 12 Jul 2022 09:07:18 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0896DB4BF4 for ; Tue, 12 Jul 2022 06:07:16 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id a5so11084715wrx.12 for ; Tue, 12 Jul 2022 06:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ePxEjCpSua6fj5aJ+IohmoUGT5bMYR8zBPzmWNl+6xg=; b=Xop0+beg+wqZ+ydJ545oDBal2z/le/onh47P20ObfekJpKfUo/JUHW3sxUmUbk8q+k mTLnqHJ32lFsRnbyshhVp1u3J1yfaIMgXBVydwGdP+kFNRo9V7fhzTIn02MW7xs+HgJL FnCXOjAi30rk/9qxcetnJclLE9VCoTD89xMN6otKjhzGIMYfqrYv4HvSjl5hm01MaPZJ 50Nm18dhI5VtzkAJ7RMsWhTUiLTjZPxOR+IQ6cD91OGKFGMbXfij4gV0GQEQbHLSi73O /KeYXB+71M/wFKR5eMLVKtWnJWyOWlKtJyYsmz+P24mGcsI6a9Uwe1OHzltILCSHEgS+ DUeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ePxEjCpSua6fj5aJ+IohmoUGT5bMYR8zBPzmWNl+6xg=; b=jleKUxOyXE/FwmPugQ0wAYRt881i9YQyfsAh9EAmIVoTXPl2XoPBsj5pED5lCtfdiW 1Q8WBsux3+8CoFghFXTWwA5OVAIeMVJUPwfQw3PqxR30F3QIynklgXXzefvbCrklYZwU DdQjFSeqqHrc8pEBjrqW7TeRuXWSO77eTiiR6ErRFzMi3PXoq3vhEJwL11gkKDll7Hip RQrrhGFYJaKrjBVyPL01tp0earjIA9/vlP17qc4rHbW1/etqq2SpADX/TVpaVhseCIUX sCtK25prnNaIueoGIOFi00eJDeJWM1IlODsoFzKKyqXsQA7J3BjpkO7hAhCrrh6qVFpU Ab6g== X-Gm-Message-State: AJIora+LKMrvi/z0gmsUyZd/BPdlrITUBmpJDp/tDOemNRy1WvESgE5e bUqcztj/lmbCypfufY36MYPpIdkrInY= X-Google-Smtp-Source: AGRyM1uyl7P4uSa2d96sSA/DlKFxBGR60usVf1zW4jAi2Wow8c5fAmMHjd+mbRNEFFxUzgcc7X9lvw== X-Received: by 2002:a5d:5601:0:b0:21d:7174:7e9d with SMTP id l1-20020a5d5601000000b0021d71747e9dmr20475852wrv.209.1657631234192; Tue, 12 Jul 2022 06:07:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c8-20020a5d4148000000b0021d8b1656dfsm8374228wrq.93.2022.07.12.06.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:07:12 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 12 Jul 2022 13:06:56 +0000 Subject: [PATCH v4 03/12] branch: consider refs under 'update-refs' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, me@ttaylorr.com, Jeff Hostetler , Phillip Wood , Elijah Newren , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The branch_checked_out() helper helps commands like 'git branch' and 'git fetch' from overwriting refs that are currently checked out in other worktrees. A future update to 'git rebase' will introduce a new '--update-refs' option which will update the local refs that point to commits that are being rebased. To avoid collisions as the rebase completes, we want to make the future data store for these refs to be considered by branch_checked_out(). The data store is a plaintext file inside the 'rebase-merge' directory for that worktree. The file lists refnames followed by two OIDs, each on separate lines. The OIDs will be used to store the original values of the refs and the to-be-written values as the rebase progresses, but can be ignored at the moment. Create a new sequencer_get_update_refs_state() method that parses this file and populates a struct string_list with the ref-OID pairs. We can then use this list to add to the current_checked_out_branches strmap used by branch_checked_out(). To properly navigate to the rebase directory for a given worktree, extract the static strbuf_worktree_gitdir() method to a public API method. We can test that this works without having Git write this file by artificially creating one in our test script, at least until 'git rebase --update-refs' is implemented and we can use it directly. Signed-off-by: Derrick Stolee --- branch.c | 13 +++++++ sequencer.c | 74 +++++++++++++++++++++++++++++++++++++++ sequencer.h | 9 +++++ t/t2407-worktree-heads.sh | 23 ++++++++++++ 4 files changed, 119 insertions(+) diff --git a/branch.c b/branch.c index 526e8237673..f252c4eef6c 100644 --- a/branch.c +++ b/branch.c @@ -365,6 +365,7 @@ static void prepare_checked_out_branches(void) char *old; struct wt_status_state state = { 0 }; struct worktree *wt = worktrees[i++]; + struct string_list update_refs = STRING_LIST_INIT_DUP; if (wt->is_bare) continue; @@ -400,6 +401,18 @@ static void prepare_checked_out_branches(void) strbuf_release(&ref); } wt_status_state_free_buffers(&state); + + if (!sequencer_get_update_refs_state(get_worktree_git_dir(wt), + &update_refs)) { + struct string_list_item *item; + for_each_string_list_item(item, &update_refs) { + old = strmap_put(¤t_checked_out_branches, + item->string, + xstrdup(wt->path)); + free(old); + } + string_list_clear(&update_refs, 1); + } } free_worktrees(worktrees); diff --git a/sequencer.c b/sequencer.c index 8c3ed3532ac..e93c61cbd25 100644 --- a/sequencer.c +++ b/sequencer.c @@ -147,6 +147,20 @@ static GIT_PATH_FUNC(rebase_path_squash_onto, "rebase-merge/squash-onto") */ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete") +/* + * The update-refs file stores a list of refs that will be updated at the end + * of the rebase sequence. The 'update-ref ' commands in the todo file + * update the OIDs for the refs in this file, but the refs are not updated + * until the end of the rebase sequence. + * + * rebase_path_update_refs() returns the path to this file for a given + * worktree directory. For the current worktree, pass the_repository->gitdir. + */ +static char *rebase_path_update_refs(const char *wt_dir) +{ + return xstrfmt("%s/rebase-merge/update-refs", wt_dir); +} + /* * The following files are written by git-rebase just after parsing the * command-line. @@ -169,6 +183,15 @@ static GIT_PATH_FUNC(rebase_path_no_reschedule_failed_exec, "rebase-merge/no-res static GIT_PATH_FUNC(rebase_path_drop_redundant_commits, "rebase-merge/drop_redundant_commits") static GIT_PATH_FUNC(rebase_path_keep_redundant_commits, "rebase-merge/keep_redundant_commits") +/** + * A 'struct update_refs_record' represents a value in the update-refs + * list. We use a string_list to map refs to these (before, after) pairs. + */ +struct update_ref_record { + struct object_id before; + struct object_id after; +}; + static int git_sequencer_config(const char *k, const char *v, void *cb) { struct replay_opts *opts = cb; @@ -5901,3 +5924,54 @@ int sequencer_determine_whence(struct repository *r, enum commit_whence *whence) return 0; } + +int sequencer_get_update_refs_state(const char *wt_dir, + struct string_list *refs) +{ + int result = 0; + FILE *fp = NULL; + struct strbuf ref = STRBUF_INIT; + struct strbuf hash = STRBUF_INIT; + struct update_ref_record *rec = NULL; + + char *path = rebase_path_update_refs(wt_dir); + + fp = fopen(path, "r"); + if (!fp) + goto cleanup; + + while (strbuf_getline(&ref, fp) != EOF) { + struct string_list_item *item; + + CALLOC_ARRAY(rec, 1); + + if (strbuf_getline(&hash, fp) == EOF || + get_oid_hex(hash.buf, &rec->before)) { + warning(_("update-refs file at '%s' is invalid"), + path); + result = -1; + goto cleanup; + } + + if (strbuf_getline(&hash, fp) == EOF || + get_oid_hex(hash.buf, &rec->after)) { + warning(_("update-refs file at '%s' is invalid"), + path); + result = -1; + goto cleanup; + } + + item = string_list_insert(refs, ref.buf); + item->util = rec; + rec = NULL; + } + +cleanup: + if (fp) + fclose(fp); + free(path); + free(rec); + strbuf_release(&ref); + strbuf_release(&hash); + return result; +} diff --git a/sequencer.h b/sequencer.h index da64473636b..3ae541bb145 100644 --- a/sequencer.h +++ b/sequencer.h @@ -232,4 +232,13 @@ void sequencer_post_commit_cleanup(struct repository *r, int verbose); int sequencer_get_last_command(struct repository* r, enum replay_action *action); int sequencer_determine_whence(struct repository *r, enum commit_whence *whence); + +/** + * Append the set of ref-OID pairs that are currently stored for the 'git + * rebase --update-refs' feature if such a rebase is currently happening. + * + * Localized to a worktree's git dir. + */ +int sequencer_get_update_refs_state(const char *wt_dir, struct string_list *refs); + #endif /* SEQUENCER_H */ diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh index a67ce5fb003..97f5c87f8c8 100755 --- a/t/t2407-worktree-heads.sh +++ b/t/t2407-worktree-heads.sh @@ -81,6 +81,29 @@ test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (mer grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err ' +test_expect_success 'refuse to overwrite: worktree in rebase with --update-refs' ' + test_when_finished rm -rf .git/worktrees/wt-3/rebase-merge && + + mkdir -p .git/worktrees/wt-3/rebase-merge && + touch .git/worktrees/wt-3/rebase-merge/interactive && + + cat >.git/worktrees/wt-3/rebase-merge/update-refs <<-EOF && + refs/heads/fake-3 + $(git rev-parse HEAD~1) + $(git rev-parse HEAD) + refs/heads/fake-4 + $(git rev-parse HEAD) + $(git rev-parse HEAD) + EOF + + for i in 3 4 + do + test_must_fail git branch -f fake-$i HEAD 2>err && + grep "cannot force update the branch '\''fake-$i'\'' checked out at.*wt-3" err || + return 1 + done +' + test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' ' test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err && From patchwork Tue Jul 12 13:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12914968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8EEFC433EF for ; Tue, 12 Jul 2022 13:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbiGLNHc (ORCPT ); Tue, 12 Jul 2022 09:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232827AbiGLNH0 (ORCPT ); Tue, 12 Jul 2022 09:07:26 -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 438B4B5211 for ; Tue, 12 Jul 2022 06:07:17 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id v10-20020a05600c15ca00b003a2db8aa2c4so4772154wmf.2 for ; Tue, 12 Jul 2022 06:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=z+L9+tPr9fjSOm+ow1CUgMKdAgsHWFJvdTFI6Y5m8Js=; b=I2gbzeLD388FFlAxV3LUiPwJw7CxWDipEwq51RAx10Fc6LNQuzoA2+Lo3wz5Hi31DR bdJsqLnCDn2aD2NY4+roXwxUlQwTXsNX5+MClvkrytTJpwREKN0ETib0XoUcinS24b5f VacEnFMCBV1PaU69GdqcTe8BauZICMtGs7BS4/Vwe1E55VwmsFAB+Bhj5KPzlehZnDn+ xcdXHXkgp4JtTbUs5H7ms7Pltw4Grz6ZAXc7WgY1+ZJX/vUvNR7nDXGIOjuW1G5JqyXS nzckq9yB1LUuMT7fVYc+WiBGMJ8BjgDjMw5xpEa0ayy9jcdIfxZsR/tzuZYdAcOAts49 JG7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=z+L9+tPr9fjSOm+ow1CUgMKdAgsHWFJvdTFI6Y5m8Js=; b=5I62eKhnNntRx/vxkerbVatV3Y68btITo3dEkP4GRxgFBFX5oLBRFMnepDLqZ2jj1e nEGNqCOgDvVisSHnBdDQ1GHktpdOW3k1MDXvQ/JCSRzlLM2zJ7tz3mTgktg9QCMwd1+O fN1SxxSWMShEjfKuqtl0x7EDodVtSalP/U8X1kt5zgkXCCSTmbqRlLDkOLKBvxwG8uQF wYtsz0EfYc7utJgTKIuv8A0JUc0o60UPvyG8grL/j8XZQavCuu8RO1KSlA1O1YkM7MU8 v7L2LKMwOYmbEgk55pu7RoKTkMMiVS+nqlCKFqflVJHx7nrdNuXAljg15RjTxPTCuIHD SRwQ== X-Gm-Message-State: AJIora/DDbO8HbiIsdQyGxBQbw4ppQenzrXFC/0+jsvcUjn1W4WDjlas so6iv07XCD/IIJJ0KOscvSg8lqUFjYI= X-Google-Smtp-Source: AGRyM1tjXNkalkNL0tdYK4mDq4G3fr22uJY778PT7IJLs1KzPQoYk52J+uRkx6K+k5Bl9cNd+VklDw== X-Received: by 2002:a7b:c2aa:0:b0:39c:9039:e74b with SMTP id c10-20020a7bc2aa000000b0039c9039e74bmr3787933wmk.127.1657631235426; Tue, 12 Jul 2022 06:07:15 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n7-20020a5d4c47000000b0021baf5e590dsm8258010wrt.71.2022.07.12.06.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:07:14 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 12 Jul 2022 13:06:57 +0000 Subject: [PATCH v4 04/12] rebase-interactive: update 'merge' description Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, me@ttaylorr.com, Jeff Hostetler , Phillip Wood , Elijah Newren , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'merge' command description for the todo list documentation in an interactive rebase has multiple lines. The lines other than the first one start with dots ('.') while the similar multi-line documentation for 'fixup' does not. This description only appears in the comment text of the todo file during an interactive rebase. The 'merge' command was documented when interactive rebase was first ported to C in 145e05ac44b (rebase -i: rewrite append_todo_help() in C, 2018-08-10). These dots might have been carried over from the previous shell implementation. The 'fixup' command was documented more recently in 9e3cebd97cb (rebase -i: add fixup [-C | -c] command, 2021-01-29). Looking at the output in an editor, my personal opinion is that the dots are unnecessary and noisy. Remove them now before adding more commands with multi-line documentation. Signed-off-by: Derrick Stolee --- rebase-interactive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index 87649d0c016..22394224faa 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -54,9 +54,9 @@ void append_todo_help(int command_count, "l, label