From 5b5b02f75d9c0a682fb647eb05c9c869c7ddddd9 Mon Sep 17 00:00:00 2001 From: Johan Marcusson Date: Thu, 22 Aug 2024 16:13:25 +0200 Subject: [PATCH] better handling of uninitialized templates repo, when refreshing settings before first refresh of templates for ex --- src/cnaas_nms/db/git_worktrees.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cnaas_nms/db/git_worktrees.py b/src/cnaas_nms/db/git_worktrees.py index ea2e453b..a5f594f1 100644 --- a/src/cnaas_nms/db/git_worktrees.py +++ b/src/cnaas_nms/db/git_worktrees.py @@ -31,7 +31,13 @@ def refresh_templates_worktree(branch: str): branch_folder = get_branch_folder(branch) if os.path.isdir(branch_folder): return - local_repo = Repo(app_settings.TEMPLATES_LOCAL) + try: + local_repo = Repo(app_settings.TEMPLATES_LOCAL) + except git.exc.InvalidGitRepositoryError: + logger.warning( + "Could not add worktree for templates branch {}: templates repository is not initialized".format(branch) + ) + return if not os.path.isdir("/tmp/worktrees"): os.mkdir("/tmp/worktrees") logger.debug("Adding worktree for templates branch {} in folder {}".format(branch, branch_folder))