-
-
Notifications
You must be signed in to change notification settings - Fork 969
Add missing Repo.tracked_files convenience property
#2121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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.""" | ||||||||||||||||||||||||||
| return self.git.ls_files().splitlines() | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| 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
AI
Mar 26, 2026
There was a problem hiding this comment.
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.
| return self.git.ls_files().splitlines() | |
| output = self.git.ls_files("-z") | |
| if not output: | |
| return [] | |
| return output.rstrip("\0").split("\0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring for
tracked_filesis much less informative thanuntracked_filesand 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 tountracked_files) so callers don’t accidentally use it in tight loops.