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 6732fb5 commit d656924
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 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)

0 comments on commit d656924

Please sign in to comment.