- Writing custom git flow scripts - finishing up without extensive testing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ..core import config, git_api, output
|
||||
from ..core import config, git_api, hooks, output
|
||||
|
||||
|
||||
def _hotfix_branch_name(name: str) -> str:
|
||||
@@ -32,6 +32,16 @@ def handle_hotfix_start(args) -> int:
|
||||
output.info(f"Aanmaken van hotfix branch '{branch_name}' vanaf '{cfg.main_branch}'")
|
||||
git_api.create_branch(branch_name, cfg.main_branch)
|
||||
output.success(f"Hotfix branch '{branch_name}' is aangemaakt en gecheckt out.")
|
||||
|
||||
# Hooks na succesvol aanmaken van een hotfix branch
|
||||
hooks.run_hooks(
|
||||
"hotfix_start",
|
||||
{
|
||||
"branch": branch_name,
|
||||
"base_branch": cfg.main_branch,
|
||||
"version": name,
|
||||
},
|
||||
)
|
||||
return 0
|
||||
except git_api.GitError as exc:
|
||||
output.error(str(exc))
|
||||
@@ -42,6 +52,7 @@ def handle_hotfix_finish(args) -> int:
|
||||
cfg = config.CONFIG
|
||||
try:
|
||||
name_arg = getattr(args, "name", None)
|
||||
env_arg = getattr(args, "env", None)
|
||||
|
||||
git_api.ensure_clean_working_tree()
|
||||
git_api.fetch_remote(cfg.remote_name)
|
||||
@@ -56,17 +67,32 @@ def handle_hotfix_finish(args) -> int:
|
||||
name = current[len(prefix) :]
|
||||
hotfix_branch = current
|
||||
else:
|
||||
name = _ensure_version(None)
|
||||
hotfix_branch = _hotfix_branch_name(name)
|
||||
# Toon lijst van beschikbare hotfix branches
|
||||
branches = git_api.list_local_branches_with_prefix(cfg.hotfix_prefix)
|
||||
if not branches:
|
||||
raise git_api.GitError(
|
||||
"Er zijn geen lokale hotfix branches gevonden. "
|
||||
"Maak eerst een hotfix branch aan of geef een naam op."
|
||||
)
|
||||
|
||||
output.heading("Beschikbare hotfix branches")
|
||||
for b in branches:
|
||||
output.plain(f"- {b}")
|
||||
|
||||
raise git_api.GitError(
|
||||
"Je zit niet op een hotfix branch. Kies een van de bovenstaande namen "
|
||||
"en voer het commando opnieuw uit, bv.: gitflow hotfix finish <naam-of-versie>."
|
||||
)
|
||||
|
||||
git_api.ensure_not_behind_remote(hotfix_branch, cfg.remote_name)
|
||||
git_api.ensure_not_behind_remote(cfg.main_branch, cfg.remote_name)
|
||||
git_api.ensure_not_behind_remote(cfg.develop_branch, cfg.remote_name)
|
||||
|
||||
# Voor nu vragen we ook hier de versie/naam en gebruiken die voor de tag.
|
||||
# In een latere iteratie kunnen we hier automatische patch-bumping doen.
|
||||
version_for_tag = name
|
||||
tag_name = cfg.tag_format.format(version=version_for_tag)
|
||||
# Bepaal omgeving en tagnaam
|
||||
env = env_arg or cfg.hotfix_default_env
|
||||
suffix = cfg.environments.get(env, "")
|
||||
base_tag = cfg.tag_format.format(version=name)
|
||||
tag_name = f"{base_tag}{suffix}"
|
||||
|
||||
# Merge naar main
|
||||
output.info(f"Mergen van '{hotfix_branch}' naar '{cfg.main_branch}' en tag '{tag_name}' aanmaken")
|
||||
@@ -101,6 +127,26 @@ def handle_hotfix_finish(args) -> int:
|
||||
output.success(
|
||||
f"Hotfix '{name}' is voltooid: gemerged naar '{cfg.main_branch}' en '{cfg.develop_branch}' en getagd als '{tag_name}'."
|
||||
)
|
||||
|
||||
# Optionele cleanup
|
||||
if cfg.delete_hotfix_after_finish:
|
||||
output.info(f"Opruimen van lokale hotfix branch '{hotfix_branch}'")
|
||||
try:
|
||||
git_api._run_git(["branch", "-d", hotfix_branch]) # type: ignore[attr-defined]
|
||||
except git_api.GitError as exc:
|
||||
output.warning(f"Kon hotfix branch '{hotfix_branch}' niet verwijderen: {exc}")
|
||||
|
||||
# Hooks na succesvolle hotfix-finish
|
||||
hooks.run_hooks(
|
||||
"hotfix_finish",
|
||||
{
|
||||
"branch": hotfix_branch,
|
||||
"base_branch": cfg.main_branch,
|
||||
"version": name,
|
||||
"env": env,
|
||||
"tag": tag_name,
|
||||
},
|
||||
)
|
||||
return 0
|
||||
except git_api.GitError as exc:
|
||||
output.error(str(exc))
|
||||
|
||||
Reference in New Issue
Block a user