Subject: [PATCH 0/4] dir: Treat a repository without commits as a repository

From: Kyle Meyer <[email-masked]>
Date: Thu, 14 Mar 2019 11:02:15 -0400

When the working tree contains a repository with no commits, it's
treated as an empty directory, not a repository:

    $ git init
    $ git init no-commit && touch no-commit/untracked
    $ git init with-commit && touch with-commit/untracked
    $ git -C with-commit commit --allow-empty -mmsg
    $ git ls-files -o
    no-commit/untracked
    with-commit/

That's admittedly a weird case that is unlikely to happen in the wild,
and indeed I didn't observe it in the wild.  In DataLad, we rely on
`ls-files -o` to stop at the boundary of a submodule (like it does
with "with-commit" above), and we noticed the "repository with no
commit" exception on a minimal snippet that was meant for debugging
another issue [*].

This series makes the "is repository?" check in treat_directory() use
is_nonbare_repository_dir() instead of resolve_gitlink_ref() so that a
repository without any commits is treated like a repository rather
than an empty directory.  This makes the reporting from commands like
ls-files consistent for the case shown above, and it also avoids the
case where 'git add no-commit' (no trailing slash) adds the untracked
files of the no-commit/ repository to the index of the current
repository.

[*]: https://github.com/datalad/datalad/issues/3139#issuecomment-460542647

Kyle Meyer (4):
  submodule: refuse to add repository with no commits
  t3000: move non-submodule repo test to separate file
  t3009: test that ls-files -o traverses bogus repo
  dir: do not traverse repositories with no commits

 dir.c                                   |  6 ++-
 git-submodule.sh                        | 12 +++++-
 t/t3000-ls-files-others.sh              |  7 ----
 t/t3009-ls-files-others-nonsubmodule.sh | 56 +++++++++++++++++++++++++
 t/t3700-add.sh                          |  1 +
 t/t7400-submodule-basic.sh              | 11 ++++-
 6 files changed, 81 insertions(+), 12 deletions(-)
 create mode 100755 t/t3009-ls-files-others-nonsubmodule.sh

-- 
2.21.0