add repo.commit shortcut

This commit is contained in:
David Lord 2025-01-14 14:11:04 -08:00
parent 3e778fb77e
commit 0c6e5ed62b
No known key found for this signature in database
GPG key ID: 43368A7AA8CC5926
2 changed files with 16 additions and 0 deletions

View file

@ -4,6 +4,7 @@ Unreleased
- If a PR already exists from a previous failed run, force push to update the - If a PR already exists from a previous failed run, force push to update the
existing branch and PR. existing branch and PR.
- Add shortcut `repo.commit(message)` method.
## Version 0.1.1 ## Version 0.1.1

View file

@ -5,6 +5,7 @@ from shutil import which
from subprocess import CompletedProcess from subprocess import CompletedProcess
from ..utils import run_cmd from ..utils import run_cmd
from ..utils import wrap_text
from .base import Repo from .base import Repo
@ -64,6 +65,20 @@ class GitRepo(Repo):
self.git_cmd("merge", "--ff-only", self.script.branch) self.git_cmd("merge", "--ff-only", self.script.branch)
self.git_cmd("push") self.git_cmd("push")
def commit(self, message: str, add: bool = False) -> None:
"""Create a commit with the given message.
:param message: The commit message.
:param add: Update tracked files while committing. Disabled by default.
Alternatively, call {meth}`add_files` first.
"""
args = ["commit", "--message", wrap_text(message, width=72)]
if add:
args.insert(1, "-a")
self.git_cmd(*args)
def add_files( def add_files(
self, *items: str | Path, update: bool = False, all: bool = False self, *items: str | Path, update: bool = False, all: bool = False
) -> None: ) -> None: