feature: agrego opcion para listar ramas wip

This commit is contained in:
Jonathan Teran Carballo
2025-12-14 21:56:18 -03:00
parent 74c333aa1a
commit 774cf9ade6
3 changed files with 26 additions and 15 deletions
+18 -10
View File
@@ -1,5 +1,5 @@
from argparse import ArgumentParser, Namespace
from git_flow import COLOR_WHITE_BOLD, COLOR_GREEN, COLOR_RED, COLOR_RESET, GitFlowError
from git_flow import COLOR_WHITE_BOLD, COLOR_GREEN, COLOR_RED, COLOR_RESET, TRASH_BRANCH_PREFIX, WIP_BRANCH_PREFIX, GitFlowError
from git_flow.command.base import Command
from git_flow.git import Git
@@ -24,7 +24,13 @@ class BranchCommand(Command):
parser.add_argument(
"--trash",
action="store_true",
help="Listar ramas en la 'papelera de reciclaje' (ramas que empiezan con 'trash/')"
help=f"Listar ramas en la 'papelera de reciclaje' (ramas que empiezan con '{TRASH_BRANCH_PREFIX}')"
)
parser.add_argument(
"--wip",
action="store_true",
help=f"Listar ramas 'en progreso' (ramas que empiezan con '{WIP_BRANCH_PREFIX}')"
)
return parser
@@ -36,8 +42,10 @@ class BranchCommand(Command):
self.environments = self.flowconfig["flow.branches"].split(",")
if args.trash:
self.show_trash_branches()
if args.environment is None:
self.show_branches(TRASH_BRANCH_PREFIX)
elif args.wip:
self.show_branches(WIP_BRANCH_PREFIX)
elif args.environment is None:
self.show_envs()
self.show_all_branches()
elif args.environment in self.environments:
@@ -46,8 +54,8 @@ class BranchCommand(Command):
else:
raise GitFlowError(f"'{args.environment}' no es un entorno válido.")
def show_trash_branches(self):
branches = self.get_trash_branches()
def show_branches(self, prefix: str):
branches = self.get_branches(prefix)
if not branches:
print("No hay ramas a mostrar.")
@@ -57,14 +65,14 @@ class BranchCommand(Command):
prefix = (COLOR_RED + "*") if branch == self.current_branch else " "
print(prefix + " " + branch + COLOR_RESET)
def get_trash_branches(self):
return Git("for-each-ref", "refs/heads/trash/", format=BRANCH_FORMAT).lines()
def get_branches(self, prefix: str):
return Git("for-each-ref", "refs/heads/" + prefix, format=BRANCH_FORMAT).lines()
def show_all_branches(self):
for environment in self.environments:
self.show_env_branches(environment, len(self.environments) > 1)
trash = len(self.get_trash_branches())
trash = len(self.get_branches(TRASH_BRANCH_PREFIX))
if trash:
print()
@@ -81,7 +89,7 @@ class BranchCommand(Command):
is_first_env = environment == self.environments[0]
pattern = "refs/heads/" if is_first_env else "refs/heads/release/" + environment + "/"
pattern += "*/*"
exclude = ["refs/heads/trash/", "refs/heads/release/"] if is_first_env else []
exclude = ["refs/heads/" + TRASH_BRANCH_PREFIX, "refs/heads/release/"] if is_first_env else []
branches = Git("for-each-ref", pattern, exclude=exclude, format=BRANCH_FORMAT).lines()
print(COLOR_WHITE_BOLD + (environment if show_env else "Ramas") + COLOR_RESET)