summaryrefslogtreecommitdiff
path: root/coverage/html.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-01-11 18:57:52 -0500
committerNed Batchelder <ned@nedbatchelder.com>2022-01-11 16:20:58 -0800
commit6cbbc90dcd89d8499191a75133a6e2b29f52270a (patch)
tree9e26d0cdc30120d5a3031cf3a6e7b1326c268453 /coverage/html.py
parentd004b18a1ad59ec89b89c96c03a789a55cc51693 (diff)
downloadpython-coveragepy-git-6cbbc90dcd89d8499191a75133a6e2b29f52270a.tar.gz
fix: don't write a .gitignore unless the directory is empty
Diffstat (limited to 'coverage/html.py')
-rw-r--r--coverage/html.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/coverage/html.py b/coverage/html.py
index ae1d041f..342d2ad1 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -164,6 +164,7 @@ class HtmlReporter:
self.incr = IncrementalChecker(self.directory)
self.datagen = HtmlDataGeneration(self.coverage)
self.totals = Numbers(precision=self.config.precision)
+ self.directory_was_empty = False
self.template_globals = {
# Functions available in the templates.
@@ -224,11 +225,11 @@ class HtmlReporter:
for static in self.STATIC_FILES:
shutil.copyfile(data_filename(static), os.path.join(self.directory, static))
+ # Only write the .gitignore file if the directory was originally empty.
# .gitignore can't be copied from the source tree because it would
# prevent the static files from being checked in.
- gitigore_path = os.path.join(self.directory, ".gitignore")
- if not os.path.exists(gitigore_path):
- with open(gitigore_path, "w") as fgi:
+ if self.directory_was_empty:
+ with open(os.path.join(self.directory, ".gitignore"), "w") as fgi:
fgi.write("# Created by coverage.py\n*\n")
# The user may have extra CSS they want copied.
@@ -240,6 +241,8 @@ class HtmlReporter:
rootname = flat_rootname(fr.relative_filename())
html_filename = rootname + ".html"
ensure_dir(self.directory)
+ if not os.listdir(self.directory):
+ self.directory_was_empty = True
html_path = os.path.join(self.directory, html_filename)
# Get the numbers for this file.