From d656924e9a13c5a81f68f414853df117cdb6a22d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Aug 2024 15:01:38 -0400 Subject: [PATCH] Add commit_tree method. --- conftest.py | 16 ++++------------ jaraco/vcs/base.py | 6 ++++++ jaraco/vcs/cmd.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/conftest.py b/conftest.py index 3e2008c..fe68ac5 100644 --- a/conftest.py +++ b/conftest.py @@ -1,7 +1,5 @@ import pytest -import jaraco.path - @pytest.fixture(autouse=True) def _isolate_home(tmp_home_dir): @@ -25,20 +23,14 @@ def _isolate_home(tmp_home_dir): @pytest.fixture def hg_repo(hg_repo): repo = hg_repo - jaraco.path.build(rev1) - repo._invoke('addremove') - repo._invoke('ci', '-m', 'committed') - jaraco.path.build(rev2) - repo._invoke('ci', '-m', 'added content') + repo.commit_tree(rev1, 'committed') + repo.commit_tree(rev2, 'added content') return repo @pytest.fixture def git_repo(git_repo): repo = git_repo - jaraco.path.build(rev1) - repo._invoke('add', '.') - repo._invoke('commit', '-m', 'committed') - jaraco.path.build(rev2) - repo._invoke('commit', '-am', 'added content') + repo.commit_tree(rev1, 'committed') + repo.commit_tree(rev2, 'added content') return repo diff --git a/jaraco/vcs/base.py b/jaraco/vcs/base.py index 1296f6c..bac42ea 100755 --- a/jaraco/vcs/base.py +++ b/jaraco/vcs/base.py @@ -134,3 +134,9 @@ def age(self): Return the age of the repo. """ raise NotImplementedError() + + def commit_tree(self, spec, msg="committed"): + """ + Apply the tree in spec and commit. + """ + raise NotImplementedError() diff --git a/jaraco/vcs/cmd.py b/jaraco/vcs/cmd.py index 6eb4626..b7c5249 100644 --- a/jaraco/vcs/cmd.py +++ b/jaraco/vcs/cmd.py @@ -6,6 +6,7 @@ import subprocess import dateutil.parser +import jaraco.path from tempora import utc @@ -150,6 +151,11 @@ def sub_paths(self): def _get_timestamp_str(self, rev): return self._invoke('log', '-l', '1', '--template', '{date|isodate}', '-r', rev) + def commit_tree(self, spec, message: str = 'committed'): + jaraco.path.build(spec) + self._invoke('addremove') + self._invoke('commit', '-m', message) + class Git(Command): exe = 'git' @@ -225,3 +231,8 @@ def age(self): proc.wait() proc.stdout.close() return utc.now() - dateutil.parser.parse(first_line) + + def commit_tree(self, spec, message: str = 'committed'): + jaraco.path.build(spec) + self._invoke('add', '.') + self._invoke('commit', '-m', message)