mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
b22827045e
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>
50 lines
1.5 KiB
Bash
Executable file
50 lines
1.5 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='test git ls-files --others with non-submodule repositories
|
|
|
|
This test runs git ls-files --others with the following working tree:
|
|
|
|
nonrepo-no-files/
|
|
plain directory with no files
|
|
nonrepo-untracked-file/
|
|
plain directory with an 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
|
|
|
|
test_expect_success 'setup: directories' '
|
|
mkdir nonrepo-no-files/ &&
|
|
mkdir nonrepo-untracked-file &&
|
|
: >nonrepo-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 untracked git repositories' '
|
|
git ls-files -o >output &&
|
|
cat >expect <<-EOF &&
|
|
nonrepo-untracked-file/untracked
|
|
output
|
|
repo-no-commit-no-files/
|
|
repo-no-commit-untracked-file/
|
|
repo-with-commit-no-files/
|
|
repo-with-commit-untracked-file/
|
|
EOF
|
|
test_cmp expect output
|
|
'
|
|
|
|
test_done
|