Skip to content

Commit

Permalink
Add commit_tree method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 6, 2024
1 parent 1d11098 commit d8691d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
16 changes: 4 additions & 12 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

import jaraco.path


@pytest.fixture(autouse=True)
def _isolate_home(tmp_home_dir):
Expand All @@ -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
6 changes: 6 additions & 0 deletions jaraco/vcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 11 additions & 0 deletions jaraco/vcs/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess

import dateutil.parser
import jaraco.path
from tempora import utc


Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"jaraco.versioning",
"python-dateutil",
"tempora",
"jaraco.path",
]
dynamic = ["version"]

Expand All @@ -43,7 +44,6 @@ test = [

# local
"pygments",
"jaraco.path",
"types-python-dateutil",
"pytest-home",
]
Expand Down

0 comments on commit d8691d4

Please sign in to comment.