Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- The --use-gitignore option now also applies to single files passed as argument.
6 changes: 6 additions & 0 deletions ggshield/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def list_files(
targets: Set[Path] = set()
for path in paths:
if path.is_file():
if (
list_files_mode == ListFilesMode.ALL_BUT_GITIGNORED
and is_git_dir(path.parent)
and path.name not in git_ls_unstaged(path.parent) + git_ls(path.parent)
):
continue
targets.add(path)
elif path.is_dir():
_targets = set()
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/utils/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,23 @@ def test_get_ignored_files(tmp_path, file_path, expected):
def test_url_for_path(path: PurePath, expected_url: str):
url = url_for_path(path)
assert url == expected_url


def test_get_gitignored_files(tmp_path):
"""
GIVEN a file, that is in the .gitignore
WHEN listing its content
THEN an empty set is returned
"""
Repository.create(tmp_path)
file_full_path = tmp_path / "file.txt"
write_text(filename=str(tmp_path / ".gitignore"), content="file.txt")
write_text(filename=str(file_full_path), content="")

file_paths = list_files(
paths=[file_full_path],
exclusion_regexes=set(),
list_files_mode=ListFilesMode.ALL_BUT_GITIGNORED,
)

assert file_paths == set()
Loading