From patchwork Tue Feb 28 18:56:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155133 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 F0C02C64EC7 for ; Tue, 28 Feb 2023 18:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbjB1S4z (ORCPT ); Tue, 28 Feb 2023 13:56:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjB1S4x (ORCPT ); Tue, 28 Feb 2023 13:56:53 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2A4C30193 for ; Tue, 28 Feb 2023 10:56:51 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id 10-20020a63030a000000b004fb64e929f2so3679818pgd.7 for ; Tue, 28 Feb 2023 10:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mr3R3joRcKFFbyznXeet9EbPAgSQ+Q4tIN1Ev2Trpd4=; b=KBbCVMhnQrfhQTQ437rWTVyE8LysI6wqUllpd8fqRT3ahwa8iw2qsGKylWgcWnh54J Dpd2Blz4c84bPz4RnLXUNcAEAiacpkxskXpYziUqMLj/pRbIjiPMpHooHLn8/4VUZdq+ sooDSmoz/OK/oJRS5I5/TrvFYu/B7tv4q9PSNOgKmMTsrAM4iMNia1+8l/BbjWvXcHlr cRce68uEsEuGl9rvjNPW+IXMZP/6mbiPHfkZU3LcHpaGLFTXfTfMxR5W/GSQBc7XjilD sGCTD4IVHojLd6gGLv4sDFWtCTpKcGHYhvhaqc+pfBMSLm6xpETc98e44/Gwmz/hoENz t4jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mr3R3joRcKFFbyznXeet9EbPAgSQ+Q4tIN1Ev2Trpd4=; b=M/aK5+KeHAhLElEedhymuJMa6/tNmth1i0yx6YMcO/FF+Ow6IhN4XretTsTEIB+ukI 0EnH/qJUqW6Axkc4ZAJoOABU/oam63hrI0S2XPwRrwx3g2RjfXq1esNZLmUCkeuUMcjK +IziprQiyAsHRcPgTC51P2fmsRA5cSwoH31NCtXdFu2Q7MtWfiWqcPp7PrO13148KuTC 4a7QQDaybbdxTHu/5SUS27pomBcq9XZ5K1dkPR8SfrqjlYOpVXXj/l5XXkXATlkvBiZk XeJKNMFU3P7XnigShUBqEPso/tN5d8jtCOB6K1TvIt0r/9N+M0OLmbhhpB0Btv5OhbHX xaSA== X-Gm-Message-State: AO0yUKVYjW8ErcCkDQP+qH2yTORVgeAtvfKEA6er2ppi1rDcOh9eVrBW ttTcqQURL859u38vRwP12A0zlmT8YYGgwUHYifvdu2nTP6Jb7lu1zWCYigShcafmuvvVhCkurgk 3XR/Mo0N5TH2BekHdYh863cWHNJXR2/NeFjLje+x38pUh/8pj3nP6Fbwki0FJuoh9Jg== X-Google-Smtp-Source: AK7set8Zf57dsON36hCbb3L7KjKh6//0pX6OFiYdvK8hb37X480ZqclM2tA6CLGE8rX16TN4AdiYMe+thz6EKh8= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:903:4285:b0:199:1afc:16ad with SMTP id ju5-20020a170903428500b001991afc16admr1345831plb.5.1677610611090; Tue, 28 Feb 2023 10:56:51 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:37 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-1-calvinwan@google.com> Subject: [PATCH v2 1/6] t4041, t4060: modernize test style From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , peff@peff.net, gitster@pobox.com, Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Josh Steadmon In preparation for later changes, move setup code into test_expect blocks. Smaller sections are moved into existing blocks, while larger sections with a standalone purpose are given their own new blocks. This makes sure that later changes that may break the test setup are easier to diagnose, because errors will caught immediately rather than in later unrelated test_expect blocks. While at it, have tests clean up after themselves with test_when_finished and fix other minor style issues. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- t/t4041-diff-submodule-option.sh | 79 ++++++++------- t/t4060-diff-submodule-option-diff-format.sh | 101 +++++++++---------- 2 files changed, 89 insertions(+), 91 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 0c1502d4b0..2aa12243bd 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -42,11 +42,12 @@ commit_file () { git commit "$@" -m "Commit $*" >/dev/null } -test_create_repo sm1 && -add_file . foo >/dev/null - -head1=$(add_file sm1 foo1 foo2) -fullhead1=$(cd sm1; git rev-parse --verify HEAD) +test_expect_success 'setup' ' + test_create_repo sm1 && + add_file . foo && + head1=$(add_file sm1 foo1 foo2) && + fullhead1=$(git -C sm1 rev-parse --verify HEAD) +' test_expect_success 'added submodule' ' git add sm1 && @@ -99,10 +100,9 @@ test_expect_success 'diff.submodule does not affect plumbing' ' test_cmp expected actual ' -commit_file sm1 && -head2=$(add_file sm1 foo3) - test_expect_success 'modified submodule(forward)' ' + commit_file sm1 && + head2=$(add_file sm1 foo3) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: @@ -129,8 +129,8 @@ test_expect_success 'modified submodule(forward) --submodule' ' test_cmp expected actual ' -fullhead2=$(cd sm1; git rev-parse --verify HEAD) test_expect_success 'modified submodule(forward) --submodule=short' ' + fullhead2=$(git -C sm1 rev-parse --verify HEAD) && git diff --submodule=short >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -144,14 +144,14 @@ test_expect_success 'modified submodule(forward) --submodule=short' ' test_cmp expected actual ' -commit_file sm1 && -head3=$( - cd sm1 && - git reset --hard HEAD~2 >/dev/null && - git rev-parse --short --verify HEAD -) test_expect_success 'modified submodule(backward)' ' + commit_file sm1 && + head3=$( + cd sm1 && + git reset --hard HEAD~2 >/dev/null && + git rev-parse --short --verify HEAD + ) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): @@ -161,8 +161,8 @@ test_expect_success 'modified submodule(backward)' ' test_cmp expected actual ' -head4=$(add_file sm1 foo4 foo5) test_expect_success 'modified submodule(backward and forward)' ' + head4=$(add_file sm1 foo4 foo5) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2...$head4: @@ -174,13 +174,15 @@ test_expect_success 'modified submodule(backward and forward)' ' test_cmp expected actual ' -commit_file sm1 && -mv sm1 sm1-bak && -echo sm1 >sm1 && -head5=$(git hash-object sm1 | cut -c1-7) && -git add sm1 && -rm -f sm1 && -mv sm1-bak sm1 +test_expect_success 'setup - change sm1 to a blob' ' + commit_file sm1 && + mv sm1 sm1-bak && + echo sm1 >sm1 && + head5=$(git hash-object sm1 | cut -c1-7) && + git add sm1 && + rm -f sm1 && + mv sm1-bak sm1 +' test_expect_success 'typechanged submodule(submodule->blob), --cached' ' git diff --submodule=log --cached >actual && @@ -198,6 +200,7 @@ test_expect_success 'typechanged submodule(submodule->blob), --cached' ' ' test_expect_success 'typechanged submodule(submodule->blob)' ' + test_when_finished rm -rf sm1 && git diff --submodule=log >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -212,9 +215,9 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' test_cmp expected actual ' -rm -rf sm1 && -git checkout-index sm1 test_expect_success 'typechanged submodule(submodule->blob)' ' + test_when_finished rm -f sm1 && + git checkout-index sm1 && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head4...0000000 (submodule deleted) @@ -229,11 +232,10 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' test_cmp expected actual ' -rm -f sm1 && -test_create_repo sm1 && -head6=$(add_file sm1 foo6 foo7) -fullhead6=$(cd sm1; git rev-parse --verify HEAD) test_expect_success 'nonexistent commit' ' + test_create_repo sm1 && + head6=$(add_file sm1 foo6 foo7) && + fullhead6=$(git -C sm1 rev-parse --verify HEAD) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head4...$head6 (commits not present) @@ -241,8 +243,8 @@ test_expect_success 'nonexistent commit' ' test_cmp expected actual ' -commit_file test_expect_success 'typechanged submodule(blob->submodule)' ' + commit_file && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -257,8 +259,8 @@ test_expect_success 'typechanged submodule(blob->submodule)' ' test_cmp expected actual ' -commit_file sm1 && test_expect_success 'submodule is up to date' ' + commit_file sm1 && git diff-index -p --submodule=log HEAD >actual && test_must_be_empty actual ' @@ -313,13 +315,13 @@ test_expect_success 'submodule contains untracked and modified content (dirty ig ' test_expect_success 'submodule contains untracked and modified content (all ignored)' ' + test_when_finished rm -f sm1/new-file && echo new > sm1/foo6 && git diff-index -p --ignore-submodules --submodule=log HEAD >actual && test_must_be_empty actual ' test_expect_success 'submodule contains modified content' ' - rm -f sm1/new-file && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 contains modified content @@ -327,9 +329,9 @@ test_expect_success 'submodule contains modified content' ' test_cmp expected actual ' -(cd sm1; git commit -mchange foo6 >/dev/null) && -head8=$(cd sm1; git rev-parse --short --verify HEAD) && test_expect_success 'submodule is modified' ' + (cd sm1 && git commit -mchange foo6 >/dev/null) && + head8=$(cd sm1 && git rev-parse --short --verify HEAD) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head6..$head8: @@ -406,13 +408,14 @@ test_expect_success 'modified submodule contains untracked and modified content ' test_expect_success 'modified submodule contains untracked and modified content (all ignored)' ' + test_when_finished rm -f sm1/new-file && echo modification >> sm1/foo6 && git diff-index -p --ignore-submodules --submodule=log HEAD >actual && test_must_be_empty actual ' test_expect_success 'modified submodule contains modified content' ' - rm -f sm1/new-file && + test_when_finished rm -rf sm1 && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 contains modified content @@ -422,7 +425,6 @@ test_expect_success 'modified submodule contains modified content' ' test_cmp expected actual ' -rm -rf sm1 test_expect_success 'deleted submodule' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && @@ -454,8 +456,8 @@ test_expect_success 'path filter' ' test_cmp expected actual ' -commit_file sm2 test_expect_success 'given commit' ' + commit_file sm2 && git diff-index -p --submodule=log HEAD^ >actual && cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) @@ -473,9 +475,8 @@ test_expect_success 'given commit --submodule' ' test_cmp expected actual ' -fullhead7=$(cd sm2; git rev-parse --verify HEAD) - test_expect_success 'given commit --submodule=short' ' + fullhead7=$(git -C sm2 rev-parse --verify HEAD) && git diff-index -p --submodule=short HEAD^ >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh index 97c6424cd5..a760ed5eb6 100755 --- a/t/t4060-diff-submodule-option-diff-format.sh +++ b/t/t4060-diff-submodule-option-diff-format.sh @@ -138,10 +138,9 @@ test_expect_success 'diff.submodule does not affect plumbing' ' diff_cmp expected actual ' -commit_file sm1 && -head2=$(add_file sm1 foo3) - test_expect_success 'modified submodule(forward)' ' + commit_file sm1 && + head2=$(add_file sm1 foo3) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: @@ -180,8 +179,8 @@ test_expect_success 'modified submodule(forward) --submodule' ' diff_cmp expected actual ' -fullhead2=$(cd sm1; git rev-parse --verify HEAD) test_expect_success 'modified submodule(forward) --submodule=short' ' + fullhead2=$(git -C sm1 rev-parse --verify HEAD) && git diff --submodule=short >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -195,14 +194,12 @@ test_expect_success 'modified submodule(forward) --submodule=short' ' diff_cmp expected actual ' -commit_file sm1 && -head3=$( - cd sm1 && - git reset --hard HEAD~2 >/dev/null && - git rev-parse --short --verify HEAD -) - test_expect_success 'modified submodule(backward)' ' + commit_file sm1 && + head3=$( + git -C sm1 reset --hard HEAD~2 >/dev/null && + git -C sm1 rev-parse --short --verify HEAD + ) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): @@ -224,8 +221,8 @@ test_expect_success 'modified submodule(backward)' ' diff_cmp expected actual ' -head4=$(add_file sm1 foo4 foo5) test_expect_success 'modified submodule(backward and forward)' ' + head4=$(add_file sm1 foo4 foo5) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2...$head4: @@ -261,13 +258,15 @@ test_expect_success 'modified submodule(backward and forward)' ' diff_cmp expected actual ' -commit_file sm1 && -mv sm1 sm1-bak && -echo sm1 >sm1 && -head5=$(git hash-object sm1 | cut -c1-7) && -git add sm1 && -rm -f sm1 && -mv sm1-bak sm1 +test_expect_success 'setup - change sm1 to a blob' ' + commit_file sm1 && + mv sm1 sm1-bak && + echo sm1 >sm1 && + head5=$(git hash-object sm1 | cut -c1-7) && + git add sm1 && + rm -f sm1 && + mv sm1-bak sm1 +' test_expect_success 'typechanged submodule(submodule->blob), --cached' ' git diff --submodule=diff --cached >actual && @@ -306,6 +305,7 @@ test_expect_success 'typechanged submodule(submodule->blob), --cached' ' ' test_expect_success 'typechanged submodule(submodule->blob)' ' + test_when_finished rm -rf sm1 && git diff --submodule=diff >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -341,9 +341,9 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' diff_cmp expected actual ' -rm -rf sm1 && -git checkout-index sm1 test_expect_success 'typechanged submodule(submodule->blob)' ' + test_when_finished rm -f sm1 && + git checkout-index sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head4...0000000 (submodule deleted) @@ -358,10 +358,9 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' diff_cmp expected actual ' -rm -f sm1 && -test_create_repo sm1 && -head6=$(add_file sm1 foo6 foo7) test_expect_success 'nonexistent commit' ' + test_create_repo sm1 && + head6=$(add_file sm1 foo6 foo7) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head4...$head6 (commits not present) @@ -369,8 +368,8 @@ test_expect_success 'nonexistent commit' ' diff_cmp expected actual ' -commit_file test_expect_success 'typechanged submodule(blob->submodule)' ' + commit_file && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -399,8 +398,8 @@ test_expect_success 'typechanged submodule(blob->submodule)' ' diff_cmp expected actual ' -commit_file sm1 && test_expect_success 'submodule is up to date' ' + commit_file sm1 && head7=$(git -C sm1 rev-parse --short --verify HEAD) && git diff-index -p --submodule=diff HEAD >actual && test_must_be_empty actual @@ -471,13 +470,13 @@ test_expect_success 'submodule contains untracked and modified content (dirty ig ' test_expect_success 'submodule contains untracked and modified content (all ignored)' ' + test_when_finished rm -f sm1/new-file && echo new > sm1/foo6 && git diff-index -p --ignore-submodules --submodule=diff HEAD >actual && test_must_be_empty actual ' test_expect_success 'submodule contains modified content' ' - rm -f sm1/new-file && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 contains modified content @@ -492,9 +491,9 @@ test_expect_success 'submodule contains modified content' ' diff_cmp expected actual ' -(cd sm1; git commit -mchange foo6 >/dev/null) && -head8=$(cd sm1; git rev-parse --short --verify HEAD) && test_expect_success 'submodule is modified' ' + (git -C sm1 commit -mchange foo6 >/dev/null) && + head8=$(git -C sm1 rev-parse --short --verify HEAD) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7..$head8: @@ -616,6 +615,7 @@ test_expect_success 'modified submodule contains untracked and modified content ' test_expect_success 'modified submodule contains untracked and modified content (all ignored)' ' + test_when_finished rm -f sm1/new-file && echo modification >> sm1/foo6 && git diff-index -p --ignore-submodules --submodule=diff HEAD >actual && test_must_be_empty actual @@ -623,7 +623,7 @@ test_expect_success 'modified submodule contains untracked and modified content # NOT OK test_expect_success 'modified submodule contains modified content' ' - rm -f sm1/new-file && + test_when_finished rm -rf sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 contains modified content @@ -643,7 +643,6 @@ test_expect_success 'modified submodule contains modified content' ' diff_cmp expected actual ' -rm -rf sm1 test_expect_success 'deleted submodule' ' git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && @@ -703,13 +702,15 @@ test_expect_success 'path filter' ' diff_cmp expected actual ' -cat >.gitmodules <<-EOF -[submodule "sm2"] - path = sm2 - url = bogus_url -EOF -git add .gitmodules -commit_file sm2 .gitmodules +test_expect_success 'setup - construct .gitmodules' ' + cat >.gitmodules <<-EOF && + [submodule "sm2"] + path = sm2 + url = bogus_url + EOF + git add .gitmodules && + commit_file sm2 .gitmodules +' test_expect_success 'given commit' ' git diff-index -p --submodule=diff HEAD^ >actual && @@ -779,9 +780,8 @@ test_expect_success 'diff --submodule=diff with .git file' ' diff_cmp expected actual ' -mv sm2 sm2-bak - test_expect_success 'deleted submodule with .git file' ' + mv sm2 sm2-bak && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7...0000000 (submodule deleted) @@ -804,9 +804,9 @@ test_expect_success 'deleted submodule with .git file' ' diff_cmp expected actual ' -echo submodule-to-blob>sm2 - test_expect_success 'typechanged(submodule->blob) submodule with .git file' ' + test_when_finished "rm sm2 && mv sm2-bak sm2" && + echo submodule-to-blob>sm2 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7...0000000 (submodule deleted) @@ -836,9 +836,6 @@ test_expect_success 'typechanged(submodule->blob) submodule with .git file' ' diff_cmp expected actual ' -rm sm2 -mv sm2-bak sm2 - test_expect_success 'setup nested submodule' ' git -c protocol.file.allow=always -C sm2 submodule add ../sm2 nested && git -C sm2 commit -a -m "nested sub" && @@ -910,13 +907,11 @@ test_expect_success 'diff --submodule=diff recurses into nested submodules' ' diff_cmp expected actual ' -(cd sm2; commit_file nested) -commit_file sm2 -head12=$(cd sm2; git rev-parse --short --verify HEAD) - -mv sm2 sm2-bak - test_expect_success 'diff --submodule=diff recurses into deleted nested submodules' ' + (cd sm2 && commit_file nested) && + commit_file sm2 && + head12=$(git -C sm2 rev-parse --short --verify HEAD) && + mv sm2 sm2-bak && cat >expected <<-EOF && Submodule sm1 $head7...0000000 (submodule deleted) Submodule sm2 $head12...0000000 (submodule deleted) @@ -971,6 +966,8 @@ test_expect_success 'diff --submodule=diff recurses into deleted nested submodul diff_cmp expected actual ' -mv sm2-bak sm2 +test_expect_success 'submodule cleanup' ' + mv sm2-bak sm2 +' test_done From patchwork Tue Feb 28 18:56:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155134 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 69926C6FA8E for ; Tue, 28 Feb 2023 18:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbjB1S44 (ORCPT ); Tue, 28 Feb 2023 13:56:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbjB1S4y (ORCPT ); Tue, 28 Feb 2023 13:56:54 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B50030194 for ; Tue, 28 Feb 2023 10:56:53 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id bx9-20020a056a00428900b005f077bc6e5eso4323258pfb.16 for ; Tue, 28 Feb 2023 10:56:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jSPXL96PFFtKhtNXGtyeUOyskgu63HGUjKzWavKC7Wc=; b=irxp3SPa6gJxs2v3EPwOIOOPVmga+rlvmf9aSmWzp3NyuKzThmAxqLF6QUlP938/jp ifVO35T6c2TqFGUEWXqt1MiCVD1O8lNLo2SIkVbcX1v5xz+Hs2hfK866+o7lLXllvkuU /v6PZKlqehYiwGGp1SJ5eqkq01TaOTBvFXSpAT20akPpCHIK3cwuNqsDLJ01hqiBJqYl 9sBgGGKYiKS60VElY8X2fT1ElhVYVPy714pTW81HcPTwAOeJpoHZ0JmF7+wsd/eVJnug QzC6nN0qUBGcn7JzIjg4VI7xOutJo8smk3MV/NY2C1foaHMZPN5+igE391DjKBhVByrj gVgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jSPXL96PFFtKhtNXGtyeUOyskgu63HGUjKzWavKC7Wc=; b=ugIGY2/WOrvLw4Zkc1KFjTArdbltqL1ODCzHdsaH/w5Hxb7HEnms7obAYxdr3n67CQ bn2rPSIGbJCxEGh2sGoSxBzZZNHzY20hV8JZTMYtJ9RC/JowVy1cjiHhYntoGl3lQyTn mlcoyWwDF66swmSEGRSZ/Xt/7HAk1gmSimlAcZdRvP+zvdzS0jMVb+b5LXkid4hTiY03 C1FS0GzAxuncTiEscPp6WxXdyAqAPCTPOtVSBay0dU8AV3zRhgK29vdDQqzq09a7zWhp npl1OTLxb2dRlNtjRbmylgFXHtqPiVdbXF6oqUIQS1GkRfOLvaQ4fpHpWo6zJkEItM/Y o0nA== X-Gm-Message-State: AO0yUKWim9SVSXTDN1TR5pCF+xyq0yEYCo9lVEwvfaXNbDOd16UC3k2D gFCBiswIphU4Zik/J3zHrBdrI9LLhW8edqTOFIDiAS4qZRTREin8qEsZ5yRy2RSRJ8gwrR1rGbt B4CFF+8zSP7kGPcZeksVVcdmPaSf4kmpF0RnhXnOHAPFkGk/GuOB4kYrr3fdmjtqiNw== X-Google-Smtp-Source: AK7set9Pu7DjYbIqKuqGvi9bNIUHr57B1+pEWyU0Sk01Nn60UrYHblK+/cUoSuedeX0u4vPM6MKi1cMUFYedGTM= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a05:6a00:26eb:b0:5de:ece4:2674 with SMTP id p43-20020a056a0026eb00b005deece42674mr1325044pfw.3.1677610612412; Tue, 28 Feb 2023 10:56:52 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:38 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-2-calvinwan@google.com> Subject: [PATCH v2 2/6] tests: Use `git submodule add` instead of `git add` From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , peff@peff.net, gitster@pobox.com, Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Josh Steadmon Since 532139940c (add: warn when adding an embedded repository, 2017-06-14), we have recognized that adding embedded repositories is a subpar user experience compared to submodules. Embedded repositories lack a .gitmodules entry, which means clones of the top-level repo will be unable to obtain the nested repo. We issue advice about this situation in the case where a user adds an embedded repository. However, many tests predate this advice, and directly add embedded repositories instead of using submodules. This commit cleans up such test cases where minimal other changes are required (e.g., committing later changes to .gitmodules or changing the counts of committed files in the worktree). Future commits will handle tests requiring more complicated adjustments. These changes will enable us to switch the default behavior of git-add from warning about embedded repositories to rejecting them outright. See later commits for a further discussion of that topic. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- t/t2013-checkout-submodule.sh | 4 +++- t/t2103-update-index-ignore-missing.sh | 2 +- t/t2107-update-index-basic.sh | 2 +- t/t3040-subprojects-basic.sh | 2 +- t/t3050-subprojects-fetch.sh | 3 ++- t/t3404-rebase-interactive.sh | 3 ++- t/t3701-add-interactive.sh | 5 +++-- t/t4010-diff-pathspec.sh | 2 +- t/t4020-diff-external.sh | 2 +- t/t5531-deep-submodule-push.sh | 4 ++-- t/t6416-recursive-corner-cases.sh | 12 ++++++------ t/t6437-submodule-merge.sh | 12 ++++++------ t/t7401-submodule-summary.sh | 4 ++-- t/t7402-submodule-rebase.sh | 2 +- 14 files changed, 32 insertions(+), 27 deletions(-) diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index b2bdd1fcb4..dd2858648b 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -10,7 +10,7 @@ test_expect_success 'setup' ' (cd submodule && git init && test_commit first) && - git add submodule && + git submodule add ./submodule && test_tick && git commit -m superproject && (cd submodule && @@ -51,6 +51,7 @@ test_expect_success '"checkout " honors submodule.*.ignore from .gitm git config diff.ignoreSubmodules none && git config -f .gitmodules submodule.submodule.path submodule && git config -f .gitmodules submodule.submodule.ignore untracked && + git commit -m "Update patterns in .gitmodules" .gitmodules && git checkout HEAD >actual 2>&1 && test_must_be_empty actual ' @@ -59,6 +60,7 @@ test_expect_success '"checkout " honors submodule.*.ignore from .git/ git config -f .gitmodules submodule.submodule.ignore none && git config submodule.submodule.path submodule && git config submodule.submodule.ignore all && + git commit -m "Update patterns in .gitmodules" .gitmodules && git checkout HEAD >actual 2>&1 && test_must_be_empty actual ' diff --git a/t/t2103-update-index-ignore-missing.sh b/t/t2103-update-index-ignore-missing.sh index e9451cd567..11bc136f6e 100755 --- a/t/t2103-update-index-ignore-missing.sh +++ b/t/t2103-update-index-ignore-missing.sh @@ -36,7 +36,7 @@ test_expect_success basics ' git add file && git commit -m "sub initial" ) && - git add xyzzy && + git add ./xyzzy && test_tick && git commit -m initial && diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index 07e6de84e6..465b41ccdc 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -49,7 +49,7 @@ test_expect_success '--cacheinfo does not accept blob null sha1' ' test_expect_success '--cacheinfo does not accept gitlink null sha1' ' git init submodule && (cd submodule && test_commit foo) && - git add submodule && + git submodule add ./submodule && git rev-parse :submodule >expect && test_must_fail git update-index --cacheinfo 160000 $ZERO_OID submodule && git rev-parse :submodule >actual && diff --git a/t/t3040-subprojects-basic.sh b/t/t3040-subprojects-basic.sh index bd65dfcffc..61da7e3b94 100755 --- a/t/t3040-subprojects-basic.sh +++ b/t/t3040-subprojects-basic.sh @@ -69,7 +69,7 @@ test_expect_success 'check if clone works' ' test_expect_success 'removing and adding subproject' ' git update-index --force-remove -- sub2 && mv sub2 sub3 && - git add sub3 && + git submodule add ./sub3 && git commit -q -m "renaming a subproject" && test_expect_code 1 git diff -M --name-status --exit-code HEAD^ HEAD ' diff --git a/t/t3050-subprojects-fetch.sh b/t/t3050-subprojects-fetch.sh index f1f09abdd9..9a692274b9 100755 --- a/t/t3050-subprojects-fetch.sh +++ b/t/t3050-subprojects-fetch.sh @@ -14,7 +14,8 @@ test_expect_success setup ' git commit -m "subproject commit #1" ) && >mainfile && - git add sub mainfile && + git add mainfile && + git submodule add ./sub && test_tick && git commit -m "superproject commit #1" ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 462cefd25d..1d0574216b 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -675,7 +675,8 @@ test_expect_success 'submodule rebase setup' ' git add elif && git commit -m "submodule initial" ) && echo 1 >file1 && - git add file1 sub && + git add file1 && + git submodule add ./sub && test_tick && git commit -m "One" && echo 2 >file1 && diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 5841f280fb..715c4fcc62 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -913,8 +913,9 @@ test_expect_success 'setup different kinds of dirty submodules' ' ) && cp -R dirty-head dirty-otherwise && cp -R dirty-head dirty-both-ways && - git add dirty-head && - git add dirty-otherwise dirty-both-ways && + git submodule add ./dirty-head && + git submodule add ./dirty-otherwise && + git submodule add ./dirty-both-ways && git commit -m initial && cd dirty-head && diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index 9d9650eba7..844258c418 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -117,7 +117,7 @@ test_expect_success 'setup submodules' ' test_tick && git init submod && ( cd submod && test_commit first ) && - git add submod && + git submodule add ./submod && git commit -m first && ( cd submod && test_commit second ) && git add submod && diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index c1ac09ecc7..ca2a23a78f 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -253,7 +253,7 @@ test_expect_success 'clean up crlf leftovers' ' test_expect_success 'submodule diff' ' git init sub && ( cd sub && test_commit sub1 ) && - git add sub && + git submodule add ./sub && test_tick && git commit -m "add submodule" && ( cd sub && test_commit sub2 ) && diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index 302e4cbdba..f8ef70b5a2 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -28,7 +28,7 @@ test_expect_success setup ' git add junk && git commit -m "Initial junk" ) && - git add gar/bage && + git submodule add ./gar/bage ./gar/bage && git commit -m "Initial superproject" ) ' @@ -367,7 +367,7 @@ test_expect_success 'push succeeds if submodule has no remote and is on the firs git add junk && git commit -m "initial" ) && - git add b && + git submodule add ./b && git commit -m "added submodule" && git push --recurse-submodules=check origin main ) diff --git a/t/t6416-recursive-corner-cases.sh b/t/t6416-recursive-corner-cases.sh index 17b54d625d..b366dd77e5 100755 --- a/t/t6416-recursive-corner-cases.sh +++ b/t/t6416-recursive-corner-cases.sh @@ -1270,7 +1270,7 @@ test_expect_success 'setup submodule modify/modify' ' ) && git -C submod reset --hard A && - git add submod && + git submodule add ./submod && git commit -m A && git tag A && @@ -1303,7 +1303,7 @@ test_expect_merge_algorithm failure success 'check submodule modify/modify' ' test_must_fail git merge -s recursive E^0 && git ls-files -s >out && - test_line_count = 3 out && + test_line_count = 4 out && git ls-files -u >out && test_line_count = 3 out && git ls-files -o >out && @@ -1364,12 +1364,12 @@ test_expect_success 'setup submodule add/add' ' git checkout -b B A && git -C submod reset --hard B && - git add submod && + git submodule add ./submod && git commit -m B && git checkout -b C A && git -C submod reset --hard C && - git add submod && + git submodule add ./submod && git commit -m C && git checkout -q B^0 && @@ -1391,7 +1391,7 @@ test_expect_merge_algorithm failure success 'check submodule add/add' ' test_must_fail git merge -s recursive E^0 && git ls-files -s >out && - test_line_count = 3 out && + test_line_count = 4 out && git ls-files -u >out && test_line_count = 2 out && git ls-files -o >out && @@ -1439,7 +1439,7 @@ test_expect_success 'setup conflicting entry types (submodule vs symlink)' ' git checkout -b B A && git -C path reset --hard B && - git add path && + git submodule add ./path && git commit -m B && git checkout -b C A && diff --git a/t/t6437-submodule-merge.sh b/t/t6437-submodule-merge.sh index c9a86f2e94..7f6e89f541 100755 --- a/t/t6437-submodule-merge.sh +++ b/t/t6437-submodule-merge.sh @@ -30,7 +30,7 @@ test_expect_success setup ' git add file && test_tick && git commit -m sub-root) && - git add sub && + git submodule add ./sub && test_tick && git commit -m root && @@ -85,7 +85,7 @@ test_expect_success 'setup for merge search' ' git branch sub-a) && git commit --allow-empty -m init && git branch init && - git add sub && + git submodule add ./sub && git commit -m "a" && git branch a && @@ -132,7 +132,7 @@ test_expect_success 'finish setup for merge-search' ' git checkout -b g init && (cd sub && git checkout -b sub-g sub-c) && - git add sub && + git submodule add ./sub && git commit -a -m "g") ' @@ -296,7 +296,7 @@ test_expect_success 'setup for recursive merge with submodule' ' git checkout -b sub-cb sub-c && git merge sub-b && git checkout main) && - git add sub && + git submodule add ./sub && git commit -m a && git checkout -b top-b main && (cd sub && git checkout sub-b) && @@ -520,7 +520,7 @@ test_expect_success 'setup for null merge base' ' git commit --allow-empty -m init && git branch init && git checkout -b a init && - git add sub && + git submodule add ./sub && git commit -m "a" && git switch main && (cd sub && @@ -532,7 +532,7 @@ test_expect_success 'setup for null merge base' ' test_expect_success 'merging should fail with no merge base' ' (cd no-merge-base && git checkout -b b init && - git add sub && + git submodule add ./sub && git commit -m "b" && test_must_fail git merge a >actual && if test "$GIT_TEST_MERGE_ALGORITHM" = ort diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 542b3331a7..73fd09edb6 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -45,7 +45,7 @@ add_file . foo >/dev/null head1=$(add_file sm1 foo1 foo2) test_expect_success 'added submodule' " - git add sm1 && + git submodule add ./sm1 && git submodule summary >actual && cat >expected <<-EOF && * sm1 0000000...$head1 (2): @@ -253,7 +253,7 @@ test_expect_success 'deleted submodule' " test_expect_success 'create second submodule' ' test_create_repo sm2 && head7=$(add_file sm2 foo8 foo9) && - git add sm2 + git submodule add ./sm2 ' test_expect_success 'multiple submodules' " diff --git a/t/t7402-submodule-rebase.sh b/t/t7402-submodule-rebase.sh index ebeca12a71..abc2092741 100755 --- a/t/t7402-submodule-rebase.sh +++ b/t/t7402-submodule-rebase.sh @@ -14,7 +14,7 @@ test_expect_success setup ' test_tick && git commit -m initial && git clone . submodule && - git add submodule && + git submodule add ./submodule && test_tick && git commit -m submodule && echo second line >> file && From patchwork Tue Feb 28 18:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155135 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 A1343C64ED6 for ; Tue, 28 Feb 2023 18:57:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbjB1S5C (ORCPT ); Tue, 28 Feb 2023 13:57:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjB1S45 (ORCPT ); Tue, 28 Feb 2023 13:56:57 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B991D30193 for ; Tue, 28 Feb 2023 10:56:54 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id y1-20020a631801000000b00503696ca95dso2119078pgl.1 for ; Tue, 28 Feb 2023 10:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=szMBxcd2fJhk+Yu9QkKAojMWq8dbuky/TvC4i1sj5us=; b=fVuvPq6qv38Eb0m4645bFUPcXdNu49UFrJBeIUqaByW03TbQPSfGtcstYTyfTf0CKy n2lJ/SIGfCKKIp0pugxnHRh/Ow539b12VQsMpMK8G3ihWui8NinUDZPhoCugR3WRSbn3 6IfyyRspb/rJ4xlE8XJWupGJuR6rPCIn/hkT0dGikSizpEXpi8dCCFHwKXL/dkVCQh2V xIuBuu6no/qWN/XMvWy358+tPvbViuuxSoJwRCTX61qZz6jl+UbsCIn4Vo/aqg9Rmw09 TzO+VTraYpJGlwYmIz5GNzCaBke0P9LmONRRKGh491PAKaIhV4iVRE+2D7KkY/WMs9aB YOCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=szMBxcd2fJhk+Yu9QkKAojMWq8dbuky/TvC4i1sj5us=; b=lOFqflep+0dZ5ALc8zwgrp5iqJyMweFU+RTMVnr1xTIUKRIxr4kNPcyMfD4TlDX3tL b6p1WRzjzGDDnjFU8Ym1TfDr7XGtF66yvhoKr1x2qju14NbjjruJQjOzcik81iQHk91j Q6a6Kg1n/Bu5kmARj7jRNHhILPNQoaW0KriJe6WBCM1V+uJgO5uYGBlyjLrJCINsJWsG ykuDcwAawB2dEm0Yy7xj/Yx0JhLfKrTkl9xqIuUftR2+6GjQnAPFhl6gv/EViBe/b2pI LEisHnNXx8CNSwnqHSUFX18+pNFQk+N1z80+MKwNMt9pr3Naynj1ABkIiT0MiG/xv9/n +05Q== X-Gm-Message-State: AO0yUKUbGpNXhpltcuKqdcImUHXuKmbp0YZHND8dwdEBF0PhcaZACGX1 oSj7BJW5fVZ25coha37TKMiwCKa8sQ/lfgAdASaycR9yrHk1elbCVH5ngdnmn1uSOQeRQWKj2ii jzQgPosDVk/Mmr3MDyWgrgRwnoEKgyKijOkm3fo5T4MQyrtVh0lNQIggJS9dQzzZ+Hw== X-Google-Smtp-Source: AK7set9YigkXZWn+Ylv2PtMSHn6MPdQscJKwMMVWIm0JimNVKRs0J9pxiFf2SW+A/lkxu0baJ+pLcP3cL5YjYjg= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:903:2615:b0:19c:1869:3558 with SMTP id jd21-20020a170903261500b0019c18693558mr1348145plb.5.1677610614024; Tue, 28 Feb 2023 10:56:54 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:39 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-3-calvinwan@google.com> Subject: [PATCH v2 3/6] tests: use `git submodule add` and fix expected diffs From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , peff@peff.net, gitster@pobox.com, Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Josh Steadmon This commit continues the previous work of updating the test suite to use `git submodule add` to create submodules instead of using `git add` to include embedded repositories. Specifically, in this commit we update test cases where expected diffs must change due to the presence of a .gitmodules file. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- t/t3040-subprojects-basic.sh | 3 +- t/t4041-diff-submodule-option.sh | 153 ++++++++++++++++++- t/t4060-diff-submodule-option-diff-format.sh | 125 +++++++++++++-- t/t7506-status-submodule.sh | 15 +- 4 files changed, 278 insertions(+), 18 deletions(-) diff --git a/t/t3040-subprojects-basic.sh b/t/t3040-subprojects-basic.sh index 61da7e3b94..a0f14db3d2 100755 --- a/t/t3040-subprojects-basic.sh +++ b/t/t3040-subprojects-basic.sh @@ -19,11 +19,12 @@ test_expect_success 'setup: create subprojects' ' ( cd sub2 && git init && : >Makefile && git add * && git commit -q -m "subproject 2" ) && git update-index --add sub1 && - git add sub2 && + git submodule add ./sub2 && git commit -q -m "subprojects added" && GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current && git branch save HEAD && cat >expected <<-\EOF && + :000000 100644 00000... A .gitmodules :000000 160000 00000... A sub1 :000000 160000 00000... A sub2 EOF diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 2aa12243bd..f5074071a4 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -50,9 +50,19 @@ test_expect_success 'setup' ' ' test_expect_success 'added submodule' ' - git add sm1 && + git submodule add ./sm1 && + gitmodules_hash1=$(git rev-parse --short $(git hash-object .gitmodules)) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 0000000...$head1 (new submodule) EOF test_cmp expected actual @@ -63,6 +73,15 @@ test_expect_success 'added submodule, set diff.submodule' ' git add sm1 && git diff --cached >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 0000000...$head1 (new submodule) EOF git config --unset diff.submodule && @@ -74,6 +93,15 @@ test_expect_success '--submodule=short overrides diff.submodule' ' git add sm1 && git diff --submodule=short --cached >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 diff --git a/sm1 b/sm1 new file mode 160000 index 0000000..$head1 @@ -89,6 +117,15 @@ test_expect_success 'diff.submodule does not affect plumbing' ' test_config diff.submodule log && git diff-index -p HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 diff --git a/sm1 b/sm1 new file mode 160000 index 0000000..$head1 @@ -105,6 +142,15 @@ test_expect_success 'modified submodule(forward)' ' head2=$(add_file sm1 foo3) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head1..$head2: > Add foo3 ($added foo3) EOF @@ -154,6 +200,15 @@ test_expect_success 'modified submodule(backward)' ' ) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head2..$head3 (rewind): < Add foo3 ($added foo3) < Add foo2 ($added foo2) @@ -165,6 +220,15 @@ test_expect_success 'modified submodule(backward and forward)' ' head4=$(add_file sm1 foo4 foo5) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head2...$head4: > Add foo5 ($added foo5) > Add foo4 ($added foo4) @@ -187,6 +251,15 @@ test_expect_success 'setup - change sm1 to a blob' ' test_expect_success 'typechanged submodule(submodule->blob), --cached' ' git diff --submodule=log --cached >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...0000000 (submodule deleted) diff --git a/sm1 b/sm1 new file mode 100644 @@ -220,6 +293,15 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' git checkout-index sm1 && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...0000000 (submodule deleted) diff --git a/sm1 b/sm1 new file mode 100644 @@ -238,6 +320,15 @@ test_expect_success 'nonexistent commit' ' fullhead6=$(git -C sm1 rev-parse --verify HEAD) && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..$gitmodules_hash1 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...$head6 (commits not present) EOF test_cmp expected actual @@ -436,12 +527,24 @@ test_expect_success 'deleted submodule' ' test_expect_success 'create second submodule' ' test_create_repo sm2 && head7=$(add_file sm2 foo8 foo9) && - git add sm2 + git submodule add ./sm2 && + gitmodules_hash2=$(git rev-parse --short $(git hash-object .gitmodules)) ' test_expect_success 'multiple submodules' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index $gitmodules_hash1..$gitmodules_hash2 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF @@ -460,6 +563,17 @@ test_expect_success 'given commit' ' commit_file sm2 && git diff-index -p --submodule=log HEAD^ >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index $gitmodules_hash1..$gitmodules_hash2 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF @@ -469,6 +583,17 @@ test_expect_success 'given commit' ' test_expect_success 'given commit --submodule' ' git diff-index -p --submodule HEAD^ >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index $gitmodules_hash1..$gitmodules_hash2 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF @@ -479,6 +604,17 @@ test_expect_success 'given commit --submodule=short' ' fullhead7=$(git -C sm2 rev-parse --verify HEAD) && git diff-index -p --submodule=short HEAD^ >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index $gitmodules_hash1..$gitmodules_hash2 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 diff --git a/sm1 b/sm1 deleted file mode 160000 index $head6..0000000 @@ -507,6 +643,17 @@ test_expect_success 'setup .git file for sm2' ' test_expect_success 'diff --submodule with .git file' ' git diff --submodule HEAD^ >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index $gitmodules_hash1..$gitmodules_hash2 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF @@ -525,7 +672,7 @@ test_expect_success 'diff --submodule with objects referenced by alternates' ' (cd super && git clone -s ../sub_alt sub && git init && - git add sub && + git submodule add ./sub && git commit -m "sub a" ) && (cd sub_alt && diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh index a760ed5eb6..89c5641c6b 100755 --- a/t/t4060-diff-submodule-option-diff-format.sh +++ b/t/t4060-diff-submodule-option-diff-format.sh @@ -61,9 +61,18 @@ test_expect_success 'setup repository' ' ' test_expect_success 'added submodule' ' - git add sm1 && + git submodule add ./sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 1234567..89abcde + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 0000000...$head1 (new submodule) diff --git a/sm1/foo1 b/sm1/foo1 new file mode 100644 @@ -88,6 +97,15 @@ test_expect_success 'added submodule, set diff.submodule' ' git add sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 1234567..89abcde + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 0000000...$head1 (new submodule) diff --git a/sm1/foo1 b/sm1/foo1 new file mode 100644 @@ -112,6 +130,15 @@ test_expect_success '--submodule=short overrides diff.submodule' ' git add sm1 && git diff --submodule=short --cached >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 1234567..89abcde + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 diff --git a/sm1 b/sm1 new file mode 160000 index 0000000..$head1 @@ -127,6 +154,15 @@ test_expect_success 'diff.submodule does not affect plumbing' ' test_config diff.submodule log && git diff-index -p HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 1234567..89abcde + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 diff --git a/sm1 b/sm1 new file mode 160000 index 0000000..$head1 @@ -143,6 +179,15 @@ test_expect_success 'modified submodule(forward)' ' head2=$(add_file sm1 foo3) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head1..$head2: diff --git a/sm1/foo3 b/sm1/foo3 new file mode 100644 @@ -202,6 +247,15 @@ test_expect_success 'modified submodule(backward)' ' ) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head2..$head3 (rewind): diff --git a/sm1/foo2 b/sm1/foo2 deleted file mode 100644 @@ -225,6 +279,15 @@ test_expect_success 'modified submodule(backward and forward)' ' head4=$(add_file sm1 foo4 foo5) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head2...$head4: diff --git a/sm1/foo2 b/sm1/foo2 deleted file mode 100644 @@ -271,6 +334,15 @@ test_expect_success 'setup - change sm1 to a blob' ' test_expect_success 'typechanged submodule(submodule->blob), --cached' ' git diff --submodule=diff --cached >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...0000000 (submodule deleted) diff --git a/sm1/foo1 b/sm1/foo1 deleted file mode 100644 @@ -346,6 +418,15 @@ test_expect_success 'typechanged submodule(submodule->blob)' ' git checkout-index sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...0000000 (submodule deleted) diff --git a/sm1 b/sm1 new file mode 100644 @@ -363,6 +444,15 @@ test_expect_success 'nonexistent commit' ' head6=$(add_file sm1 foo6 foo7) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + new file mode 100644 + index 0000000..2334463 + --- /dev/null + +++ b/.gitmodules + @@ -0,0 +1,3 @@ + +[submodule "sm1"] + + path = sm1 + + url = ./sm1 Submodule sm1 $head4...$head6 (commits not present) EOF diff_cmp expected actual @@ -654,12 +744,23 @@ test_expect_success 'deleted submodule' ' test_expect_success 'create second submodule' ' test_create_repo sm2 && head9=$(add_file sm2 foo8 foo9) && - git add sm2 + git submodule add ./sm2 ' test_expect_success 'multiple submodules' ' git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && + diff --git a/.gitmodules b/.gitmodules + index 2334463..8809a9f 100644 + --- a/.gitmodules + +++ b/.gitmodules + @@ -1,3 +1,6 @@ + [submodule "sm1"] + path = sm1 + url = ./sm1 + +[submodule "sm2"] + + path = sm2 + + url = ./sm2 Submodule sm1 $head7...0000000 (submodule deleted) Submodule sm2 0000000...$head9 (new submodule) diff --git a/sm2/foo8 b/sm2/foo8 @@ -716,11 +817,13 @@ test_expect_success 'given commit' ' git diff-index -p --submodule=diff HEAD^ >actual && cat >expected <<-EOF && diff --git a/.gitmodules b/.gitmodules - new file mode 100644 - index 1234567..89abcde - --- /dev/null + index 1234567..89abcde 100644 + --- a/.gitmodules +++ b/.gitmodules - @@ -0,0 +1,3 @@ + @@ -1,3 +1,3 @@ + -[submodule "sm1"] + - path = sm1 + - url = ./sm1 +[submodule "sm2"] +path = sm2 +url = bogus_url @@ -752,11 +855,13 @@ test_expect_success 'diff --submodule=diff with .git file' ' git diff --submodule=diff HEAD^ >actual && cat >expected <<-EOF && diff --git a/.gitmodules b/.gitmodules - new file mode 100644 - index 1234567..89abcde - --- /dev/null + index 1234567..89abcde 100644 + --- a/.gitmodules +++ b/.gitmodules - @@ -0,0 +1,3 @@ + @@ -1,3 +1,3 @@ + -[submodule "sm1"] + - path = sm1 + - url = ./sm1 +[submodule "sm2"] +path = sm2 +url = bogus_url diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh index d050091345..9dbd9ff266 100755 --- a/t/t7506-status-submodule.sh +++ b/t/t7506-status-submodule.sh @@ -31,7 +31,8 @@ sanitize_diff () { test_expect_success 'setup' ' test_create_repo_with_commit sub && echo output > .gitignore && - git add sub .gitignore && + git submodule add ./sub && + git add .gitignore && git commit -m "Add submodule sub" ' @@ -243,7 +244,7 @@ test_expect_success 'status -a clean (empty submodule dir)' ' ' cat >status_expect <<\EOF -AA .gitmodules +UU .gitmodules A sub1 EOF @@ -277,7 +278,10 @@ cat >diff_expect <<\EOF diff --cc .gitmodules --- a/.gitmodules +++ b/.gitmodules -@@@ -1,3 -1,3 +1,9 @@@ +@@@ -1,6 -1,6 +1,12 @@@ + [submodule "sub"] + path = sub + url = ./sub ++<<<<<<< HEAD +[submodule "sub2"] + path = sub2 @@ -293,7 +297,10 @@ cat >diff_submodule_expect <<\EOF diff --cc .gitmodules --- a/.gitmodules +++ b/.gitmodules -@@@ -1,3 -1,3 +1,9 @@@ +@@@ -1,6 -1,6 +1,12 @@@ + [submodule "sub"] + path = sub + url = ./sub ++<<<<<<< HEAD +[submodule "sub2"] + path = sub2 From patchwork Tue Feb 28 18:56:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155136 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 DACECC6FA8E for ; Tue, 28 Feb 2023 18:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbjB1S5D (ORCPT ); Tue, 28 Feb 2023 13:57:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjB1S47 (ORCPT ); Tue, 28 Feb 2023 13:56:59 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A327234025 for ; Tue, 28 Feb 2023 10:56:56 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536cb268ab8so231733157b3.17 for ; Tue, 28 Feb 2023 10:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1MkopZfLPXahIQVKEC5ptnb/+EmnusHEQ6NScH519X8=; b=W0L0xBzqkq2JgDCKnFTACMQBnjgY/hmZBJDNrUci4hj0i2VxdDNRiOr8qLl7I3EZjX /kXshHBzJIaH8XYnV10A12EUlkYdGRCHE2mtd7/Al5fvyMQ9Q+dIbNaCLpY6ruS7GE+d 0EGRhTdMDxZmPKmDlHCALkstmDgVcdnhbSVGIpWtfzHVBKrBczVVpJc4ejjwrvRxp/gC V+aSLbBi8nQEUwgYZ6cZ5bS2RgNQcoQOWvOQ3P23B9nl7CSnT2R0c75T7N8Nfy72knWu ehYBmniPyMutEMsmw3wzKmHDFS0N9lnBYJZ/6p+q+Otrxst9Drl1We4V3O6yoE6/sTl5 YKBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1MkopZfLPXahIQVKEC5ptnb/+EmnusHEQ6NScH519X8=; b=AgRKZuEA8Rcbo6QRdx6wkhZ6Dj4S7LrgVxl3U65k0fcR3J31lPCysedQv+GAO5URpd gJ0rV7SDbuhO6JG8H2tbeA/h7e/jBYEoU7qsD+w6ZaqoqDG0U3MrzB7rEhtZHZ8eb1XF /dnJ5qdnE99wCLJTsXa0PJR/Looh382EAtI9MMqsY7j4V8cwX/zNtX98wewT1zgwevrR rTocwJv44H0jw9rkA7vSm4QNJQM4henwYxGtNwzL6Wz+jdW2C2YtY4R124s5Pt2+CuTn 2/O2we+gMzjG5Psn1CjjVtu/1Xh70LA3Z5ZkVXpuxtCs/Qj2ILkSJ12i4X1pZ6DNC/Ms RNwg== X-Gm-Message-State: AO0yUKUlkNfQdd3jCuG4nM3cymgyaMTep1kj+FjVmmNrNKVj6iYh/JMJ b/d/jKVj2uu9ql2KqJZDy9Jl9saVBbpWr7AdSK2O7xm7NzHXg0iqwYK1YRsotC+ylhaV4BKnEgn 78ADihK+n8H4CodgGVJ4NfGnxcaAGQ+qG5vv/ImaDprIgyVfXNZOrz7X8a8GdrImvOA== X-Google-Smtp-Source: AK7set/YglQboLaDk2/tB5dVf0rsHp7bQTW3bJbwrGddnOw7jzyuXtCagwU1EYsvMhWY6A8MqLPYf+BX5aPC1tw= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a05:6902:1247:b0:90d:a6c0:6870 with SMTP id t7-20020a056902124700b0090da6c06870mr11329370ybu.2.1677610615796; Tue, 28 Feb 2023 10:56:55 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:40 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-4-calvinwan@google.com> Subject: [PATCH v2 4/6] tests: use `git submodule add` and fix expected status From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , peff@peff.net, gitster@pobox.com, Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Josh Steadmon This commit continues the previous work of updating the test suite to use `git submodule add` to create submodules instead of using `git add` to include embedded repositories. In this commit, we update test cases where the expected status output must change due to the presence of a .gitmodules file. We use the pre-existing expected output as a template for cases where .gitmodules has been modified but not committed. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- t/t4027-diff-submodule.sh | 17 +++-- t/t7508-status.sh | 134 ++++++++++++++++++++++++++++++++------ 2 files changed, 128 insertions(+), 23 deletions(-) diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index 40164ae07d..2ee9f18b38 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -18,7 +18,8 @@ test_expect_success setup ' test_tick && echo frotz >nitfol && - git add nitfol sub && + git add nitfol && + git submodule add ./sub && git commit -m superproject && ( @@ -122,25 +123,30 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' ' test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' ' + git branch pristine-gitmodules && git config diff.ignoreSubmodules dirty && git diff HEAD >actual && test_must_be_empty actual && git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sub && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual.body && git config -f .gitmodules submodule.subname.ignore all && git config -f .gitmodules submodule.subname.path sub && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual2 && test_must_be_empty actual2 && git config -f .gitmodules submodule.subname.ignore untracked && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual3 && sed -e "1,/^@@/d" actual3 >actual3.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual3.body && git config -f .gitmodules submodule.subname.ignore dirty && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual4 && test_must_be_empty actual4 && git config submodule.subname.ignore none && @@ -152,7 +158,7 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) git config --remove-section submodule.subname && git config --remove-section -f .gitmodules submodule.subname && git config --unset diff.ignoreSubmodules && - rm .gitmodules + git reset --hard pristine-gitmodules ' test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' ' @@ -190,12 +196,15 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' ' git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sub && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual2 && test_must_be_empty actual2 && git config -f .gitmodules submodule.subname.ignore untracked && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual3 && test_must_be_empty actual3 && git config -f .gitmodules submodule.subname.ignore dirty && + git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual4 && test_must_be_empty actual4 && git config submodule.subname.ignore none && @@ -206,7 +215,7 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) test_cmp expect.body actual.body && git config --remove-section submodule.subname && git config --remove-section -f .gitmodules submodule.subname && - rm .gitmodules + git reset --hard pristine-gitmodules ' test_expect_success 'git diff between submodule commits' ' @@ -243,7 +252,7 @@ test_expect_success 'git diff between submodule commits [.gitmodules]' ' expect_from_to >expect.body $subtip $subprev && git config --remove-section submodule.subname && git config --remove-section -f .gitmodules submodule.subname && - rm .gitmodules + git reset --hard pristine-gitmodules ' test_expect_success 'git diff (empty submodule dir)' ' diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 2b7ef6c41a..5808339997 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -892,7 +892,7 @@ test_expect_success 'setup status submodule summary' ' git add foo && git commit -m "Add foo" ) && - git add sm + git submodule add ./sm ' test_expect_success 'status submodule summary is disabled by default' ' @@ -904,6 +904,7 @@ and have 1 and 2 different commits each, respectively. Changes to be committed: (use "git restore --staged ..." to unstage) + new file: .gitmodules new file: dir2/added new file: sm @@ -931,6 +932,7 @@ test_expect_success 'status --untracked-files=all does not show submodule' ' ' cat >expect <..." to unstage) + new file: .gitmodules new file: dir2/added new file: sm @@ -998,6 +1001,7 @@ test_expect_success 'commit with submodule summary ignores status.displayComment ' cat >expect <..." to unstage) + new file: .gitmodules new file: dir2/added new file: sm @@ -1134,7 +1139,6 @@ Submodule changes to be committed: Untracked files: (use "git add ..." to include in what will be committed) - .gitmodules dir1/untracked dir2/modified dir2/untracked @@ -1152,8 +1156,37 @@ test_expect_success '.gitmodules ignore=untracked suppresses submodules with unt test_cmp expect output && git config --add -f .gitmodules submodule.subname.ignore untracked && git config --add -f .gitmodules submodule.subname.path sm && + cat > expect-modified-gitmodules << EOF && +On branch main +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: .gitmodules + modified: dir1/modified + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Untracked files: + (use "git add ..." to include in what will be committed) + dir1/untracked + dir2/modified + dir2/untracked + untracked + +EOF git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1163,7 +1196,7 @@ test_expect_success '.git/config ignore=untracked suppresses submodules with unt git config --add submodule.subname.ignore untracked && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config --remove-section -f .gitmodules submodule.subname ' @@ -1180,7 +1213,7 @@ test_expect_success '.gitmodules ignore=dirty suppresses submodules with untrack git config --add -f .gitmodules submodule.subname.ignore dirty && git config --add -f .gitmodules submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1190,7 +1223,7 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with untrack git config --add submodule.subname.ignore dirty && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' @@ -1205,7 +1238,7 @@ test_expect_success '.gitmodules ignore=dirty suppresses submodules with modifie git config --add -f .gitmodules submodule.subname.ignore dirty && git config --add -f .gitmodules submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1215,7 +1248,7 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with modifie git config --add submodule.subname.ignore dirty && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' @@ -1245,7 +1278,6 @@ Submodule changes to be committed: Untracked files: (use "git add ..." to include in what will be committed) - .gitmodules dir1/untracked dir2/modified dir2/untracked @@ -1259,8 +1291,39 @@ EOF test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" ' git config --add -f .gitmodules submodule.subname.ignore untracked && git config --add -f .gitmodules submodule.subname.path sm && + cat > expect-modified-gitmodules << EOF && +On branch main +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + (commit or discard the untracked or modified content in submodules) + modified: .gitmodules + modified: dir1/modified + modified: sm (modified content) + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Untracked files: + (use "git add ..." to include in what will be committed) + dir1/untracked + dir2/modified + dir2/untracked + untracked + +EOF git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1270,7 +1333,7 @@ test_expect_success ".git/config ignore=untracked doesn't suppress submodules wi git config --add submodule.subname.ignore untracked && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' @@ -1306,7 +1369,6 @@ Submodules changed but not updated: Untracked files: (use "git add ..." to include in what will be committed) - .gitmodules dir1/untracked dir2/modified dir2/untracked @@ -1318,10 +1380,45 @@ EOF ' test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" ' + cat > expect-modified-gitmodules << EOF && +On branch main +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: .gitmodules + modified: dir1/modified + modified: sm (new commits) + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Submodules changed but not updated: + +* sm $new_head...$head2 (1): + > 2nd commit + +Untracked files: + (use "git add ..." to include in what will be committed) + dir1/untracked + dir2/modified + dir2/untracked + untracked + +EOF git config --add -f .gitmodules submodule.subname.ignore untracked && git config --add -f .gitmodules submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1331,7 +1428,7 @@ test_expect_success ".git/config ignore=untracked doesn't suppress submodule sum git config --add submodule.subname.ignore untracked && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' @@ -1344,7 +1441,7 @@ test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary git config --add -f .gitmodules submodule.subname.ignore dirty && git config --add -f .gitmodules submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config -f .gitmodules --remove-section submodule.subname ' @@ -1354,7 +1451,7 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary git config --add submodule.subname.ignore dirty && git config --add submodule.subname.path sm && git status >output && - test_cmp expect output && + test_cmp expect-modified-gitmodules output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' @@ -1387,7 +1484,6 @@ cat > expect << EOF ; ; Untracked files: ; (use "git add ..." to include in what will be committed) -; .gitmodules ; dir1/untracked ; dir2/modified ; dir2/untracked @@ -1420,7 +1516,6 @@ Changes not staged for commit: Untracked files: (use "git add ..." to include in what will be committed) - .gitmodules dir1/untracked dir2/modified dir2/untracked @@ -1446,11 +1541,11 @@ Changes to be committed: Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) + modified: .gitmodules modified: dir1/modified Untracked files: (use "git add ..." to include in what will be committed) - .gitmodules dir1/untracked dir2/modified dir2/untracked @@ -1566,6 +1661,7 @@ Changes to be committed: Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) + modified: .gitmodules modified: dir1/modified Untracked files not listed (use -u option to show untracked files) From patchwork Tue Feb 28 18:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155137 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 09ED8C64EC7 for ; Tue, 28 Feb 2023 18:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjB1S5F (ORCPT ); Tue, 28 Feb 2023 13:57:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjB1S5B (ORCPT ); Tue, 28 Feb 2023 13:57:01 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF4BE301AA for ; Tue, 28 Feb 2023 10:56:57 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id v15-20020a17090a458f00b0023816b2f381so2622065pjg.2 for ; Tue, 28 Feb 2023 10:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8okqx69KRhetVgOni9lfppGj+2TmeavnXyZbZcLi3fg=; b=NahEo1xSXCTyA2XvtQP/69P5J79VW6qlUq7b9fjNUDvTdmla5n/GKaSQQathX4MEqr xgyXQj8OZ3ErE1zAnLlNWmPPDLxVM7FEl5oWslAswLDhmqHEDrSUykB2dSxLIuLcgveN 3df/RrOOkqI3I1dvTCJdwblN/xGNHYusbW2w8H/nMTelLy/RPSJ8yLJMeYIsFVVuXQHI H4staSKskczZlsunjhyGndSYpdwz2uUZ1ija+ry07jfh9a8QUP+98asPnSLUISW5BkJx LeJKBWSFz1xFH9QKU5GKXx+wlSQ1XzeDwyLhnywKLazjPJZtu4ynHOr3wuUIFdyy203b 0xuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8okqx69KRhetVgOni9lfppGj+2TmeavnXyZbZcLi3fg=; b=Puh1PqhoV4HBvkFaKFNQTn1qfG39CP7wrsMt5BHO/ERW3Pst12lIVM9kutws8I8D/l 7sHmMsvpW0pIyw8yBI4Cl1DN5jRPXmrEElU/tC3tiJloRXPQYiNnVKvlkre8TbbLVmPg M8nZLdVzHqvDDe5nvhJAlqndp6vUoZ6ynLzP3csuc74F1IIlcS/ybAYwSfAa8J8I3Q6W GA95d+V+AdcMi4mLxuVcVd/MClaofx6EckpMzpjgyi6x+jxl0Ye05e2/SB3NYkgt2X45 L6/ULvKI2Xfe2AFAYrXRdr5iJzQlzSMEM5GdDmkAGeYQ+DjhAif8PqUzRZZorMJbz/Je JX9w== X-Gm-Message-State: AO0yUKXMPqymURSIkKDXPS7lKYUhbPcoQ+xMuesRRI7Gpqx9Iz4pIZKN KgkbS6w4/OwoAG015ENpdB4AXYTkj3FcrNt08u08AAF1HgRoq2qFqrxJbs3Jk5uKLfnR/PgjFqg syYMISuARDR5q1fix9h20E7F5Fc7mAqy6IoAIz9CLvq+G/mRWlNOMNQQa3hifTDZ5wQ== X-Google-Smtp-Source: AK7set/R6EQKOQ7L2suV/ofv0YmiIONQ5V7GVsy/aUcLPLSYh96pcVgzA+IEzp6X8Bt7cvYYrWXL1ck7gMOeB1A= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:902:f782:b0:19a:7bd4:5b0d with SMTP id q2-20020a170902f78200b0019a7bd45b0dmr1327087pln.8.1677610617050; Tue, 28 Feb 2023 10:56:57 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:41 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-5-calvinwan@google.com> Subject: [PATCH v2 5/6] tests: remove duplicate .gitmodules path From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan , steadmon@google.com, peff@peff.net, gitster@pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Swapping `git add ` to `git submodule add ` in a previous patch created a .gitmodules file with multiple submodules pointing to the same path in certain tests. Fix tests so that they are run on the original added submodule rather than a separate manually configured submodule. Signed-off-by: Calvin Wan --- t/t4027-diff-submodule.sh | 41 ++++++-------- t/t7508-status.sh | 114 +++++++++++++++----------------------- 2 files changed, 62 insertions(+), 93 deletions(-) diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index 2ee9f18b38..ce335534b9 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -127,36 +127,33 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) git config diff.ignoreSubmodules dirty && git diff HEAD >actual && test_must_be_empty actual && - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sub && + git config --add -f .gitmodules submodule.sub.ignore none && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual.body && - git config -f .gitmodules submodule.subname.ignore all && - git config -f .gitmodules submodule.subname.path sub && + git config -f .gitmodules submodule.sub.ignore all && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual2 && test_must_be_empty actual2 && - git config -f .gitmodules submodule.subname.ignore untracked && + git config -f .gitmodules submodule.sub.ignore untracked && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual3 && sed -e "1,/^@@/d" actual3 >actual3.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual3.body && - git config -f .gitmodules submodule.subname.ignore dirty && + git config -f .gitmodules submodule.sub.ignore dirty && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual4 && test_must_be_empty actual4 && - git config submodule.subname.ignore none && - git config submodule.subname.path sub && + git config submodule.sub.ignore none && + git config submodule.sub.path sub && git diff HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual.body && - git config --remove-section submodule.subname && - git config --remove-section -f .gitmodules submodule.subname && + git config --unset submodule.sub.ignore && git config --unset diff.ignoreSubmodules && git reset --hard pristine-gitmodules ' @@ -194,27 +191,24 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' ' test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' ' - git config --add -f .gitmodules submodule.subname.ignore all && - git config --add -f .gitmodules submodule.subname.path sub && + git config --add -f .gitmodules submodule.sub.ignore all && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual2 && test_must_be_empty actual2 && - git config -f .gitmodules submodule.subname.ignore untracked && + git config -f .gitmodules submodule.sub.ignore untracked && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual3 && test_must_be_empty actual3 && - git config -f .gitmodules submodule.subname.ignore dirty && + git config -f .gitmodules submodule.sub.ignore dirty && git commit -m "Update .gitmodules" .gitmodules && git diff HEAD >actual4 && test_must_be_empty actual4 && - git config submodule.subname.ignore none && - git config submodule.subname.path sub && + git config submodule.sub.ignore none && git diff HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subprev $subprev-dirty && test_cmp expect.body actual.body && - git config --remove-section submodule.subname && - git config --remove-section -f .gitmodules submodule.subname && + git config --unset submodule.sub.ignore && git reset --hard pristine-gitmodules ' @@ -236,22 +230,19 @@ test_expect_success 'git diff between submodule commits [.gitmodules]' ' sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subtip $subprev && test_cmp expect.body actual.body && - git config --add -f .gitmodules submodule.subname.ignore dirty && - git config --add -f .gitmodules submodule.subname.path sub && + git config --add -f .gitmodules submodule.sub.ignore dirty && git diff HEAD^..HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subtip $subprev && test_cmp expect.body actual.body && - git config -f .gitmodules submodule.subname.ignore all && + git config -f .gitmodules submodule.sub.ignore all && git diff HEAD^..HEAD >actual && test_must_be_empty actual && - git config submodule.subname.ignore dirty && - git config submodule.subname.path sub && + git config submodule.sub.ignore dirty && git diff HEAD^..HEAD >actual && sed -e "1,/^@@/d" actual >actual.body && expect_from_to >expect.body $subtip $subprev && - git config --remove-section submodule.subname && - git config --remove-section -f .gitmodules submodule.subname && + git config --unset submodule.sub.ignore && git reset --hard pristine-gitmodules ' diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 5808339997..3d934bfb86 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1154,8 +1154,7 @@ test_expect_success '.gitmodules ignore=untracked suppresses submodules with unt test_config diff.ignoreSubmodules dirty && git status >output && test_cmp expect output && - git config --add -f .gitmodules submodule.subname.ignore untracked && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore untracked && cat > expect-modified-gitmodules << EOF && On branch main Your branch and '\''upstream'\'' have diverged, @@ -1187,18 +1186,16 @@ Untracked files: EOF git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore untracked && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore untracked && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config --remove-section -f .gitmodules submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' ' @@ -1210,22 +1207,19 @@ test_expect_success '.gitmodules ignore=dirty suppresses submodules with untrack test_config diff.ignoreSubmodules dirty && git status >output && ! test -s actual && - git config --add -f .gitmodules submodule.subname.ignore dirty && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore dirty && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' ' @@ -1235,22 +1229,19 @@ test_expect_success '--ignore-submodules=dirty suppresses submodules with modifi ' test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' ' - git config --add -f .gitmodules submodule.subname.ignore dirty && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore dirty && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" ' @@ -1289,8 +1280,7 @@ EOF ' test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" ' - git config --add -f .gitmodules submodule.subname.ignore untracked && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore untracked && cat > expect-modified-gitmodules << EOF && On branch main Your branch and '\''upstream'\'' have diverged, @@ -1324,18 +1314,16 @@ Untracked files: EOF git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore untracked && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore untracked && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD) @@ -1415,22 +1403,19 @@ Untracked files: untracked EOF - git config --add -f .gitmodules submodule.subname.ignore untracked && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore untracked && git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore untracked && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore untracked && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" ' @@ -1438,22 +1423,19 @@ test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summar test_cmp expect output ' test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" ' - git config --add -f .gitmodules submodule.subname.ignore dirty && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore dirty && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore dirty && git status >output && test_cmp expect-modified-gitmodules output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' cat > expect << EOF @@ -1552,22 +1534,19 @@ Untracked files: untracked EOF - git config --add -f .gitmodules submodule.subname.ignore all && - git config --add -f .gitmodules submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore all && git status > output && test_cmp expect output && - git config -f .gitmodules --remove-section submodule.subname + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' ' - git config --add -f .gitmodules submodule.subname.ignore none && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore all && - git config --add submodule.subname.path sm && + git config --add -f .gitmodules submodule.sm.ignore none && + git config --add submodule.sm.ignore all && git status > output && test_cmp expect output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success 'setup of test environment' ' @@ -1633,9 +1612,8 @@ test_expect_success 'Restore default test environment' ' ' test_expect_success 'git commit will commit a staged but ignored submodule' ' - git config --add -f .gitmodules submodule.subname.ignore all && - git config --add -f .gitmodules submodule.subname.path sm && - git config --add submodule.subname.ignore all && + git config --add -f .gitmodules submodule.sm.ignore all && + git config --add submodule.sm.ignore all && git status -s --ignore-submodules=dirty >output && test_i18ngrep "^M. sm" output && GIT_EDITOR="echo hello >>\"\$1\"" && @@ -1676,8 +1654,8 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' ' git commit -uno -m message && git status -s --ignore-submodules=dirty >output && test_i18ngrep ! "^M. sm" output && - git config --remove-section submodule.subname && - git config -f .gitmodules --remove-section submodule.subname + git config --unset submodule.sm.ignore && + git config -f .gitmodules --unset submodule.sm.ignore ' test_expect_success 'show stash info with "--show-stash"' ' From patchwork Tue Feb 28 18:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13155138 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 1487FC64ED6 for ; Tue, 28 Feb 2023 18:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjB1S5O (ORCPT ); Tue, 28 Feb 2023 13:57:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbjB1S5D (ORCPT ); Tue, 28 Feb 2023 13:57:03 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67165301BD for ; Tue, 28 Feb 2023 10:56:59 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id m18-20020a17090a7f9200b002375a3cbc9bso3304804pjl.9 for ; Tue, 28 Feb 2023 10:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2fYQcH/kJ1rUNvVb2YC9RCfJJEZVtZAfrB2GGGFDwBQ=; b=L7SyTuSpfiaqZ52krsynvj5KS03IYx0sjCsix1bqEBp3hz6m7J3SVwArnZTsEkqYmj unPOB+lzKyujY8Q9YxC92EWzRCSQDV/4UuskHFp6QKmX0ziiSNa9NnnZ9xBLlTvENdsE +GLLO6MOHG2e16epaaKZ7pg8KiKKIZAF3HiSK9TPiy01RgEoXq7iE01tAVE7lr0dhh6b g3jCk9xiL6Eb/J2cSocredXSRZjRCMCSqU3LzrLc8OGTZvWPXk3U6newTSuprfoAbLXY jN62KxTkLcQsdrkiN0ASokMudb2++GohJ4ynJ2T+pustnmVmExRUqfRC+4BAVqw6SNLZ nSzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2fYQcH/kJ1rUNvVb2YC9RCfJJEZVtZAfrB2GGGFDwBQ=; b=NJFSZWbdLgXFYbGH5oD/TmhpsnNdd5gljaliJYNXrVVyadcdqAiFHP+W+cw60sRzrI 1u8jnxAHBPitdHhnRs5VRJZJhUt/KH1sga/lNXVl896QbW/kTbwaQJNk4ECxSsHiPkQ2 7dIF15xFdQZJ5w/pgmAdrcM1NS1SOsSgEdcSwHEfhi4zbE8syvmhaMkoxFYCF+MVrmY2 OoEH8LSNiEX4160cklcphzMd9bO6ellWNOog+evxMlboYYvLMAyUhHfrrek9hou0Pgkd Q0CRPUFwaAJ8xKxGUIbaf867zmWIQXXG6ii+y18Cm0ms23X4J5itJxoQ/G5kfALv9L1C t5+w== X-Gm-Message-State: AO0yUKXIcTCek6VI2lBfKmfuWkxTSJEHzYyxoL6GVwBHblqCHAcS6kf1 nYCJuUG7XOrakwKoAc9WT7a7hg76ssAoQlamKnsCDal4UWN0lEXv6H/g9+IpGl2FPNKgK/9E9BX 0fdiECBIdbcNOqtVQ1B4ZHoWiOHOsYopyOwlfNedtr1b1Q3hPcylaUBK8qqJRaRkRxQ== X-Google-Smtp-Source: AK7set+5BQnjjDxU/NFbq5xeNrL8jYl70uIm5EoTPKVbcsc9GPoqlRgCjmOZv4p8NbEmr2H0UUFkVtkz3vKVDfQ= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a62:8747:0:b0:5a8:dc92:109f with SMTP id i68-20020a628747000000b005a8dc92109fmr1444502pfe.3.1677610618771; Tue, 28 Feb 2023 10:56:58 -0800 (PST) Date: Tue, 28 Feb 2023 18:56:42 +0000 In-Reply-To: <20230228185253.2356546-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230228185642.2357806-6-calvinwan@google.com> Subject: [PATCH v2 6/6] add: reject nested repositories From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , peff@peff.net, gitster@pobox.com, Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Josh Steadmon As noted in 532139940c (add: warn when adding an embedded repository, 2017-06-14), adding embedded repositories results in subpar experience compared to submodules, due to the lack of a corresponding .gitmodules entry, which means later clones of the top-level repository cannot locate the embedded repo. We expect that this situation is usually unintentional, which is why 532139940c added a warning message and advice when users attempt to add an embedded repo. At $dayjob, we have found that even this advice is insufficient to stop users from committing unclonable embedded repos in shared projects. This causes toil for the owners of the top-level project repository as they must clean up the resulting gitlinks. Additionally, these mistakes are often made by partners outside of $dayjob, which means that a simple organization-wide change to the default Git config would be insufficient to prevent these mistakes. Due to this experience, we believe that Git's default behavior should be changed to disallow adding embedded repositories. This commit changes the existing warning into a fatal error, rewrites the advice given, and deprecates `--no-warn-embedded-repo` in favor of `--allow-embedded-repo` to bypass the fatal error. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- Documentation/git-add.txt | 15 +++++++---- builtin/add.c | 37 +++++++++++++++++--------- builtin/submodule--helper.c | 4 +-- t/t0008-ignores.sh | 2 +- t/t2103-update-index-ignore-missing.sh | 2 +- t/t4035-diff-quiet.sh | 2 +- t/t6430-merge-recursive.sh | 2 +- t/t7400-submodule-basic.sh | 4 +-- t/t7412-submodule-absorbgitdirs.sh | 2 +- t/t7414-submodule-mistakes.sh | 29 +++++++++++--------- t/t7450-bad-git-dotfiles.sh | 2 +- 11 files changed, 61 insertions(+), 40 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index a030d33c6e..b90e305110 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -176,12 +176,17 @@ for "git add --no-all ...", i.e. ignored removed files. be ignored, no matter if they are already present in the work tree or not. ---no-warn-embedded-repo:: - By default, `git add` will warn when adding an embedded +--allow-embedded-repo:: + By default, `git add` will error out when adding an embedded repository to the index without using `git submodule add` to - create an entry in `.gitmodules`. This option will suppress the - warning (e.g., if you are manually performing operations on - submodules). + create an entry in `.gitmodules`. This option will allow the + embedded repository to be added. (e.g., if you are manually + performing operations on submodules). + +--no-warn-embedded-repo:: + This option is deprecated in favor of '--add-embedded-repo'. + Passing this option still suppresses advice but does not bypass + the error. --renormalize:: Apply the "clean" process freshly to all tracked files to diff --git a/builtin/add.c b/builtin/add.c index 76277df326..c1590129bb 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -354,6 +354,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n"); static int verbose, show_only, ignored_too, refresh_only; static int ignore_add_errors, intent_to_add, ignore_missing; static int warn_on_embedded_repo = 1; +static int allow_embedded_repo = 0; #define ADDREMOVE_DEFAULT 1 static int addremove = ADDREMOVE_DEFAULT; @@ -392,6 +393,8 @@ static struct option builtin_add_options[] = { N_("override the executable bit of the listed files")), OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo, N_("warn when adding an embedded repository")), + OPT_HIDDEN_BOOL(0, "allow-embedded-repo", &allow_embedded_repo, + N_("allow adding an embedded repository")), OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), OPT_END(), @@ -409,48 +412,53 @@ static int add_config(const char *var, const char *value, void *cb) } static const char embedded_advice[] = N_( -"You've added another git repository inside your current repository.\n" +"You attempted to add another git repository inside your current repository.\n" "Clones of the outer repository will not contain the contents of\n" "the embedded repository and will not know how to obtain it.\n" "If you meant to add a submodule, use:\n" "\n" " git submodule add %s\n" "\n" -"If you added this path by mistake, you can remove it from the\n" -"index with:\n" +"See \"git help submodule\" for more information.\n" "\n" -" git rm --cached %s\n" +"If you cannot use submodules, you may bypass this check with:\n" "\n" -"See \"git help submodule\" for more information." +" git add --allow-embedded-repo %s\n" ); -static void check_embedded_repo(const char *path) +static int check_embedded_repo(const char *path) { + int ret = 0; struct strbuf name = STRBUF_INIT; static int adviced_on_embedded_repo = 0; - if (!warn_on_embedded_repo) - return; + if (allow_embedded_repo) + goto cleanup; if (!ends_with(path, "/")) - return; + goto cleanup; + + ret = 1; /* Drop trailing slash for aesthetics */ strbuf_addstr(&name, path); strbuf_strip_suffix(&name, "/"); - warning(_("adding embedded git repository: %s"), name.buf); + error(_("cannot add embedded git repository: %s"), name.buf); if (!adviced_on_embedded_repo && - advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) { + warn_on_embedded_repo && + advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) { advise(embedded_advice, name.buf, name.buf); adviced_on_embedded_repo = 1; } +cleanup: strbuf_release(&name); + return ret; } static int add_files(struct dir_struct *dir, int flags) { - int i, exit_status = 0; + int i, exit_status = 0, embedded_repo = 0; struct string_list matched_sparse_paths = STRING_LIST_INIT_NODUP; if (dir->ignored_nr) { @@ -476,10 +484,13 @@ static int add_files(struct dir_struct *dir, int flags) die(_("adding files failed")); exit_status = 1; } else { - check_embedded_repo(dir->entries[i]->name); + embedded_repo |= check_embedded_repo(dir->entries[i]->name); } } + if (embedded_repo) + die(_("refusing to add embedded git repositories")); + if (matched_sparse_paths.nr) { advise_on_updating_sparse_paths(&matched_sparse_paths); exit_status = 1; diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 05f2c9bc98..534ed22c9e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3129,7 +3129,7 @@ static void configure_added_submodule(struct add_data *add_data) add_submod.git_cmd = 1; strvec_pushl(&add_submod.args, "add", - "--no-warn-embedded-repo", NULL); + "--allow-embedded-repo", NULL); if (add_data->force) strvec_push(&add_submod.args, "--force"); strvec_pushl(&add_submod.args, "--", add_data->sm_path, NULL); @@ -3318,7 +3318,7 @@ static int module_add(int argc, const char **argv, const char *prefix) cp.git_cmd = 1; cp.no_stdout = 1; strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing", - "--no-warn-embedded-repo", add_data.sm_path, NULL); + "--allow-embedded-repo", add_data.sm_path, NULL); if ((ret = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) { strbuf_complete_line(&sb); fputs(sb.buf, stderr); diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index c70d11bc91..a53dac5931 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -191,7 +191,7 @@ test_expect_success 'setup' ' git add a && git commit -m"commit in submodule" ) && - git add a/submodule && + git add --allow-embedded-repo a/submodule && cat <<-\EOF >.gitignore && one ignored-* diff --git a/t/t2103-update-index-ignore-missing.sh b/t/t2103-update-index-ignore-missing.sh index 11bc136f6e..1ce4fc49fa 100755 --- a/t/t2103-update-index-ignore-missing.sh +++ b/t/t2103-update-index-ignore-missing.sh @@ -36,7 +36,7 @@ test_expect_success basics ' git add file && git commit -m "sub initial" ) && - git add ./xyzzy && + git add --allow-embedded-repo ./xyzzy && test_tick && git commit -m initial && diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh index 76f8034c60..bfd87891f4 100755 --- a/t/t4035-diff-quiet.sh +++ b/t/t4035-diff-quiet.sh @@ -66,7 +66,7 @@ test_expect_success 'git diff-index --cached HEAD^' ' test_expect_success 'git diff-index --cached HEAD^' ' echo text >>b && echo 3 >c && - git add . && + git add --allow-embedded-repo . && test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt && test_line_count = 0 cnt ' diff --git a/t/t6430-merge-recursive.sh b/t/t6430-merge-recursive.sh index 07067bb347..ae435fa492 100755 --- a/t/t6430-merge-recursive.sh +++ b/t/t6430-merge-recursive.sh @@ -677,7 +677,7 @@ test_expect_success 'merging with triple rename across D/F conflict' ' echo content3 >sub2/file3 && mkdir simple && echo base >simple/bar && - git add -A && + git add -A --allow-embedded-repo && test_tick && git commit -m base && diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index eae6a46ef3..18ef9141b7 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -118,7 +118,7 @@ test_expect_success 'setup - repository in init subdirectory' ' test_expect_success 'setup - commit with gitlink' ' echo a >a && echo z >z && - git add a init z && + git add --allow-embedded-repo a init z && git commit -m "super commit 1" ' @@ -771,7 +771,7 @@ test_expect_success 'set up for relative path tests' ' git init && test_commit foo ) && - git add sub && + git add --allow-embedded-repo sub && git config -f .gitmodules submodule.sub.path sub && git config -f .gitmodules submodule.sub.url ../subrepo && cp .git/config pristine-.git-config && diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 2859695c6d..d1662aa23c 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -100,7 +100,7 @@ test_expect_success 'absorb the git dir in a nested submodule' ' test_expect_success 'setup a gitlink with missing .gitmodules entry' ' git init sub2 && test_commit -C sub2 first && - git add sub2 && + git add --allow-embedded-repo sub2 && git commit -m superproject ' diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh index 101afff30f..d38cf34dff 100755 --- a/t/t7414-submodule-mistakes.sh +++ b/t/t7414-submodule-mistakes.sh @@ -10,31 +10,36 @@ test_expect_success 'create embedded repository' ' test_commit -C embed one ' -test_expect_success 'git-add on embedded repository warns' ' - test_when_finished "git rm --cached -f embed" && - git add embed 2>stderr && - test_i18ngrep warning stderr +test_expect_success 'git-add on embedded repository dies' ' + test_must_fail git add embed 2>stderr && + test_i18ngrep fatal stderr ' -test_expect_success '--no-warn-embedded-repo suppresses warning' ' +test_expect_success '--allow-embedded-repo adds embedded repository and suppresses error message' ' test_when_finished "git rm --cached -f embed" && - git add --no-warn-embedded-repo embed 2>stderr && - test_i18ngrep ! warning stderr + git add --allow-embedded-repo embed 2>stderr && + test_i18ngrep ! fatal stderr +' + +test_expect_success '--no-warn-embedded-repo dies and suppresses advice' ' + test_must_fail git add --no-warn-embedded-repo embed 2>stderr && + test_i18ngrep ! hint stderr && + test_i18ngrep fatal stderr ' -test_expect_success 'no warning when updating entry' ' +test_expect_success 'no error message when updating entry' ' test_when_finished "git rm --cached -f embed" && - git add embed && + git add --allow-embedded-repo embed && git -C embed commit --allow-empty -m two && git add embed 2>stderr && - test_i18ngrep ! warning stderr + test_i18ngrep ! fatal stderr ' -test_expect_success 'submodule add does not warn' ' +test_expect_success 'submodule add neither fails nor issues error message' ' test_when_finished "git rm -rf submodule .gitmodules" && git -c protocol.file.allow=always \ submodule add ./embed submodule 2>stderr && - test_i18ngrep ! warning stderr + test_i18ngrep ! fatal stderr ' test_done diff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh index ba1f569bcb..4b3010c9e2 100755 --- a/t/t7450-bad-git-dotfiles.sh +++ b/t/t7450-bad-git-dotfiles.sh @@ -307,7 +307,7 @@ test_expect_success 'git dirs of sibling submodules must not be nested' ' EOF git clone . thing1 && git clone . thing2 && - git add .gitmodules thing1 thing2 && + git add --allow-embedded-repo .gitmodules thing1 thing2 && test_tick && git commit -m nested ) &&