-
-
Notifications
You must be signed in to change notification settings - Fork 959
-
Hey all,
How do I get a list of all file? using git I can run
git ls-tree HEAD -r
how can I do it with this library? the best I could find is:
for file in repo.commit().tree.blobs: print(file.abspath)
but that only lists files in the top dictionary.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions
You are probably looking for this:
for entry in repo.commit().tree.traverse(): print(entry)
There are fields or methods on the returned entries to obtain their name or path relative to the root tree.
Replies: 2 comments 1 reply
-
You are probably looking for this:
for entry in repo.commit().tree.traverse(): print(entry)
There are fields or methods on the returned entries to obtain their name or path relative to the root tree.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3
-
To complete this, if you want a file listing, you want:
for entry in repo.commit().tree.traverse():
print(entry.path)
or
for entry in repo.commit().tree.traverse():
print(entry.abspath)
Beta Was this translation helpful? Give feedback.
All reactions
-
I also realize now that even though this is a way to list files that will always work, it will be much faster to traverse index entries instead if one is present, i.e. do the equivalent of git ls-files
. But then again, unless repo.git.ls_files()
is used, any kind of traversal will be slow comparatively.
Beta Was this translation helpful? Give feedback.