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

Fix: LF is replaced with CRLF on Windows #59

Merged
merged 1 commit into from Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions bumpversion/cli.py
Expand Up @@ -197,7 +197,9 @@ def main(original_args=None):

logger.info("Reading config file {}:".format(config_file))
# TODO: this is a DEBUG level log
logger.info(io.open(config_file, "rt", encoding="utf-8").read())
with io.open(config_file, "rt", encoding="utf-8") as f:
logger.info(f.read())
config_new_lines = f.newlines

try:
# TODO: we're reading the config file twice.
Expand Down Expand Up @@ -580,7 +582,7 @@ def main(original_args=None):
logger.info(new_config.getvalue())

if write_to_config_file:
with io.open(config_file, "wt", encoding="utf-8") as f:
with io.open(config_file, "wt", encoding="utf-8", newline=config_new_lines) as f:
f.write(new_config.getvalue())

except UnicodeEncodeError:
Expand Down
3 changes: 2 additions & 1 deletion bumpversion/utils.py
Expand Up @@ -91,6 +91,7 @@ def replace(self, current_version, new_version, context, dry_run):

with io.open(self.path, "rt", encoding="utf-8") as f:
file_content_before = f.read()
file_new_lines = f.newlines

context["current_version"] = self._versionconfig.serialize(
current_version, context
Expand Down Expand Up @@ -135,7 +136,7 @@ def replace(self, current_version, new_version, context, dry_run):
)

if not dry_run:
with io.open(self.path, "wt", encoding="utf-8") as f:
with io.open(self.path, "wt", encoding="utf-8", newline=file_new_lines) as f:
f.write(file_content_after)

def __str__(self):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli.py
Expand Up @@ -1916,6 +1916,28 @@ def test_correct_interpolation_for_setup_cfg_files(tmpdir, configfile):
assert "current_version = 1.0.0" in tmpdir.join(configfile).read()


@pytest.mark.parametrize("newline", [b'\n', b'\r\n'])
def test_retain_newline(tmpdir, configfile, newline):
tmpdir.join("file.py").write_binary(dedent("""
0.7.2
Some Content
""").strip().encode(encoding='UTF-8').replace(b'\n', newline))
tmpdir.chdir()

tmpdir.join(configfile).write_binary(dedent("""
[bumpversion]
current_version = 0.7.2
search = {current_version}
replace = {new_version}
[bumpversion:file:file.py]
""").strip().encode(encoding='UTF-8').replace(b'\n', newline))

main(["major"])

assert newline in tmpdir.join("file.py").read_binary()
assert newline in tmpdir.join(configfile).read_binary()


class TestSplitArgsInOptionalAndPositional:

def test_all_optional(self):
Expand Down