diff --git a/src/git_flow/command/tag.py b/src/git_flow/command/tag.py index c4cb1b3..79233a7 100644 --- a/src/git_flow/command/tag.py +++ b/src/git_flow/command/tag.py @@ -77,11 +77,7 @@ class TagCommand(Command): return commit def check_not_tagged(self, commit: str): - tag = ( - Git("describe", commit, tags=True, exact_match=True) - .without_checking() - .firstline() - ) + tag = Git("describe", commit, tags=True, exact_match=True).firstline(check=False) if tag: raise GitFlowError("El commit a taggear ya tiene tag: " + tag) diff --git a/src/git_flow/git.py b/src/git_flow/git.py index 3408378..5ca7b0d 100644 --- a/src/git_flow/git.py +++ b/src/git_flow/git.py @@ -22,7 +22,6 @@ class Git: self.file = line[3:].strip("\n") command: list[str] - check_returncode: bool = True @staticmethod def get_config(file: str | None = None): @@ -60,7 +59,7 @@ class Git: @staticmethod 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 def get_first_fork_point(branch: str, env: str): @@ -115,44 +114,47 @@ class Git: self.command += args - def lines(self, strip: bool = True): - process = subprocess.run(self.command, capture_output=True, text=True) - - self.__print_process(process.stdout, process.stderr) - - if self.check_returncode: - process.check_returncode() - + def lines(self, strip: bool = True, **kwargs: bool): + process = self._get(**kwargs) lines = process.stdout.splitlines() return lines if not strip else list(map(lambda l: l.strip(), lines)) - def firstline(self): - lines = self.lines() + def firstline(self, **kwargs: bool): + lines = self.lines(**kwargs) 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) - 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() - def code(self): - process = subprocess.run(self.command, capture_output=True, text=True) + return process - 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): - self.check_returncode = False + if print: + 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 = [] for arg in self.command: diff --git a/src/git_flow/main.py b/src/git_flow/main.py index 344df92..dfaa9c5 100755 --- a/src/git_flow/main.py +++ b/src/git_flow/main.py @@ -218,7 +218,7 @@ def tag_command(): message = output[pos+1:] 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: print_error("El ultimo merge ya tiene tag: " + output)