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

added --allow-dirty option #42

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 7 additions & 1 deletion bumpversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ def main(original_args=None):
parser3.add_argument('--new-version', metavar='VERSION',
help='New version that should be in the files',
required=not 'new_version' in defaults)
parser3.add_argument('--allow-dirty', action='store_true', default=False,
help='Do not check that version control is non-dirty')


commitgroup = parser3.add_mutually_exclusive_group()

Expand Down Expand Up @@ -614,7 +617,10 @@ def main(original_args=None):

for vcs in VCS:
if vcs.is_usable():
vcs.assert_nondirty()
if args.allow_dirty:
pass
else:
vcs.assert_nondirty()
break
else:
vcs = None
Expand Down
19 changes: 18 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _mock_calls_to_string(called_mock):
EXPECTED_USAGE = ("""
usage: py.test [-h] [--config-file FILE] [--verbose] [--list] [--parse REGEX]
[--serialize FORMAT] [--current-version VERSION] [--dry-run]
--new-version VERSION [--commit | --no-commit]
--new-version VERSION [--allow-dirty] [--commit | --no-commit]
[--tag | --no-tag] [--tag-name TAG_NAME] [--message COMMIT_MSG]
part [file [file ...]]

Expand All @@ -72,6 +72,8 @@ def _mock_calls_to_string(called_mock):
--new-version VERSION
New version that should be in the files (default:
None)
--allow-dirty Do not check that version control is non-dirty
(default: False)
--commit Commit to version control (default: False)
--no-commit Do not commit to version control
--tag Create a tag in version control (default: False)
Expand All @@ -83,6 +85,18 @@ def _mock_calls_to_string(called_mock):
{current_version} → {new_version})
""" % DESCRIPTION).lstrip()

def _unidiff_output(expected, actual):
"""
Helper function. Returns a string containing the unified diff of two multiline strings.
"""

import difflib
expected=expected.splitlines(1)
actual=actual.splitlines(1)

diff=difflib.unified_diff(expected, actual)

return ''.join(diff)

def test_usage_string(tmpdir, capsys):
tmpdir.chdir()
Expand All @@ -91,6 +105,9 @@ def test_usage_string(tmpdir, capsys):
main(['--help'])

out, err = capsys.readouterr()
import pdb; pdb.set_trace()

s = _unidiff_output(out, EXPECTED_USAGE)
assert err == ""
assert out == EXPECTED_USAGE, "Usage string changed to \n\n\n{}\n\n\n".format(out)

Expand Down