git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kyle Meyer <kyle@kyleam.com>
Cc: git@vger.kernel.org, debian@onerussian.com
Subject: Re: [PATCH v2 1/4] submodule: refuse to add repository with no commits
Date: Thu, 04 Apr 2019 16:24:46 +0900	[thread overview]
Message-ID: <xmqqv9zufd1d.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: 20190402183505.31512-2-kyle@kyleam.com

Kyle Meyer <kyle@kyleam.com> writes:

> 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.

OK, in short, in an already-populated repository,

	$ git init junk ;# there was no 'junk' subdirectory
	$ git add junk

would have been a successful no-op, and after the above two
commands,

	$ >junk/one
	$ git add junk

would have added junk/one as a normal blob to the top-level project,
ignoring the fact that the user wanted to eventually populate junk
as a repository and add it as a submodule.  You'll be teaching "git
add" not to do so, and pay attention to the fact that junk/.git exists,
even though junk/.git/HEAD is on an unborn branch.

Which makes sense to me.

> Signed-off-by: Kyle Meyer <kyle@kyleam.com>
> ---
>  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 &&

  reply	other threads:[~2019-04-04  7:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 15:02 [PATCH 0/4] dir: Treat a repository without commits as a repository Kyle Meyer
2019-03-14 15:02 ` [PATCH 1/4] submodule: refuse to add repository with no commits Kyle Meyer
2019-03-16 15:40   ` Kyle Meyer
2019-04-02 18:35     ` [PATCH v2 0/4] dir: Treat a repository without commits as a repository Kyle Meyer
2019-04-02 18:35       ` [PATCH v2 1/4] submodule: refuse to add repository with no commits Kyle Meyer
2019-04-04  7:24         ` Junio C Hamano [this message]
2019-04-02 18:35       ` [PATCH v2 2/4] t3000: move non-submodule repo test to separate file Kyle Meyer
2019-04-03  7:59         ` Junio C Hamano
2019-04-03 22:21           ` Kyle Meyer
2019-04-02 18:35       ` [PATCH v2 3/4] t3009: test that ls-files -o traverses bogus repo Kyle Meyer
2019-04-02 18:35       ` [PATCH v2 4/4] dir: do not traverse repositories with no commits Kyle Meyer
2019-04-03  8:05         ` Junio C Hamano
2019-04-03 22:25           ` Kyle Meyer
2019-03-14 15:02 ` [PATCH 2/4] t3000: move non-submodule repo test to separate file Kyle Meyer
2019-03-14 15:02 ` [PATCH 3/4] t3009: test that ls-files -o traverses bogus repo Kyle Meyer
2019-03-14 15:02 ` [PATCH 4/4] dir: do not traverse repositories with no commits Kyle Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqv9zufd1d.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=debian@onerussian.com \
    --cc=git@vger.kernel.org \
    --cc=kyle@kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).