patman: Clean up creation of the git tree

The test starts with the HEAD pointing to the wrong place, so that the
created files appear to be deleted. Fix this by resetting the tree
before tests start. Add a check that the tree is clean.

Update pygit2 so that the enums are available.
This commit is contained in:
Simon Glass
2025-05-08 05:23:41 +02:00
parent 9302d672a5
commit 3724cbade4
3 changed files with 27 additions and 2 deletions

View File

@@ -757,6 +757,24 @@ def get_branch(git_dir=None):
return out
def check_dirty(git_dir=None, work_tree=None):
"""Check if the tree is dirty
Args:
git_dir (str): Path to git repository (None to use default)
Return:
str: List of dirty filenames and state
"""
cmd = ['git']
if git_dir:
cmd += ['--git-dir', git_dir]
if work_tree:
cmd += ['--work-tree', work_tree]
cmd += ['status', '--porcelain', '--untracked-files=no']
return command.output(*cmd).splitlines()
if __name__ == "__main__":
import doctest