Skip to content

Commit 88d55de

Browse files
committed
feat: html output directory gets a .gitignore file. #1244
1 parent 7fd1ea3 commit 88d55de

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Unreleased
3737
a ``-q/--quiet`` option to suppress the messages they write to stdout about
3838
what they are doing (`issue 1254`_).
3939

40+
- Feature: The ``html`` command writes a ``.gitignore`` file into the HTML
41+
output directory, to prevent the report from being committed to git. If you
42+
want to commit it, you will need to delete that file. Closes `issue 1244`_.
43+
4044
- Feature: Added support for PyPy 3.8.
4145

4246
- Fix: more generated code is now excluded from measurement. Code such as
@@ -58,6 +62,7 @@ Unreleased
5862
.. _issue 553: https://github.com/nedbat/coveragepy/issues/553
5963
.. _issue 840: https://github.com/nedbat/coveragepy/issues/840
6064
.. _issue 1160: https://github.com/nedbat/coveragepy/issues/1160
65+
.. _issue 1244: https://github.com/nedbat/coveragepy/issues/1244
6166
.. _issue 1254: https://github.com/nedbat/coveragepy/issues/1254
6267
.. _attrs: https://www.attrs.org/
6368

coverage/html.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def make_local_static_report_files(self):
224224
for static in self.STATIC_FILES:
225225
shutil.copyfile(data_filename(static), os.path.join(self.directory, static))
226226

227+
# .gitignore can't be copied from the source tree because it would
228+
# prevent the static files from being checked in.
229+
with open(os.path.join(self.directory, ".gitignore"), "w") as fgi:
230+
fgi.write("# Created by coverage.py\n*\n")
231+
227232
# The user may have extra CSS they want copied.
228233
if self.extra_css:
229234
shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css))

tests/test_html.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def assert_htmlcov_files_exist(self):
144144
self.assert_exists("htmlcov/helper2_py.html")
145145
self.assert_exists("htmlcov/style.css")
146146
self.assert_exists("htmlcov/coverage_html.js")
147+
self.assert_exists("htmlcov/.gitignore")
147148

148149
def test_html_created(self):
149150
# Test basic HTML generation: files should be created.

0 commit comments

Comments
 (0)