chore: better git handling
Deploy bin / deploy (push) Canceled after 0s
Deploy service MASTER / deploy (push) Canceled after 0s

This commit is contained in:
Benjamin Labrecque
2026-07-03 15:20:55 +02:00
parent 33b56dec66
commit 469e2a9eab
2 changed files with 19 additions and 24 deletions
+18 -11
View File
@@ -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()
+1 -13
View File
@@ -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