From patchwork Tue Apr 2 18:35:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Meyer X-Patchwork-Id: 10882197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C5991575 for ; Tue, 2 Apr 2019 18:35:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7938E288F7 for ; Tue, 2 Apr 2019 18:35:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BDBB2891F; Tue, 2 Apr 2019 18:35:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 099D3288F7 for ; Tue, 2 Apr 2019 18:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729267AbfDBSfo (ORCPT ); Tue, 2 Apr 2019 14:35:44 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:54495 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbfDBSfn (ORCPT ); Tue, 2 Apr 2019 14:35:43 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 65FC864EC5; Tue, 2 Apr 2019 14:35:40 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=lsvJO3KIHXPZ1P2FYbyzi85L0 30=; b=fZI6UdFDbofwuIukI4eY+Gl27cvsOk8IQa6xlikYOL7hlFNSs5bG/OYUU IRKR3zEf0eUXZRw0D7IfhlPYpLTPt12NSAOuaD+I/ApDCi1f69BFovzLy8XH5uyF jmH28rfBP8hh8Aq9ytf/wP6v+T5EFLhwACjBTo1N9NN9jqyTLE= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 5E6DE64EC4; Tue, 2 Apr 2019 14:35:40 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=zJgdVAjOhgYSSUb3wZjjOLg+g5FRpWul5ne+s250Rhg=; b=bY0m17NAX5SkfMsGQZGUeVCyjE8RYK7R2cBCzUCw7ZwFpvue25tcc4jEUekYR/i/FZ5/Zg2pyEU65VjpVsi33AQl1BidM4cwU2qzNzKQsT6dlIZrgxzHj4YH2/ZuQ08Myx+hK6Dx6DbszC4zEUcSHeM5xscgmbZHuTZUfxMqqmE= Received: from hylob.dartmouth.edu (unknown [129.170.31.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 92C9F64EC1; Tue, 2 Apr 2019 14:35:36 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Kyle Meyer , git@vger.kernel.org Cc: debian@onerussian.com Subject: [PATCH v2 1/4] submodule: refuse to add repository with no commits Date: Tue, 2 Apr 2019 14:35:02 -0400 Message-Id: <20190402183505.31512-2-kyle@kyleam.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402183505.31512-1-kyle@kyleam.com> References: <87lg1eq146.fsf@kyleam.com> <20190402183505.31512-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 1C285DFC-5576-11E9-ABEB-EE24A11ADF13-24757444!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the path given to 'git submodule add' is an existing repository that is not in the index, the repository is passed to 'git add'. If this repository doesn't have any commits, we don't get a useful result: there is no subproject OID to track, and any untracked files in the sub-repository are added to the current repository. Detect if the path is a repository with no commits and abort to avoid getting into this state. Note that this check must come before the 'git add --dry-run' check because an upcoming commit will make 'git add' fail in this situation. Signed-off-by: Kyle Meyer --- git-submodule.sh | 7 +++++++ t/t7400-submodule-basic.sh | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/git-submodule.sh b/git-submodule.sh index 514ede2596..5a9dc9bf7e 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -231,6 +231,13 @@ cmd_add() die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")" fi + if test -d "$sm_path" && + test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null) + then + git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null || + die "$(eval_gettext "'\$sm_path' does not have any commits")" + fi + if test -z "$force" && ! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1 then diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index aba2d4d6ee..6adf640143 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -46,6 +46,15 @@ test_expect_success 'submodule update aborts on missing gitmodules url' ' test_must_fail git submodule init ' +test_expect_success 'add aborts on repository with no commits' ' + cat >expected <<-\EOF && + '"'repo-no-commits'"' does not have any commits + EOF + git init repo-no-commits && + test_must_fail git submodule add ../a ./repo-no-commits 2>actual && + test_i18ncmp expected actual +' + test_expect_success 'setup - repository in init subdirectory' ' mkdir init && ( @@ -809,7 +818,7 @@ test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.gi cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && mkdir -p a/b/c && - (cd a/b/c && git init) && + (cd a/b/c && git init && test_commit msg) && git config remote.origin.url ../foo/bar.git && git submodule add ../bar/a/b/c ./a/b/c && git submodule init && From patchwork Tue Apr 2 18:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Meyer X-Patchwork-Id: 10882199 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 452DF1575 for ; Tue, 2 Apr 2019 18:36:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32D3228918 for ; Tue, 2 Apr 2019 18:36:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26D5528929; Tue, 2 Apr 2019 18:36:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBC028918 for ; Tue, 2 Apr 2019 18:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729272AbfDBSf6 (ORCPT ); Tue, 2 Apr 2019 14:35:58 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:63174 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbfDBSf6 (ORCPT ); Tue, 2 Apr 2019 14:35:58 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 8DF4364EC9; Tue, 2 Apr 2019 14:35:53 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=/zXPjEN6fy8KAleL/49vkFad2 mE=; b=o68Q50NYhXs5hOcchwEyHwRykE/YPF2uvrsFgyNCfqEwFY5GTUpjNUafj x+tpo3EVt2O6FDAiKEr1DaUf0eZLkgyRW+Z7r0H723x4MGx9PxJjnpzvZ9fdQKo6 X2uSqVICjTOenWNnS09dTCGqABRwWWMeoMVY8CP/j2oUbmRjuI= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 8721A64EC8; Tue, 2 Apr 2019 14:35:53 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=HQWqSnKUq9mnZy+XYe3QbiEcs2ioWpwtOwXJU6NAABY=; b=VdbtahI5oyOzjblV/ux+JpN0FyeMOQu5jkqpwple+CtCEonFS+AVnLYa/f5VxpfdP9JrH//dbj76qLvSrlRPk7RTROGclHlI4uGBPccwLRi1J3ScuJeCQpzigzY2qk94vx1XbnY0oDlEWURX+tNSm200JdLH4/pHS+/8QNNpg60= Received: from hylob.dartmouth.edu (unknown [129.170.31.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id B809864EC6; Tue, 2 Apr 2019 14:35:49 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Kyle Meyer , git@vger.kernel.org Cc: debian@onerussian.com Subject: [PATCH v2 2/4] t3000: move non-submodule repo test to separate file Date: Tue, 2 Apr 2019 14:35:03 -0400 Message-Id: <20190402183505.31512-3-kyle@kyleam.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402183505.31512-1-kyle@kyleam.com> References: <87lg1eq146.fsf@kyleam.com> <20190402183505.31512-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 23FF5954-5576-11E9-B220-EE24A11ADF13-24757444!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP a2d5156c2b (resolve_gitlink_ref: ignore non-repository paths, 2016-01-22) added a test to t3000-ls-files-others.sh to check that 'ls-files -o' does not die() when given a subdirectory that looks like a repository but is actually a subdirectory containing a bogus .git file. Move this test to a separate file in preparation for testing scenarios with non-submodule repositories that are not bogus. Signed-off-by: Kyle Meyer --- t/t3000-ls-files-others.sh | 7 ------- t/t3009-ls-files-others-nonsubmodule.sh | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100755 t/t3009-ls-files-others-nonsubmodule.sh diff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh index afd4756134..b4f9fc4580 100755 --- a/t/t3000-ls-files-others.sh +++ b/t/t3000-ls-files-others.sh @@ -65,13 +65,6 @@ test_expect_success '--no-empty-directory hides empty directory' ' test_cmp expected3 output ' -test_expect_success 'ls-files --others handles non-submodule .git' ' - mkdir not-a-submodule && - echo foo >not-a-submodule/.git && - git ls-files -o >output && - test_cmp expected1 output -' - test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' ' git init super && git init sub && diff --git a/t/t3009-ls-files-others-nonsubmodule.sh b/t/t3009-ls-files-others-nonsubmodule.sh new file mode 100755 index 0000000000..cc66a4a14d --- /dev/null +++ b/t/t3009-ls-files-others-nonsubmodule.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +test_description='test git ls-files --others with non-submodule repositories' + +. ./test-lib.sh + +test_expect_success 'setup: expected output' ' + cat >expected <<-EOF + expected + output + EOF +' + +test_expect_success 'ls-files --others handles non-submodule .git' ' + mkdir not-a-submodule && + echo foo >not-a-submodule/.git && + git ls-files -o >output && + test_cmp expected output +' + +test_done From patchwork Tue Apr 2 18:35:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Meyer X-Patchwork-Id: 10882201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 391431575 for ; Tue, 2 Apr 2019 18:36:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271F028918 for ; Tue, 2 Apr 2019 18:36:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B68E28929; Tue, 2 Apr 2019 18:36:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B20C828918 for ; Tue, 2 Apr 2019 18:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729289AbfDBSgB (ORCPT ); Tue, 2 Apr 2019 14:36:01 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:58671 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728724AbfDBSgB (ORCPT ); Tue, 2 Apr 2019 14:36:01 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id B70E164ECC; Tue, 2 Apr 2019 14:35:56 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Ln+3RKIc4+1gtv687vJ+Y+jNx zw=; b=DwMf2B1/EqGyXnaEPfAjrA3T8Jo8EfEJHnWnxKAu5hOjAGuKbAi5N19wf FBq/5cASGYSK4y8Zf9RHbGbI18hjEzBCJfdyDReNQuK/0sk+uF8FhMlHipZ4Nkku F+96bdUY/8aHOkI2nvQUjAXoyF7INrH9HBGhg5M0WBJpVh1E4c= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id AE5DA64ECB; Tue, 2 Apr 2019 14:35:56 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=8pBgDRBYkQqv/MU3KvmVVM3Y0EvyNV9T1zL4ECxoaaU=; b=ZYGcKAI6klbkqVH8y7P1n+nb/nn//1psDN2hYfKNXWkRi3Q4dwDrSLEtbOFwe/7BeLMBbymD7TWmydo9S2LAIQdb0M5VOjsy3BPFF3vIqKld84cXRevfZGFfqIzJVHoPfqIHcB8eag7LIqMKzd/yI12zKNcFw4yBwnwx9HBfXQQ= Received: from hylob.dartmouth.edu (unknown [129.170.31.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id DD1B364EC7; Tue, 2 Apr 2019 14:35:52 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Kyle Meyer , git@vger.kernel.org Cc: debian@onerussian.com Subject: [PATCH v2 3/4] t3009: test that ls-files -o traverses bogus repo Date: Tue, 2 Apr 2019 14:35:04 -0400 Message-Id: <20190402183505.31512-4-kyle@kyleam.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402183505.31512-1-kyle@kyleam.com> References: <87lg1eq146.fsf@kyleam.com> <20190402183505.31512-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 25E063EE-5576-11E9-A4D1-EE24A11ADF13-24757444!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a2d5156c2b (resolve_gitlink_ref: ignore non-repository paths, 2016-01-22) added this test, the purpose was to check the 'ls-files -o' didn't die() when processing the bogus repository. The expected output didn't even need to be adjusted for the addition because the bogus repository is treated as an empty directory. Let's add another scenario to test that 'ls-files -o' lists an untracked file within this directory. Doing so isn't useful for the original purpose of the test, but it will be helpful for highlighting that this traversal does _not_ happen in the non-bogus scenarios that will be added next. Rename the original subdirectory to highlight the difference with the new one. Signed-off-by: Kyle Meyer --- t/t3009-ls-files-others-nonsubmodule.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/t/t3009-ls-files-others-nonsubmodule.sh b/t/t3009-ls-files-others-nonsubmodule.sh index cc66a4a14d..9ed75928aa 100755 --- a/t/t3009-ls-files-others-nonsubmodule.sh +++ b/t/t3009-ls-files-others-nonsubmodule.sh @@ -1,6 +1,14 @@ #!/bin/sh -test_description='test git ls-files --others with non-submodule repositories' +test_description='test git ls-files --others with non-submodule repositories + +This test runs git ls-files --others with the following working tree: + + repo-bogus-no-files/ + directory with no files aside from a bogus .git file + repo-bogus-untracked-file/ + directory with a bogus .git file and another untracked file +' . ./test-lib.sh @@ -8,12 +16,19 @@ test_expect_success 'setup: expected output' ' cat >expected <<-EOF expected output + repo-bogus-untracked-file/untracked EOF ' +test_expect_success 'setup: directories' ' + mkdir repo-bogus-no-files && + echo foo >repo-bogus-no-files/.git && + mkdir repo-bogus-untracked-file && + echo foo >repo-bogus-untracked-file/.git && + : >repo-bogus-untracked-file/untracked +' + test_expect_success 'ls-files --others handles non-submodule .git' ' - mkdir not-a-submodule && - echo foo >not-a-submodule/.git && git ls-files -o >output && test_cmp expected output ' From patchwork Tue Apr 2 18:35:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Meyer X-Patchwork-Id: 10882203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47C5317E0 for ; Tue, 2 Apr 2019 18:36:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35911288EF for ; Tue, 2 Apr 2019 18:36:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29D492891F; Tue, 2 Apr 2019 18:36:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0BE5288EF for ; Tue, 2 Apr 2019 18:36:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729308AbfDBSgH (ORCPT ); Tue, 2 Apr 2019 14:36:07 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:56179 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbfDBSgH (ORCPT ); Tue, 2 Apr 2019 14:36:07 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id F214A64ED0; Tue, 2 Apr 2019 14:35:59 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=74xv6UM0j2BZnrv2w9q/wnYO5 bw=; b=V7cXXUH4TaQX/QaO6JZrgKCr9ljAk+5GI48Ln+ZxA7Kcdo9XBxsHi/11e 4aROMMfmAziCB3MtpBL1j1syQEI95ccFqBHCjm+4wpHhN0PUHMvy66L1ZwelLRo2 X3Nx7vHbRVtltGX5QR1UzsYEe2CChgxCZQLIAdnrnyz3vb6v7U= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id D3F7464ECF; Tue, 2 Apr 2019 14:35:59 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:cc:subject:date:message-id:in-reply-to:references:mime-version:content-transfer-encoding; s=mesmtp; bh=9N75kEzyWaWhMWYHfD6WhxOj/85mJoxLTWMSyfxupD0=; b=FMC9mFi5gKLHFDkaDNYb+fYHLFK5RFPKE3TZ6Ac2dukNG1uWxMoZO+FVV5D3MjYHhanjFyFs5AlovhwoxhHyt3uy28MFHCfKuhm/y01rztsFUIPY1etJ2ncgGOdNcbwLNbUl9Te22CIPL5rOKZS3vSGgbqOP6Vgv4cecbEFnFTI= Received: from hylob.dartmouth.edu (unknown [129.170.31.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 0C84D64ECA; Tue, 2 Apr 2019 14:35:55 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Kyle Meyer , git@vger.kernel.org Cc: debian@onerussian.com Subject: [PATCH v2 4/4] dir: do not traverse repositories with no commits Date: Tue, 2 Apr 2019 14:35:05 -0400 Message-Id: <20190402183505.31512-5-kyle@kyleam.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402183505.31512-1-kyle@kyleam.com> References: <87lg1eq146.fsf@kyleam.com> <20190402183505.31512-1-kyle@kyleam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 27C0246A-5576-11E9-9AE0-EE24A11ADF13-24757444!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When treat_directory() encounters a directory that is not in the index and DIR_NO_GITLINKS is unset, it calls resolve_gitlink_ref() to decide if a directory looks like a repository, in which case the directory won't be traversed. As a result, 'status -uall' and 'ls-files -o' will show only the directory, even when there are untracked files within the directory. For the unusual case where a repository doesn't have any commits, resolve_gitlink_ref() returns -1 because HEAD cannot be resolved, and the directory is treated as a normal directory (i.e. traversal does not stop at the repository boundary). The status and ls-files commands above list untracked files within the repository rather than showing only the top-level directory. The above case is a corner case in an already unusual situation of the working tree containing a repository that is not a tracked submodule, but we might as well treat anything that looks like a repository consistently. Loosen the "looks like a repository" criteria in treat_directory() by replacing resolve_gitlink_ref() with is_nonbare_repository_dir(), one of the checks that is performed downstream when resolve_gitlink_ref() is called with an empty repository. As the required update to t3700-add shows, being looser with the check means that we're stricter when adding empty repositories to the index: % git add repo warning: adding embedded git repository: repo hint: You've added another git repository inside your current repository. hint: [...] error: unable to index file 'repo/' fatal: adding files failed That error message isn't particularly helpful in this situation, but it seems preferable to the old behavior of adding the repository's untracked files. And if the caller really wants the previous behavior, they can get it by adding a trailing slash. Signed-off-by: Kyle Meyer --- dir.c | 6 ++++-- t/t3009-ls-files-others-nonsubmodule.sh | 22 +++++++++++++++++++++- t/t3700-add.sh | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/dir.c b/dir.c index b2cabadf25..a4e59eb351 100644 --- a/dir.c +++ b/dir.c @@ -1467,9 +1467,11 @@ static enum path_treatment treat_directory(struct dir_struct *dir, return path_none; } if (!(dir->flags & DIR_NO_GITLINKS)) { - struct object_id oid; - if (resolve_gitlink_ref(dirname, "HEAD", &oid) == 0) + struct strbuf sb = STRBUF_INIT; + strbuf_addstr(&sb, dirname); + if (is_nonbare_repository_dir(&sb)) return exclude ? path_excluded : path_untracked; + strbuf_release(&sb); } return path_recurse; } diff --git a/t/t3009-ls-files-others-nonsubmodule.sh b/t/t3009-ls-files-others-nonsubmodule.sh index 9ed75928aa..be4e7e26bc 100755 --- a/t/t3009-ls-files-others-nonsubmodule.sh +++ b/t/t3009-ls-files-others-nonsubmodule.sh @@ -8,6 +8,14 @@ This test runs git ls-files --others with the following working tree: directory with no files aside from a bogus .git file repo-bogus-untracked-file/ directory with a bogus .git file and another untracked file + repo-no-commit-no-files/ + git repository without a commit or a file + repo-no-commit-untracked-file/ + git repository without a commit but with an untracked file + repo-with-commit-no-files/ + git repository with a commit and no untracked files + repo-with-commit-untracked-file/ + git repository with a commit and an untracked file ' . ./test-lib.sh @@ -17,6 +25,10 @@ test_expect_success 'setup: expected output' ' expected output repo-bogus-untracked-file/untracked + repo-no-commit-no-files/ + repo-no-commit-untracked-file/ + repo-with-commit-no-files/ + repo-with-commit-untracked-file/ EOF ' @@ -25,7 +37,15 @@ test_expect_success 'setup: directories' ' echo foo >repo-bogus-no-files/.git && mkdir repo-bogus-untracked-file && echo foo >repo-bogus-untracked-file/.git && - : >repo-bogus-untracked-file/untracked + : >repo-bogus-untracked-file/untracked && + git init repo-no-commit-no-files && + git init repo-no-commit-untracked-file && + : >repo-no-commit-untracked-file/untracked && + git init repo-with-commit-no-files && + git -C repo-with-commit-no-files commit --allow-empty -mmsg && + git init repo-with-commit-untracked-file && + test_commit -C repo-with-commit-untracked-file msg && + : >repo-with-commit-untracked-file/untracked ' test_expect_success 'ls-files --others handles non-submodule .git' ' diff --git a/t/t3700-add.sh b/t/t3700-add.sh index be582a513b..5a8425962b 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -396,6 +396,7 @@ test_expect_success 'no file status change if no pathspec is given in subdir' ' ' test_expect_success 'all statuses changed in folder if . is given' ' + rm -fr empty && git add --chmod=+x . && test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 && git add --chmod=-x . &&