diff --git a/CHANGES.rst b/CHANGES.rst index ec58069c..132f5aea 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,10 @@ Changelog for zest.releaser needed for most entry points, btw). Fixes `issue 370 `_. +- Allowing for retry for ``git push``, which might fail because of a protected + branch. Also displaying that possible cause when it occurs. Fixes `issue 385 + `_. + 9.0.0a2 (2023-07-19) -------------------- diff --git a/zest/releaser/baserelease.py b/zest/releaser/baserelease.py index f0b8f60a..82b4e88b 100644 --- a/zest/releaser/baserelease.py +++ b/zest/releaser/baserelease.py @@ -408,7 +408,11 @@ def _push(self): default_anwer = self.zest_releaser_config.push_changes() if utils.ask("OK to push commits to the server?", default=default_anwer): for push_cmd in push_cmds: - output = execute_command(push_cmd) + output = execute_command( + push_cmd, + allow_retry=True, + fail_message="Perhaps the main branch is protected?", + ) logger.info(output) def _run_hooks(self, when): diff --git a/zest/releaser/utils.py b/zest/releaser/utils.py index 29da211d..8e128adf 100644 --- a/zest/releaser/utils.py +++ b/zest/releaser/utils.py @@ -740,6 +740,9 @@ def execute_command( result = _execute_command(command, cwd=cwd, extra_environ=extra_environ) if not allow_retry: return result + if AUTO_RESPONSE: + # Also don't ask for retry, just return the result. + return result if Fore.RED not in result: show_interesting_lines(result) return result @@ -770,7 +773,11 @@ def execute_commands(commands, allow_retry=False, fail_message=""): def retry_yes_no(command): - """Ask the user to maybe retry a command.""" + """Ask the user to maybe retry a command. + + This is used for the twine upload command and for the final 'git push'. + + """ explanation = """ You have these options for retrying (first character is enough): Yes: Retry. Do this if it looks like a temporary Internet or PyPI outage. @@ -778,7 +785,8 @@ def retry_yes_no(command): case of a credentials problem. No: Do not retry, but continue with the rest of the process. Quit: Stop completely. Note that the postrelease step has not - been run yet, you need to do that manually. + finished fully. You need to do the 'git push' and possibly the upload + manually. ?: Show this help.""" explanation = textwrap.dedent(explanation) question = "Retry this command? [Yes/no/quit/?]"