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.
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index 9c7d5d8..61df823 100644
--- a/tools/patman/func_test.py
+++ b/tools/patman/func_test.py
@@ -503,7 +503,7 @@
target = repo.revparse_single('HEAD~2')
# pylint doesn't seem to find this
# pylint: disable=E1101
- repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE)
+ repo.reset(target.oid, pygit2.enums.ResetMode.HARD)
self.make_commit_with_file('video: Some video improvements', '''
Fix up the video so that
it looks more purple. Purple is
@@ -543,6 +543,13 @@
repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base')
repo.branches.local.create('base', base_target)
+
+ target = repo.lookup_reference('refs/heads/first')
+ repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE)
+ target = repo.revparse_single('HEAD')
+ repo.reset(target.oid, pygit2.enums.ResetMode.HARD)
+
+ self.assertFalse(gitutil.check_dirty(self.gitdir, self.tmpdir))
return repo
def test_branch(self):
diff --git a/tools/patman/requirements.txt b/tools/patman/requirements.txt
index 57a284d..ce9a385 100644
--- a/tools/patman/requirements.txt
+++ b/tools/patman/requirements.txt
@@ -1,6 +1,6 @@
aiohttp==3.9.1
ConfigParser==7.1.0
importlib_resources==6.5.2
-pygit2==1.13.3
+pygit2==1.14.1
Requests==2.32.3
setuptools==75.8.0
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index cc57e7b..3c52cce 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -757,6 +757,24 @@
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