import pygit2 # using version 1.15.1 in this example import sys import os def walk_repo_files(repo, branch): tree = repo.revparse_single(branch).tree trees_and_paths = [(tree, [])] # keep going until there is no more data while len(trees_and_paths) != 0: tree, path = trees_and_paths.pop() # take the last entry for entry in tree: if entry.filemode == pygit2.GIT_FILEMODE_TREE: next_tree = repo.get(entry.id) next_path = list(path) next_path.append(entry.name) trees_and_paths.append((next_tree, next_path,)) else: yield os.path.join(*path, entry.name) repo_path = sys.argv[1] branch_name = sys.argv[2] repo = pygit2.Repository(repo_path) for entry in walk_repo_files(repo, branch_name): sys.stdout.write(entry) sys.stdout.write("\n")