diff --git a/python/grass/gunittest/reporters.py b/python/grass/gunittest/reporters.py index 21afce314e1..45b1c386b27 100644 --- a/python/grass/gunittest/reporters.py +++ b/python/grass/gunittest/reporters.py @@ -19,7 +19,7 @@ import re from collections.abc import Iterable -from .utils import ensure_dir +from .utils import add_gitignore_to_dir, ensure_dir from .checkers import text_to_keyvalue @@ -330,9 +330,10 @@ def __init__(self, reporters, forgiving=False): def start(self, results_dir): # TODO: no directory cleaning (self.clean_before)? now cleaned by caller - # TODO: perhaps only those whoe need it should do it (even multiple times) + # TODO: perhaps only those who need it should do it (even multiple times) # and there is also the delete problem ensure_dir(os.path.abspath(results_dir)) + add_gitignore_to_dir(os.path.abspath(results_dir)) for reporter in self.reporters: try: reporter.start(results_dir) diff --git a/python/grass/gunittest/utils.py b/python/grass/gunittest/utils.py index d20f575325b..082366cacaf 100644 --- a/python/grass/gunittest/utils.py +++ b/python/grass/gunittest/utils.py @@ -11,6 +11,7 @@ import errno import os +from pathlib import Path import shutil import sys @@ -21,6 +22,12 @@ def ensure_dir(directory): os.makedirs(directory) +def add_gitignore_to_dir(directory): + gitignore_path = Path(directory) / ".gitignore" + if not Path(gitignore_path).exists(): + Path(gitignore_path).write_text("*") + + def silent_rmtree(filename): """Remove the file but do nothing if file does not exist.""" try: