diff options
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | coverage/html.py | 6 | ||||
-rw-r--r-- | tests/test_html.py | 7 |
3 files changed, 14 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 0b6e2490..5aaa0c4a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,9 @@ Unreleased - Fix: A colon in a decorator expression would cause an exclusion to end too early, preventing the exclusion of the decorated function. This is now fixed. +- Fix: The HTML report now will not overwrite a .gitignore file that already + exists in the HTML output directory (follow-on for `issue 1244`_). + .. _changes_612: diff --git a/coverage/html.py b/coverage/html.py index 52689050..d018d0f0 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -226,8 +226,10 @@ class HtmlReporter: # .gitignore can't be copied from the source tree because it would # prevent the static files from being checked in. - with open(os.path.join(self.directory, ".gitignore"), "w") as fgi: - fgi.write("# Created by coverage.py\n*\n") + gitigore_path = os.path.join(self.directory, ".gitignore") + if not os.path.exists(gitigore_path): + with open(gitigore_path, "w") as fgi: + fgi.write("# Created by coverage.py\n*\n") # The user may have extra CSS they want copied. if self.extra_css: diff --git a/tests/test_html.py b/tests/test_html.py index 51062f73..c8f9c1e6 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -284,6 +284,13 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest): assert "htmlcov/helper2_py.html" in self.files_written assert "htmlcov/main_file_py.html" in self.files_written + def test_dont_overwrite_gitignore(self): + self.create_initial_files() + self.make_file("htmlcov/.gitignore", "# ignore nothing") + self.run_coverage() + with open("htmlcov/.gitignore") as fgi: + assert fgi.read() == "# ignore nothing" + class HtmlTitleTest(HtmlTestHelpers, CoverageTest): """Tests of the HTML title support.""" |