- Writing custom git flow scripts - finishing up without extensive testing

This commit is contained in:
Josako
2025-12-11 09:47:19 +01:00
parent fe9fc047ff
commit 2c8347c91b
8 changed files with 389 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
from __future__ import annotations
from ..core import config, git_api, output
from ..core import config, git_api, hooks, output
def _bugfix_branch_name(name: str) -> str:
@@ -20,6 +20,15 @@ def handle_bugfix_start(args) -> int:
output.info(f"Aanmaken van bugfix branch '{branch_name}' vanaf '{cfg.develop_branch}'")
git_api.create_branch(branch_name, cfg.develop_branch)
output.success(f"Bugfix branch '{branch_name}' is aangemaakt en gecheckt out.")
# Hooks na succesvol aanmaken van een bugfix branch
hooks.run_hooks(
"bugfix_start",
{
"branch": branch_name,
"base_branch": cfg.develop_branch,
},
)
return 0
except git_api.GitError as exc:
output.error(str(exc))
@@ -36,11 +45,24 @@ def handle_bugfix_finish(args) -> int:
if name is None:
current = git_api.get_current_branch()
if not current.startswith(cfg.bugfix_prefix):
if current.startswith(cfg.bugfix_prefix):
bugfix_branch = current
else:
branches = git_api.list_local_branches_with_prefix(cfg.bugfix_prefix)
if not branches:
raise git_api.GitError(
"Er zijn geen lokale bugfix branches gevonden. "
"Maak eerst een bugfix branch aan of geef een naam op."
)
output.heading("Beschikbare bugfix branches")
for b in branches:
output.plain(f"- {b}")
raise git_api.GitError(
"Je zit niet op een bugfix branch. Geef de bugfix-naam expliciet door (zonder prefix)."
"Je zit niet op een bugfix branch. Kies een van de bovenstaande namen "
"en voer het commando opnieuw uit, bv.: gitflow bugfix finish <naam-zonder-prefix>."
)
bugfix_branch = current
else:
bugfix_branch = _bugfix_branch_name(name)
@@ -63,6 +85,23 @@ def handle_bugfix_finish(args) -> int:
) from exc
output.success(f"Bugfix branch '{bugfix_branch}' is gemerged naar '{cfg.develop_branch}'.")
# Optionele cleanup
if cfg.delete_bugfix_after_finish:
output.info(f"Opruimen van lokale bugfix branch '{bugfix_branch}'")
try:
git_api._run_git(["branch", "-d", bugfix_branch]) # type: ignore[attr-defined]
except git_api.GitError as exc:
output.warning(f"Kon bugfix branch '{bugfix_branch}' niet verwijderen: {exc}")
# Hooks na succesvolle bugfix-finish
hooks.run_hooks(
"bugfix_finish",
{
"branch": bugfix_branch,
"base_branch": cfg.develop_branch,
},
)
return 0
except git_api.GitError as exc:
output.error(str(exc))