Skip to content

Commit

Permalink
Merge pull request #208 from hartwork/issue-136-handle-dry-run-config…
Browse files Browse the repository at this point in the history
…uration-attempt

Handle attempt to combine --dry-run with live configuration (fixes #136)
  • Loading branch information
hartwork authored Dec 22, 2024
2 parents 8c6fa03 + eaa1f2e commit fd21706
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions git_delete_merged_branches/_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def __init__(self, pattern):
)


class _CannotDryRunConfigurationError(_DmbException):
def __init__(self, force_reconfiguration):
message = (
"Arguments --configure and --dry-run are not compatible."
if force_reconfiguration
else f"{APP}' need for configuration and argument --dry-run are not compatible."
)
super().__init__(message)


class DeleteMergedBranches:
_CONFIG_KEY_CONFIGURED = "delete-merged-branches.configured"
_CONFIG_VALUE_CONFIGURED = "5.0.0+" # i.e. most ancient version with compatible config
Expand Down Expand Up @@ -159,6 +169,8 @@ def _is_configured(cls, git_config):
def ensure_configured(self, force_reconfiguration):
git_config = self._git.extract_git_config()
if force_reconfiguration or not self._is_configured(git_config):
if self._git.pretend:
raise _CannotDryRunConfigurationError(force_reconfiguration)
self._configure(git_config)
git_config = self._git.extract_git_config()
assert self._is_configured(git_config)
Expand Down
4 changes: 4 additions & 0 deletions git_delete_merged_branches/_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def __init__(self, messenger, pretend, verbose, work_dir=None):
self._pretend = pretend
self._working_directory = work_dir

@property
def pretend(self):
return self._pretend

def _wrap_subprocess(self, subprocess_function, argv, is_write, pretend_result, env):
pretend = is_write and self._pretend
if self._verbose:
Expand Down

0 comments on commit fd21706

Please sign in to comment.