From 202adeae8d18d5385a176f0ca38719ec6096fa5e Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Mon, 11 Mar 2024 12:59:42 +0100 Subject: [PATCH] explicitly check if we are inside a git repo (fixes #24) --- livesync/folder.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/livesync/folder.py b/livesync/folder.py index d8bda3d..4d478e5 100644 --- a/livesync/folder.py +++ b/livesync/folder.py @@ -60,12 +60,15 @@ def _get_ignores(self) -> List[str]: def get_summary(self) -> str: summary = f'{self.source_path} --> {self.target}\n' try: + cmd = ['git', 'rev-parse', '--is-inside-work-tree'] + subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except subprocess.CalledProcessError: + pass # not a git repo, git is not installed, or something else + else: cmd = ['git', 'log', '--pretty=format:[%h]\n', '-n', '1'] summary += subprocess.check_output(cmd, cwd=self.source_path).decode() cmd = ['git', 'status', '--short', '--branch'] summary += subprocess.check_output(cmd, cwd=self.source_path).decode().strip() + '\n' - except Exception: - pass # not a git repo, git is not installed, or something else return summary async def watch(self) -> None: