feature: muevo opciones para check y print a metodos para ejecutar git

This commit is contained in:
jt
2025-11-22 11:23:24 -03:00
parent 37a7c101af
commit 7346cfd1a8
3 changed files with 27 additions and 29 deletions
+1 -5
View File
@@ -77,11 +77,7 @@ class TagCommand(Command):
return commit return commit
def check_not_tagged(self, commit: str): def check_not_tagged(self, commit: str):
tag = ( tag = Git("describe", commit, tags=True, exact_match=True).firstline(check=False)
Git("describe", commit, tags=True, exact_match=True)
.without_checking()
.firstline()
)
if tag: if tag:
raise GitFlowError("El commit a taggear ya tiene tag: " + tag) raise GitFlowError("El commit a taggear ya tiene tag: " + tag)
+25 -23
View File
@@ -22,7 +22,6 @@ class Git:
self.file = line[3:].strip("\n") self.file = line[3:].strip("\n")
command: list[str] command: list[str]
check_returncode: bool = True
@staticmethod @staticmethod
def get_config(file: str | None = None): def get_config(file: str | None = None):
@@ -60,7 +59,7 @@ class Git:
@staticmethod @staticmethod
def get_current_tag(): def get_current_tag():
return Git("describe", abbrev="0", tags=True).without_checking().firstline() return Git("describe", abbrev="0", tags=True).firstline(check=False)
@staticmethod @staticmethod
def get_first_fork_point(branch: str, env: str): def get_first_fork_point(branch: str, env: str):
@@ -115,44 +114,47 @@ class Git:
self.command += args self.command += args
def lines(self, strip: bool = True): def lines(self, strip: bool = True, **kwargs: bool):
process = subprocess.run(self.command, capture_output=True, text=True) process = self._get(**kwargs)
self.__print_process(process.stdout, process.stderr)
if self.check_returncode:
process.check_returncode()
lines = process.stdout.splitlines() lines = process.stdout.splitlines()
return lines if not strip else list(map(lambda l: l.strip(), lines)) return lines if not strip else list(map(lambda l: l.strip(), lines))
def firstline(self): def firstline(self, **kwargs: bool):
lines = self.lines() lines = self.lines(**kwargs)
return lines[0] if lines else "" return lines[0] if lines else ""
def exec(self): def code(self, **kwargs):
return self._run(check=False, **kwargs).returncode
def exec(self, **kwargs):
self._run(**kwargs)
def _get(self, print: bool = False, check: bool = True):
process = subprocess.run(self.command, capture_output=True, text=True) process = subprocess.run(self.command, capture_output=True, text=True)
self.__print_process(process.stdout, process.stderr) if print:
self._print_process(process.stdout, process.stderr)
if self.check_returncode: if check:
process.check_returncode() process.check_returncode()
def code(self): return process
process = subprocess.run(self.command, capture_output=True, text=True)
self.__print_process(process.stdout, process.stderr)
return process.returncode def _run(self, print: bool = False, check: bool = True):
process = subprocess.run(self.command)
def without_checking(self): if print:
self.check_returncode = False self._print_process("", "")
return self if check:
process.check_returncode()
def __print_process(self, stdout: str, stderr: str): return process
def _print_process(self, stdout: str, stderr: str):
command = [] command = []
for arg in self.command: for arg in self.command:
+1 -1
View File
@@ -218,7 +218,7 @@ def tag_command():
message = output[pos+1:] message = output[pos+1:]
merged_branch = None merged_branch = None
output = Git("describe", commit, tags=True, exact_match=True).without_checking().firstline() output = Git("describe", commit, tags=True, exact_match=True).firstline(check=False)
if output: if output:
print_error("El ultimo merge ya tiene tag: " + output) print_error("El ultimo merge ya tiene tag: " + output)