From 469e2a9eab95ab938a46096d8297ca44edc0838d Mon Sep 17 00:00:00 2001 From: Benjamin Labrecque Date: Fri, 3 Jul 2026 15:20:55 +0200 Subject: [PATCH] chore: better git handling --- cli/src/core/git.py | 29 ++++++++++++++++++----------- config/services_registry.yml | 14 +------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/cli/src/core/git.py b/cli/src/core/git.py index aaacd2a..5d99634 100644 --- a/cli/src/core/git.py +++ b/cli/src/core/git.py @@ -12,17 +12,11 @@ def git_push_service_directory( """ Push newly created service to Gitea """ - try: - repo = git.Repo(repo_root) - original_branch = repo.active_branch.name + repo = git.Repo(repo_root) + original_branch = repo.active_branch.name - logger.info(f"Switching to branch '{branch_name}'...") - # Create branch if it doesn't exist, then checkout - if branch_name in repo.heads: - new_branch = repo.heads[branch_name] - else: - new_branch = repo.create_head(branch_name) - new_branch.checkout() + try: + switch_branch(repo, branch_name) logger.info(f"Staging files inside: {service_dir_rel_path}...") repo.index.add([service_dir_rel_path]) @@ -40,7 +34,20 @@ def git_push_service_directory( origin.push(refspec=f"{branch_name}:{branch_name}").raise_if_error() logger.info("Successfully pushed!") - logger.info(f"Switching to branch '{original_branch}'...") + switch_branch(repo, original_branch) except Exception as e: logger.info(f"Git Operation Failed: {e}") + switch_branch(repo, original_branch) + + +def switch_branch(repo: git.Repo, branch_name: str): + """ + Create branch if it doesn't exist, then checkout + """ + logger.info(f"Switching to branch '{branch_name}'...") + if branch_name in repo.heads: + new_branch = repo.heads[branch_name] + else: + new_branch = repo.create_head(branch_name) + new_branch.checkout() diff --git a/config/services_registry.yml b/config/services_registry.yml index 97ec892..938f5bc 100644 --- a/config/services_registry.yml +++ b/config/services_registry.yml @@ -1,17 +1,5 @@ -next_available_id: 5 +next_available_id: 1 services: 0: name: master status: active - 1: - name: cool-service - status: active - 2: - name: cool-service - status: active - 3: - name: cool-service - status: active - 4: - name: cool-service - status: active