implement branch check prior to commit
This commit is contained in:
parent
b61ff148ed
commit
d23070435a
3
git.py
3
git.py
@ -3,3 +3,6 @@ from typing import Sequence
|
|||||||
|
|
||||||
def exec(*args: Sequence[str]):
|
def exec(*args: Sequence[str]):
|
||||||
return subprocess.call(["git", *args])
|
return subprocess.call(["git", *args])
|
||||||
|
|
||||||
|
def read(*args: Sequence[str]):
|
||||||
|
return subprocess.check_output(["git", *args], text=True).strip()
|
22
tzk.py
22
tzk.py
@ -1,6 +1,7 @@
|
|||||||
from abc import ABC, abstractmethod, abstractclassmethod
|
from abc import ABC, abstractmethod, abstractclassmethod
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import git
|
import git
|
||||||
@ -27,19 +28,34 @@ class CommitCommand(CliCommand):
|
|||||||
"-m", "--message",
|
"-m", "--message",
|
||||||
metavar="MSG",
|
metavar="MSG",
|
||||||
help="Commit message to use.",
|
help="Commit message to use.",
|
||||||
default="daily checkpoint"
|
default=(cm.commit_message or "checkpoint")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-r", "--remote",
|
||||||
|
metavar="REMOTE",
|
||||||
|
help="Name of the configured Git remote to push to.",
|
||||||
|
default=(cm.commit_remote or "origin"),
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-l", "--local",
|
"-l", "--local",
|
||||||
help="Don't push the results to any configured remote repository.",
|
help="Don't push the results to any configured remote repository.",
|
||||||
action="store_true"
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
|
||||||
def execute(self, args: argparse.Namespace) -> None:
|
def execute(self, args: argparse.Namespace) -> None:
|
||||||
|
if cm.commit_require_branch:
|
||||||
|
current_branch = git.read("rev-parse", "--abbrev-ref", "HEAD")
|
||||||
|
if current_branch != cm.commit_require_branch:
|
||||||
|
print(f"You are on the '{current_branch}' branch, "
|
||||||
|
f"but your TZK configuration requires you to be on the "
|
||||||
|
f"'{cm.commit_require_branch}' branch to commit.",
|
||||||
|
file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
git.exec("add", "-A")
|
git.exec("add", "-A")
|
||||||
git.exec("commit", "-m", args.message)
|
git.exec("commit", "-m", args.message)
|
||||||
if not args.local:
|
if not args.local:
|
||||||
git.exec("push", "backup")
|
git.exec("push", args.remote)
|
||||||
|
|
||||||
|
|
||||||
class ListenCommand(CliCommand):
|
class ListenCommand(CliCommand):
|
||||||
|
Loading…
Reference in New Issue
Block a user