chore: better git handling
This commit is contained in:
+18
-11
@@ -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,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
|
||||
|
||||
Reference in New Issue
Block a user