From patchwork Mon Feb 13 18:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138818 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 57CCDC636D4 for ; Mon, 13 Feb 2023 18:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjBMSWe (ORCPT ); Mon, 13 Feb 2023 13:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbjBMSWP (ORCPT ); Mon, 13 Feb 2023 13:22:15 -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 287FB20552 for ; Mon, 13 Feb 2023 10:21:57 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id u3-20020a056a00124300b0056d4ab0c7cbso6602441pfi.7 for ; Mon, 13 Feb 2023 10:21: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=qiwvlTuxsldB+i5b7/28DCMT7O9vGrWnXDrnuVIGZz4=; b=YqM2KaRWghAIhGOO1kz5PmKuUAX+iM6kK5Gw4nvdtqgj4QNvi+TLehW60ywklNnjQ3 gDty69iWCvx5rBqP7V27Mqfvyz9E9K22ncOFn6+ljCB3qvvbqZm+frzAloJdj5Rfa50q LYMHFW/AMJuPmqiJYF+sCIs3NXGVvpiq54pYTsJzfbwdwDi99tIpiLjhS/+v53xFcpCJ tdwaADcWXQlpU6Co8rIOPVxAALUWfqtVfo4sNAk/2oEwkH9vdo3qX5/deirlTOrSinp+ Qnzahl5zWjZ2gweMVsppT3OZ3dpW6ooFt+wNh3aidh+c0eaSp+7iZPe5vQQcvlcAIJnc 2JBw== 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=qiwvlTuxsldB+i5b7/28DCMT7O9vGrWnXDrnuVIGZz4=; b=tLeKCKW4RG8Ez3CzL4baIIbNdgbUQjIc69nztNQeLoFADIqJ4qIBpovNCNfHQwmwti uwLXjB6TcvY4hbF33F1KoNkDy1MihQMhbl2JoKOE25JL3xNwS7aqZceuFb/MgVdBORnT s9UtZ0Aam1y90yeuETKKSCGZDx02cOFgvXJRQR7I3BeX4D9xplVFeXLhcV8+jhIwHU2j Y5adSgMaU5F1/SV1raJkdAMDckgYDLQWPzbMCwNQTZkcm1aMGBTG8TU9COTRKnQIYJPw iCD17C+VnjixVLtOsKUTc8pEQ1VzLJ5FjMLTQI1/0Vhxns0ONpnHK3QI8NFz0N+7mY1o CvLQ== X-Gm-Message-State: AO0yUKU0K8MhnFBE1dqR8gJOOs5N5+gYGwLT+vOzt1PTXqsbvFjHowQZ kgpqrYGTZnnCWj9Nu/U/tqehVasBLKz50L5FVhLaPABbTBE25mtBCbX2cfHVl/wu/U7/dM1AIon sdbPJYIDA+W9+2LE/dJ+uYVbQAcwYrzWrdGlE6J238HKYGD+kO7+z35VTrxIlzcpqNg== X-Google-Smtp-Source: AK7set/dUg8eBVfgscikZyRosRSATGg8k3iBqkYo9p6TDLSls9X2L2/pBiTsl1wKxbWYPlve55s9in1HL6jf2QE= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:aa7:9551:0:b0:5a8:d638:584f with SMTP id w17-20020aa79551000000b005a8d638584fmr110858pfq.2.1676312516404; Mon, 13 Feb 2023 10:21:56 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:29 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-2-calvinwan@google.com> Subject: [RFC PATCH 1/6] leak fix: cache_put_path From: Calvin Wan To: git@vger.kernel.org Cc: Calvin Wan Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org hashmap_put returns a pointer if the key was found and subsequently replaced. Free this pointer so it isn't leaked. Signed-off-by: Calvin Wan --- submodule-config.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/submodule-config.c b/submodule-config.c index 4dc61b3a78..90cab34568 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -128,9 +128,11 @@ static void cache_put_path(struct submodule_cache *cache, unsigned int hash = hash_oid_string(&submodule->gitmodules_oid, submodule->path); struct submodule_entry *e = xmalloc(sizeof(*e)); + struct hashmap_entry *replaced; hashmap_entry_init(&e->ent, hash); e->config = submodule; - hashmap_put(&cache->for_path, &e->ent); + replaced = hashmap_put(&cache->for_path, &e->ent); + free(replaced); } static void cache_remove_path(struct submodule_cache *cache, From patchwork Mon Feb 13 18:21:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138823 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 D4A93C636CC for ; Mon, 13 Feb 2023 18:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbjBMSWq (ORCPT ); Mon, 13 Feb 2023 13:22:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbjBMSWR (ORCPT ); Mon, 13 Feb 2023 13:22:17 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6140D1A96E for ; Mon, 13 Feb 2023 10:22:02 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id u18-20020a62ed12000000b00593cc641da4so6593235pfh.0 for ; Mon, 13 Feb 2023 10:22:02 -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=3pAvTQVWuv+/Z8mP2TbPKDUkmBy5TW9DXOvSb/zWsYc=; b=cUVgrKjh9A9W0g94C84aaz9EN21aMVnf9l7gRc4fWHFL7AyaaY7vrZvSD6oV1lu8Xn /7N2mVZJmIyyliEWN1+3FvdLO4Ui1RddIfVPANYZpjEDZ7B80RFTWFVBWNt3o2sf1WCU SSCuLvVxnT2TXEkC6j3+8E7x/pPdtctNiZl7vG8I+7Inqu/5vglpeGpjK7QVJ0kkOs58 ddeKZJTFyJ6jI7swkxY4KaIT9l3PAZuOwCDD4GYEbZoz2SH4W+VLz4q+SYTO6O9+gGoq QWlpoiAduUbNAhASxzcj0Q+kICSel9YsLpPEIdgjVeIxZtaMW0Zrr/eaRkqZyQXsxZE7 ciKg== 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=3pAvTQVWuv+/Z8mP2TbPKDUkmBy5TW9DXOvSb/zWsYc=; b=br2bm8uv84rCcqqR6qkf2ZcaPk6skqQG/DBs3EAryLZtoYodMBgvxcOEmmpJVcGvqz si0eyJdhsKdexdYYzg46CQhDN1saMM025nFkG+rAmR352J6l6MdXg6HEC593dFzCkGge 8FYX2eVJvNQwwAn5OCA/GgRSktvUJmAgwxl3xczF7yHGHr/zISsD+YCRrm/GGMdPmkFi pm+JH9E2KhWLGrgqfP9P3kHYmOHxFY6C7ptVZbIATi8QveGrZGCG77yPxpT89UablT8Y VuNQLTVz/oPO2gztaHbsdgdGRDKEpwKAJDuVopTqb+9GqE4XOwkrsSOJ5Kn5J941+evO GErw== X-Gm-Message-State: AO0yUKXE52eux5z93kFKtZvfOFeTCBtUdkHVyW7EfsnMUiYP9MdhVBc4 sfUhw+whOkvV/4s84CHSwLsL4pBs4R52FdmINR5riF/7K4g3hPDUH8vS98w+ahOJggP+eOwhH4y UlkimGrWPelMjcO3gCYZ4otMdrrq5H+njSRXeQE/PWxiGw8zH9q98d95iOKSMMJiFhw== X-Google-Smtp-Source: AK7set+R8/T77/Rhy5DhstWdw/gDGgY+LcYC7MRrxuXqSdscUJcwl44J8I6aB9vzxGkL7UTcXjlXsLmD6ZObDeU= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:90a:51c3:b0:233:af25:85f6 with SMTP id u61-20020a17090a51c300b00233af2585f6mr301359pjh.1.1676312521338; Mon, 13 Feb 2023 10:22:01 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:30 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-3-calvinwan@google.com> Subject: [RFC PATCH 2/6] t4041, t4060: modernize test style From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , 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. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- t/t4041-diff-submodule-option.sh | 75 +++++++-------- t/t4060-diff-submodule-option-diff-format.sh | 99 ++++++++++---------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 0c1502d4b0..556682b18b 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 >/dev/null && + head1=$(add_file sm1 foo1 foo2) && + fullhead1=$(cd sm1 && git 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=$(cd sm1 && git 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 && @@ -212,9 +214,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)' ' + rm -rf sm1 && + git checkout-index sm1 && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head4...0000000 (submodule deleted) @@ -229,11 +231,11 @@ 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' ' + rm -f sm1 && + test_create_repo sm1 && + head6=$(add_file sm1 foo6 foo7) && + fullhead6=$(cd sm1 && git 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 ' @@ -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: @@ -422,8 +424,8 @@ test_expect_success 'modified submodule contains modified content' ' test_cmp expected actual ' -rm -rf sm1 test_expect_success 'deleted submodule' ' + rm -rf sm1 && git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) @@ -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=$(cd sm2 && git 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..3cda8ffd14 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=$(cd sm1 && git rev-parse --verify HEAD) && git diff --submodule=short >actual && cat >expected <<-EOF && diff --git a/sm1 b/sm1 @@ -195,14 +194,13 @@ 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=$( + cd sm1 && + git reset --hard HEAD~2 >/dev/null && + git rev-parse --short --verify HEAD + ) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): @@ -224,8 +222,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 +259,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 && @@ -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)' ' + rm -rf 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,10 @@ 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' ' + rm -f sm1 && + 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 +369,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 +399,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 @@ -492,9 +492,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' ' + (cd sm1 && git commit -mchange foo6 >/dev/null) && + head8=$(cd sm1 && git rev-parse --short --verify HEAD) && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7..$head8: @@ -643,8 +643,8 @@ test_expect_success 'modified submodule contains modified content' ' diff_cmp expected actual ' -rm -rf sm1 test_expect_success 'deleted submodule' ' + rm -rf sm1 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7...0000000 (submodule deleted) @@ -703,13 +703,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 +781,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 +805,8 @@ 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' ' + echo submodule-to-blob>sm2 && git diff-index -p --submodule=diff HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head7...0000000 (submodule deleted) @@ -836,10 +836,9 @@ 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' ' + rm sm2 && + mv sm2-bak sm2 && git -c protocol.file.allow=always -C sm2 submodule add ../sm2 nested && git -C sm2 commit -a -m "nested sub" && head10=$(git -C sm2 rev-parse --short --verify HEAD) @@ -910,13 +909,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=$(cd sm2 && git 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 +968,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 Mon Feb 13 18:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138819 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 4EF1AC64EC7 for ; Mon, 13 Feb 2023 18:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjBMSWf (ORCPT ); Mon, 13 Feb 2023 13:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbjBMSWV (ORCPT ); Mon, 13 Feb 2023 13:22:21 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E413220073 for ; Mon, 13 Feb 2023 10:22:06 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id z8-20020a170902834800b001990ad8de5bso7770740pln.10 for ; Mon, 13 Feb 2023 10:22:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1676312526; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nh4j4y0rRE6Y7+356e1tgpoREu4tfQKkql0MR4ZIT94=; b=BRiOCIMo+qzr0DCM05GtC5C4Fl0wo0ua6KqpMKcVtwjGTXqMIvDoQMdEAa28y5kq6/ FUVmJNUqGt1zURZCN8XRsjQ5cK8ND1CxL1fpV0INkQ3s/MLeOz0h88wSiMFPRUf2aIMg p7enlXe2B1Qx1eWuJCXIP9EV2zMLMG+742jZWly/69KDuCULjcWqZYT+S5rnPYde+W5r nJSHbPnnr5wVGqpgxEFZ6GaIi/+xAYxqrDQhGJjNFNUqgb85aigpTBgDA+21tMBzrWEG b0CHDrFtacP/hLVtS3uBALLa7aCUuOqa/aIuoTGZZMjnqhSHfIWM2Nn3Gr/VeW/SiWXr 2ikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676312526; 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=nh4j4y0rRE6Y7+356e1tgpoREu4tfQKkql0MR4ZIT94=; b=BcsMgHuSV6VhI5aBQffggwMPIqMvhMsfyUhASCPYMbiWXWS28iY4UNYI+Fq3wznf3T idOIK2Xvm/Ief3HSXCwAYbLo0I/LxVdMZomWqjUqUeTzUl4E0x8j+jRJiDNtFWOQIuqp hc7dTKoOMWLfRZSpBp4/45BCU+o++KW6E8iSHOzdqp9nj/5xaqDvOHXj3c6ghOy7HdBo vFe7n70pzMgKOj4mjKcfWNVHEf0EjhJuh5jVRNyLzTMkypnCZIrLn9y48VDy3kRmJZG5 +6s2+E4R/PjzD8ioH87BJUYbZGcoPQpbyA+MZr8x9LA2pIAgJlQElkM9yltCHq4V8Q6P iOLg== X-Gm-Message-State: AO0yUKWa3ixHY1zZtbfXSdiFqho4oi65o0Dle7Bko/6J1ANTLuIUQgPp AzrFVNLpgJgCSAvFPkx0tYVQp3MQOhMZYXMC55avyhUT5fylOYQS0YcuXIewplR1x6KBaqTnyDo Ou+a2FjaS3g63O2MCWZkC+vq4lYGko3pB0/bnmd4mJTXmCvFjliszttsaesemlNclqw== X-Google-Smtp-Source: AK7set+S8+7ggp++x0rDf8F1Jp9Xx8fI2SmJ0Zuo6MyHB2VRo5GucYFUkZvYFbi/w9JiFAedIr7fYqhY5LUN8TY= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:902:db0f:b0:198:e13d:a05d with SMTP id m15-20020a170902db0f00b00198e13da05dmr5797918plx.12.1676312526349; Mon, 13 Feb 2023 10:22:06 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:31 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-4-calvinwan@google.com> Subject: [RFC PATCH 3/6] tests: Use `git submodule add` instead of `git add` From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , 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/t0008-ignores.sh | 2 +- 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/t4035-diff-quiet.sh | 1 + t/t5531-deep-submodule-push.sh | 4 ++-- t/t6416-recursive-corner-cases.sh | 12 ++++++------ t/t6430-merge-recursive.sh | 1 + t/t6437-submodule-merge.sh | 12 ++++++------ t/t7401-submodule-summary.sh | 4 ++-- t/t7402-submodule-rebase.sh | 2 +- 17 files changed, 35 insertions(+), 28 deletions(-) diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index c70d11bc91..ea58d415ba 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 submodule add ./a/submodule ./a/submodule && cat <<-\EOF >.gitignore && one ignored-* 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..f43a57350c 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 submodule 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/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh index 76f8034c60..23ef222006 100755 --- a/t/t4035-diff-quiet.sh +++ b/t/t4035-diff-quiet.sh @@ -66,6 +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 submodule add ./test-outside/repo ./test-outside/repo && git add . && test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt && test_line_count = 0 cnt 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/t6430-merge-recursive.sh b/t/t6430-merge-recursive.sh index 07067bb347..8962db8faa 100755 --- a/t/t6430-merge-recursive.sh +++ b/t/t6430-merge-recursive.sh @@ -677,6 +677,7 @@ test_expect_success 'merging with triple rename across D/F conflict' ' echo content3 >sub2/file3 && mkdir simple && echo base >simple/bar && + git -c protocol.file.allow=always submodule add ./sym && git add -A && test_tick && git commit -m base && 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 Mon Feb 13 18:21:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138820 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 7CEB4C636D4 for ; Mon, 13 Feb 2023 18:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230517AbjBMSWh (ORCPT ); Mon, 13 Feb 2023 13:22:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjBMSWW (ORCPT ); Mon, 13 Feb 2023 13:22:22 -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 83B2A20689 for ; Mon, 13 Feb 2023 10:22:09 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id cd27-20020a056a00421b00b005a87bcb8a5cso4199979pfb.12 for ; Mon, 13 Feb 2023 10:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1676312529; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rcUa+ydeHBptl3Zvwcwox1kNmUkeDe015LzvshtpHLk=; b=tPpQ0a/Y/VhZGYQ5oSYPcICjRfX0MGHbX3n9HxWDIVemgTVc3dl0XQUDFK9eXNAz/T Lp8xfBCQYk7XQmU6c9uyXLndBEFmiYffMh//vR7+RqcIst6Ec7FGJgByHOM8tdhoQhhp NKkC90h3Mft6NLwXxiVJgFg0a0XX0YdNp8dlOtQLPRn+RSk5YPC1LY0cqCDLLatF/5SY rpCguQoc/N8n0jirOHbuV9/kESwP6LmjKgs0X0J7OLKUJTAwHHvOxTnJstUk3VbKINot 6f/En1zProVjDAM+wVXyR7BdKsc13/jOETxbR7knGe81PZRgLKlW9kBlZ2ioclHUF4/r n+dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676312529; 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=rcUa+ydeHBptl3Zvwcwox1kNmUkeDe015LzvshtpHLk=; b=4/dtzx70PVDch9s4ubHlT312bXlnvMKZIqCZ7h0i9nHl7yuKjwz9m7MNIB0uigzn63 NspfrkwLctPbiLArblFReFqGDRsmSlQrmEMaYU/LSP+WXdt2kaKi34M8PF9x5E41MJRD nUFvojpCrtmV4op5oaM8E2E5WX04tifzKgzlN2OOw8rBTxBXlBiHzKCAPtdaNsFeAe2B D6FVbfgWh2NftrprwsOJxOs9ecmy0lHnsMdgaWDmxjX3YXB5igHq3opr6ZWMC5smGYlq 277QZ3O9lNskllymqD39o9SIU+/hwF8QoUn16CbGQfmTKRNp4Ld6x3I1HHfEjERyhhW7 moYA== X-Gm-Message-State: AO0yUKVuRInSOzufdGgJRHIpHXh9z6PUngjccvx+u4zqynfbB0t0ar6T FsBkXd0QHhm2MwnMc8xWcfmFt/HUzjdKWBnoFv8SWD1prHaJdGQlfWQMJlXGQQpDgGghKfPxeqY qa1lWQFJQPSJRXksUO5EsY5Od35WUTEeZSZLLvxcuegjfMmYhDe+SnzKi6y1mFn4yFQ== X-Google-Smtp-Source: AK7set+Cm9n5NWrGR8aRvYzFmHCYlBY3gku+6Z1C55M5GymE6sRHX/P0e9mhLJS16gyBjz4i8B4K/ZNsTPZ28qU= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a17:902:7289:b0:199:1852:d21 with SMTP id d9-20020a170902728900b0019918520d21mr6290059pll.0.1676312528931; Mon, 13 Feb 2023 10:22:08 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:32 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-5-calvinwan@google.com> Subject: [RFC PATCH 4/6] tests: use `git submodule add` and fix expected diffs From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , 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 556682b18b..6c666d2b7a 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 @@ -219,6 +292,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=$(cd sm1 && git 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=$(cd sm2 && git 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 3cda8ffd14..6bee3ac628 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 @@ -203,6 +248,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 @@ -226,6 +280,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 @@ -272,6 +335,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 @@ -364,6 +445,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 @@ -655,12 +745,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 @@ -717,11 +818,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 @@ -753,11 +856,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 Mon Feb 13 18:21:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138821 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 35F51C636CC for ; Mon, 13 Feb 2023 18:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231271AbjBMSWk (ORCPT ); Mon, 13 Feb 2023 13:22:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbjBMSW0 (ORCPT ); Mon, 13 Feb 2023 13:22:26 -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 F2236199EC for ; Mon, 13 Feb 2023 10:22:11 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id h11-20020a17090adb8b00b00233cde95f87so3562221pjv.9 for ; Mon, 13 Feb 2023 10:22:11 -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=UIXNxru0UF2Rv0J4xEkgtDeaLbMVDvXFb3u7iw7mSH4=; b=lsWRY98Zj//daooWqGbiiH4jt91t6y9DmFrxgg0I+Z4iCAIckPnl3ULi9C7xex3cyX uGEZVqDvlVulmJP7GW/U9vRqObl00vnC5rTDb+po5XE9GSt3tk4V8j9tgz7mFTHycZhe VJsaF+DZr4OVn+87vP4Phr8h4ZSTBab3KAcmMRjJf5g7BwTyg4X0xOVM0GgWKWGTZKKh zWNgTge1NjZUxA2/70v06fXct67/M5o319IM5Lg3JUg5rbUxjI/cH6zOCcgsNuSLh5x/ 4iH+aJa0zytG5OTc+50uHFSfYcFd0anyGSwwxTgBcuLDAmf4IwRzxRv0okilXZMtoQcE HI4g== 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=UIXNxru0UF2Rv0J4xEkgtDeaLbMVDvXFb3u7iw7mSH4=; b=1h18yCzLx7WsieaHXZg/cNJszOCd4A1svjweEQraqTHesqyp4ZA3sD05U5McD6f2wq 04zhC8zXek6fFnaQMziTdg8RJMklzbA1vtjjfdYWf7NivnAmskP+IJRUdCSU2UTEklH9 K+UsaJWU+PdXkJNUGMbWJHVkF/OK9L9HmLGAlUDxQ17caXD30PY2yFTqAApC+yM10SGN KvFnyPwcQz6isIHyXl3wc6dvGC5F5i7SvRzbgcQL798pUFBcDxiEztwM3SoppRQA8Dle t0wf1DjEfdneCEVz1HLL5+Dj3WWP4EKuNLAT+DxXwewxIaeUJ97ZceXop1TaB2bH0QpZ Em6Q== X-Gm-Message-State: AO0yUKWi/9B7AcWes0vGeN9yeMEOW6rE1DDDRxUJ27/KEAc66L9fqrQ+ hf3ve36RtigsCV/f51MftyfKWABZfG50VZy8OTEPTWhf7/iElzIlUg1nna90ELziEBf2UwEfvbr fCGHZ9uaYk0LDyYxBD3ZWB+XmJys9isYwMy4Qn8Rqvcn6XMny+UmvU5FtTgMVKJoVnA== X-Google-Smtp-Source: AK7set92qnjSkVqelc1ZjFrDgKrFGQeE2lit5nwlgXobsb4ka32mkYl9SL2tlli6XLaBAkFF6z7tHoFcsXmDn24= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:aa7:9576:0:b0:5a8:ab92:d78d with SMTP id x22-20020aa79576000000b005a8ab92d78dmr1017655pfq.22.1676312531366; Mon, 13 Feb 2023 10:22:11 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:33 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-6-calvinwan@google.com> Subject: [RFC PATCH 5/6] tests: use `git submodule add` and fix expected status From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , 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 Mon Feb 13 18:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Wan X-Patchwork-Id: 13138822 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 CF2F0C636D4 for ; Mon, 13 Feb 2023 18:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbjBMSWl (ORCPT ); Mon, 13 Feb 2023 13:22:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231320AbjBMSW0 (ORCPT ); Mon, 13 Feb 2023 13:22:26 -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 26108206B2 for ; Mon, 13 Feb 2023 10:22:14 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id pj9-20020a17090b4f4900b00232cca91108so5011319pjb.7 for ; Mon, 13 Feb 2023 10:22:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1676312533; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ggoJOO2GA5Q5f8At6jIma7siMSH6HvKvh/4fysEYNoM=; b=Emcr6FeD2p7kr2bH9TEdXi4kRMyHWcpTKAr8r9dpa9rxtRBMWZageiRRDAogDq4and 1EibYRPz0hGCbnIagjOxqRt5DuD1V9rcoW5SXEp6bb+t7Qg6fr4gAlGynbtQ2BWDfgiJ yUquvKsUpN1z8mzhD9WRlODC932HNSjHxqhoWwtjU+pCNJeAytvrpETES+JWUVdcEmsL m4hPC9t33czy7nSmOhPW5hd4kUvx2lvlLMh5IA3XZED0Trovk+cjfzp0OLuH9Hf0wkhl 5IsJ1XXFejKpJhCtZPnYiUBcyyF7ZoasROEPjpFYhULejQQh5LReMC9qz5jFH23w1E+b mZLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676312533; 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=ggoJOO2GA5Q5f8At6jIma7siMSH6HvKvh/4fysEYNoM=; b=Y1QXbUg+XsWvmAHTK/GCEHp/OS7FZfLl8zQis7raZu/P6LHYglI4z9awLKxbDCZYrn bTMKdlE/yx30JJX0az5F6vXif92Hwo1nl0MRA2O3S9XRIZMzwQ+Rg1OGgy5wFWKmLtZi yJgQ5RQZ/gsQha82/B/IQLAjzS1qQulgt0arEdV4fZpmmaCP4jJJUD1Pv4LOOVmyoo08 dGATGnLs/mdR2U3n8EqrmuWlD7Gne9HSDBQFYvIP3wKam45bi2pZpWG6n8k7+jZCw3dY Dwn4Rcn90le+IBDu3TkVABAVr/8trBcf4vGAPEE/bwqQ8eKR5/8AW8TEOrO9aCm7CRMI eZ7A== X-Gm-Message-State: AO0yUKWFsyVnQ21E329sNCilGKBPgvCwe3SYTHP+eGFdhJXJ/w2PTVBC z6dVSW2CxeSDNOpZ+GxAEOzr1ErnHJcCxw+yxnToHfCCInRaN7ecevSoBLPIeWI5HYPALTvLEFs 7PpYYmjJEvSFi9jLc4+wUwZEvWJ0loqYNd2/YrNO2ICj55Hd8sXVqPT+8P1xcSLgg/w== X-Google-Smtp-Source: AK7set/RY9vFz/r8wB0N/V/CdPkGxzMExke4C24D01Dhz6JdlIQ6Tt71AyaonzAnfRlQFpz8arM6e/MXpfgCP5s= X-Received: from barleywine.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3bd4]) (user=calvinwan job=sendgmr) by 2002:a62:4ed7:0:b0:5a8:b6e2:a3fe with SMTP id c206-20020a624ed7000000b005a8b6e2a3femr983368pfb.41.1676312533521; Mon, 13 Feb 2023 10:22:13 -0800 (PST) Date: Mon, 13 Feb 2023 18:21:34 +0000 In-Reply-To: <20230213182134.2173280-1-calvinwan@google.com> Mime-Version: 1.0 References: <20230213182134.2173280-1-calvinwan@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213182134.2173280-7-calvinwan@google.com> Subject: [RFC PATCH 6/6] add: reject nested repositories From: Calvin Wan To: git@vger.kernel.org Cc: Josh Steadmon , 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 while preserving the `--no-warn-embedded-repo` flag as a way to bypass this check. Signed-off-by: Josh Steadmon Signed-off-by: Calvin Wan --- Documentation/git-add.txt | 7 ++++--- builtin/add.c | 28 ++++++++++++++++++++-------- t/t7400-submodule-basic.sh | 4 ++-- t/t7412-submodule-absorbgitdirs.sh | 2 +- t/t7414-submodule-mistakes.sh | 21 ++++++++++----------- t/t7450-bad-git-dotfiles.sh | 2 +- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index a030d33c6e..b7fb95b061 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -177,10 +177,11 @@ for "git add --no-all ...", i.e. ignored removed files. tree or not. --no-warn-embedded-repo:: - By default, `git add` will warn when adding an embedded + 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 + create an entry in `.gitmodules`. This option will allow the + embedded repository to be added and suppress the error. + (e.g., if you are manually performing operations on submodules). --renormalize:: diff --git a/builtin/add.c b/builtin/add.c index 76277df326..795d9251b9 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -421,36 +421,45 @@ static const char embedded_advice[] = N_( "\n" " git rm --cached %s\n" "\n" -"See \"git help submodule\" for more information." +"See \"git help submodule\" for more information.\n" +"\n" +"If you cannot use submodules, you may bypass this check with:\n" +"\n" +" git add --no-warn-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; + 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)) { - advise(embedded_advice, name.buf, name.buf); + advise(embedded_advice, name.buf, 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 +485,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/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index eae6a46ef3..e0bcecba6e 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 --no-warn-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 --no-warn-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..365953b558 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 --no-warn-embedded-repo sub2 && git commit -m superproject ' diff --git a/t/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh index 101afff30f..dbdcbe909d 100755 --- a/t/t7414-submodule-mistakes.sh +++ b/t/t7414-submodule-mistakes.sh @@ -10,31 +10,30 @@ 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 '--no-warn-embedded-repo suppresses error message' ' test_when_finished "git rm --cached -f embed" && git add --no-warn-embedded-repo embed 2>stderr && - test_i18ngrep ! warning 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 --no-warn-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 does not issue 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..6fbcf36ae9 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 --no-warn-embedded-repo .gitmodules thing1 thing2 && test_tick && git commit -m nested ) &&