X Tutup
Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ or low-level like git-plumbing.
It provides abstractions of git objects for easy access of repository data often backed by calling the `git`
command-line program.

For file discovery convenience, repositories expose both `Repo.untracked_files` and `Repo.tracked_files`.

### DEVELOPMENT STATUS

This project is in **maintenance mode**, which means that
Expand Down
5 changes: 5 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ class Repo:
"""Subclasses may easily bring in their own custom types by placing a constructor or
type here."""

@property
def tracked_files(self) -> List[str]:
"""Files currently tracked by git."""
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for tracked_files is much less informative than untracked_files and will be surfaced in the generated API reference. It would be helpful to document what the paths are relative to, and add a note that the property is expensive/no-cache (similar to untracked_files) so callers don’t accidentally use it in tight loops.

Suggested change
"""Files currently tracked by git."""
"""List of files currently tracked by Git.
The returned paths are relative to the repository's working tree directory.
.. note::
This property calls out to ``git ls-files`` every time it is accessed
and does not cache results. Avoid calling it in tight loops or other
performance-sensitive code paths.
"""

Copilot uses AI. Check for mistakes.
return self.git.ls_files().splitlines()
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new public convenience property should have test coverage similar to Repo.untracked_files (see test_repo.py::test_untracked_files). Please add a test that tracked_files returns expected tracked paths (ideally including spaces/unicode), so parsing/quoting regressions are caught.

Suggested change
return self.git.ls_files().splitlines()
# Use NUL-separated output to safely handle filenames with whitespace,
# newlines, and other special characters.
output = self.git.ls_files("-z")
if not output:
return []
return output.rstrip("\0").split("\0")

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracked_files parses git ls-files output by splitting on newlines. This will mis-handle valid pathnames that contain newlines, and can also mis-parse/return quoted or escaped paths when Git applies core.quotepath. Consider calling ls-files with NUL-termination (e.g., -z) and splitting on \0 (dropping the trailing empty entry) to get an unambiguous list of paths.

Suggested change
return self.git.ls_files().splitlines()
output = self.git.ls_files("-z")
if not output:
return []
return output.rstrip("\0").split("\0")

Copilot uses AI. Check for mistakes.

def __init__(
self,
path: Optional[PathLike] = None,
Expand Down
Loading
X Tutup