71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from ..core import config, git_api, output
|
|
|
|
|
|
def _bugfix_branch_name(name: str) -> str:
|
|
return f"{config.CONFIG.bugfix_prefix}{name}"
|
|
|
|
|
|
def handle_bugfix_start(args) -> int:
|
|
name: str = args.name
|
|
cfg = config.CONFIG
|
|
|
|
try:
|
|
git_api.ensure_clean_working_tree()
|
|
git_api.fetch_remote(cfg.remote_name)
|
|
git_api.ensure_not_behind_remote(cfg.develop_branch, cfg.remote_name)
|
|
|
|
branch_name = _bugfix_branch_name(name)
|
|
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.")
|
|
return 0
|
|
except git_api.GitError as exc:
|
|
output.error(str(exc))
|
|
return 1
|
|
|
|
|
|
def handle_bugfix_finish(args) -> int:
|
|
cfg = config.CONFIG
|
|
name: str | None = args.name
|
|
|
|
try:
|
|
git_api.ensure_clean_working_tree()
|
|
git_api.fetch_remote(cfg.remote_name)
|
|
|
|
if name is None:
|
|
current = git_api.get_current_branch()
|
|
if not current.startswith(cfg.bugfix_prefix):
|
|
raise git_api.GitError(
|
|
"Je zit niet op een bugfix branch. Geef de bugfix-naam expliciet door (zonder prefix)."
|
|
)
|
|
bugfix_branch = current
|
|
else:
|
|
bugfix_branch = _bugfix_branch_name(name)
|
|
|
|
git_api.ensure_not_behind_remote(bugfix_branch, cfg.remote_name)
|
|
git_api.ensure_not_behind_remote(cfg.develop_branch, cfg.remote_name)
|
|
|
|
output.info(f"Mergen van '{bugfix_branch}' naar '{cfg.develop_branch}'")
|
|
git_api.checkout_branch(cfg.develop_branch)
|
|
|
|
merge_args = ["merge"]
|
|
if cfg.use_no_ff_for_feature:
|
|
merge_args.append("--no-ff")
|
|
merge_args.append(bugfix_branch)
|
|
|
|
try:
|
|
git_api._run_git(merge_args) # type: ignore[attr-defined]
|
|
except git_api.GitError as exc:
|
|
raise git_api.GitError(
|
|
"Merge is mislukt (mogelijk conflicten). Los de conflicten op en voltooi de merge handmatig."
|
|
) from exc
|
|
|
|
output.success(f"Bugfix branch '{bugfix_branch}' is gemerged naar '{cfg.develop_branch}'.")
|
|
return 0
|
|
except git_api.GitError as exc:
|
|
output.error(str(exc))
|
|
return 1
|
|
|