Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting allow_dirty=False in the config file #183

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
time_context = {"now": datetime.now(), "utcnow": datetime.utcnow()}
special_char_context = {c: c for c in ("#", ";")}

FLAG_ARGUMENTS = [
"commit",
"tag",
"dry_run",
"allow_dirty",
"push",
"sign_tags",
]

OPTIONAL_ARGUMENTS_THAT_TAKE_VALUES = [
"--config-file",
Expand Down Expand Up @@ -294,13 +302,13 @@ def _load_configuration(config_file, explicit_config, defaults):
except NoOptionError:
pass # no default value then ;)

for boolvaluename in ("commit", "tag", "dry_run"):
for flag_argument in FLAG_ARGUMENTS:
try:
defaults[boolvaluename] = config.getboolean(
"bumpversion", boolvaluename
defaults[flag_argument] = config.getboolean(
"bumpversion", flag_argument
)
except NoOptionError:
pass # no default value then ;)
pass # no default value then (like, False-y)

part_configs = {}
files = []
Expand Down
49 changes: 43 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,12 @@ def test_bump_version_missing_part(tmpdir):
main(['bugfix', '--current-version', '1.0.0', 'file5'])


def test_dirty_work_dir(tmpdir, vcs):
def test_dirty_work_dir_without_allow_dirty_fails_with_warning(tmpdir, vcs):
tmpdir.chdir()
check_call([vcs, "init"])
tmpdir.join("dirty").write("i'm dirty")

check_call([vcs, "add", "dirty"])
vcs_name = "Mercurial" if vcs == "hg" else "Git"
vcs_output = "A dirty" if vcs == "hg" else "A dirty"

with pytest.raises(exceptions.WorkingDirectoryIsDirtyException):
with LogCapture() as log_capture:
Expand All @@ -600,14 +598,41 @@ def test_dirty_work_dir(tmpdir, vcs):
"{}\n"
"\n"
"Use --allow-dirty to override this if you know what you're doing.".format(
vcs_name,
vcs_output
"Mercurial" if vcs == "hg" else "Git",
"A dirty" if vcs == "hg" else "A dirty",
)
)
)


def test_force_dirty_work_dir(tmpdir, vcs):
def test_dirty_work_dir_with_allow_dirty_false_in_config_file_fails_with_warning(tmpdir, vcs):
tmpdir.chdir()
check_call([vcs, "init"])
tmpdir.join(".bumpversion.cfg").write("[bumpversion]\nallow_dirty = False\ncurrent_version = 1.0.0")
tmpdir.join("dirty").write("dirty file version 1.0.0")

check_call([vcs, "add", "dirty"])

with pytest.raises(exceptions.WorkingDirectoryIsDirtyException):
with LogCapture() as log_capture:
main(['patch', '--new-version', '2.0.0', 'dirty'])

log_capture.check_present(
(
'bumpversion.cli',
'WARNING',
"{} working directory is not clean:\n"
"{}\n"
"\n"
"Use --allow-dirty to override this if you know what you're doing.".format(
"Mercurial" if vcs == "hg" else "Git",
"A dirty" if vcs == "hg" else "A dirty",
)
)
)


def test_dirty_work_dir_with_allow_dirty_argument_passes(tmpdir, vcs):
tmpdir.chdir()
check_call([vcs, "init"])
tmpdir.join("dirty2").write("i'm dirty! 1.1.1")
Expand All @@ -625,6 +650,18 @@ def test_force_dirty_work_dir(tmpdir, vcs):
assert "i'm dirty! 1.1.2" == tmpdir.join("dirty2").read()


def test_dirty_work_with_allow_dirty_true_in_config_file_passes(tmpdir, vcs):
tmpdir.chdir()
check_call([vcs, "init"])
tmpdir.join(".bumpversion.cfg").write("[bumpversion]\nallow_dirty = True\ncurrent_version = 1.0.0")
tmpdir.join("dirty").write("dirty file version 1.0.0")

check_call([vcs, "add", "dirty"])

main(['patch', '--new-version', '2.0.0', 'dirty'])
assert "dirty file version 2.0.0" == tmpdir.join("dirty").read()


def test_bump_major(tmpdir):
tmpdir.join("fileMAJORBUMP").write("4.2.8")
tmpdir.chdir()
Expand Down