Jir Jir - 3 years ago 73
Git Question

List the content of a directory for a specific git commit using GitPython

Using GitPython, I'm trying to list the content of a directory at a given commit (i.e. a "snapshot" of the directory at the time).

In the terminal, what I'd do is:

git ls-tree --name-only 4b645551aa82ec55d1794d0bae039dd28e6c5704

How can I do the same in GitPyhon?

Based on the answers I've found to a similar question (GitPython get tree and blob object by sha) I've tried recursively traversing
and its
, but I don't seem to get anywhere.

Any ideas?

Jir Jir
Answer Source

I couldn't find a more elegant way than actually calling execute. This is the end result:

configFiles = repo.git.execute(
    ['git', 'ls-tree', '--name-only', commit.hexsha, path]).split()

where commit is a git.Commit object and path is the path I'm interested in.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download