]> git.ipfire.org Git - thirdparty/git.git/commit - dir.c
dir: do not traverse repositories with no commits
authorKyle Meyer <kyle@kyleam.com>
Tue, 9 Apr 2019 23:07:36 +0000 (19:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Apr 2019 03:52:49 +0000 (12:52 +0900)
commitb22827045e0b6c2ae1b12be2820cdc4b7f750895
treeb213f3cfb5da9c1c97489256ece8cfc44aed92c1
parente13811189bbd6b8672e3359f25c1e10f0c9b3c20
dir: do not traverse repositories with no commits

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 a commit checked
out, 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.  And if 'git add' is called on a
repository with no commit checked out, any untracked files under the
repository are added as blobs in the top-level project, a behavior
that is unlikely to be what the caller intended.

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.

As the required update to t3700-add shows, calling 'git add' on a
repository with no commit checked out will now raise an error.  While
this is the desired behavior, note that the output isn't yet
appropriate.  The next commit will improve this output.

Signed-off-by: Kyle Meyer <kyle@kyleam.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t3009-ls-files-others-nonsubmodule.sh [new file with mode: 0755]
t/t3700-add.sh