diff --git a/qutil/git.py b/qutil/git.py index c129f3b460fb440d5e85b36ab65b53395b31871f..bcbe0bcc117eef680349dc8481383dc2ba4a7ba3 100644 --- a/qutil/git.py +++ b/qutil/git.py @@ -4,10 +4,11 @@ Created on Mon Aug 14 18:36:43 2023 @author: Simon Humpohl """ +from typing import Set, Dict from dataclasses import dataclass from pathlib import Path import logging -import tkinter +import tkinter.messagebox from subprocess import check_output, check_call try: @@ -27,7 +28,7 @@ class SimpleRepo: def get_status(self) -> str: """Returns modified/untracked files and submodules""" - check_output(['git', 'status', '--short'], cwd=self.repo_path) + return check_output(['git', 'status', '--short'], cwd=self.repo_path).decode("utf8") def add_all(self): check_call(['git', 'add', '--all'], cwd=self.repo_path) @@ -43,8 +44,9 @@ class SimpleRepo: folders.append(SimpleRepo(Path(folder).absolute())) return folders - def current_hash(self): - raise NotImplementedError('todo') + def get_current_hash(self) -> bytes: + hash_base64, = check_output(['git', 'rev-parse', 'HEAD'], cwd=self.repo_path).splitlines() + return hash_base64 def auto_commit(repo: SimpleRepo): @@ -58,17 +60,19 @@ def manual_commit(repo: SimpleRepo, name: str): title = f'Manual commit: {name}' msg = (f'The repository {repo.name} is dirty. ' - 'Commit, ignore or stash the changes and press OK. ' - 'Pressing cancel will raise a KeyboardInterrupt.\n\n' - f'{status}') + 'Commit, ignore or stash the changes and press OK. ' + 'Pressing cancel will raise a KeyboardInterrupt.\n\n' + f'{status}') if not tkinter.messagebox.askokcancel(title, msg): raise KeyboardInterrupt(name) +@dataclass class GitRules: - auto_commit: set - auto_push: dict + ignore: Set[Path] + auto_commit: Set[Path] + auto_push: Mapping[Path, str] def process(self, repo: SimpleRepo): if not repo.get_status():