Skip to content

Commit fd4a746

Browse files
clementmartinClément Martin
andauthored
Make exclude files work with progressive mode (#1767)
Co-authored-by: Clément Martin <[email protected]>
1 parent 15565da commit fd4a746

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/ansiblelint/__main__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
)
4545
from ansiblelint.config import options
4646
from ansiblelint.constants import ANSIBLE_MISSING_RC, EXIT_CONTROL_C_RC
47-
from ansiblelint.file_utils import cwd
47+
from ansiblelint.file_utils import abspath, cwd, normpath
4848
from ansiblelint.prerun import check_ansible_presence, prepare_environment
4949
from ansiblelint.skip_utils import normalize_tag
5050
from ansiblelint.version import __version__
@@ -200,6 +200,7 @@ def main(argv: Optional[List[str]] = None) -> int:
200200

201201
initialize_logger(options.verbosity)
202202
_logger.debug("Options: %s", options)
203+
_logger.debug(os.getcwd())
203204

204205
app = App(options=options)
205206

@@ -241,6 +242,8 @@ def main(argv: Optional[List[str]] = None) -> int:
241242
"Matches found, running again on previous revision in order to detect regressions"
242243
)
243244
with _previous_revision():
245+
_logger.debug("Options: %s", options)
246+
_logger.debug(os.getcwd())
244247
old_result = _get_matches(rules, options)
245248
# remove old matches from current list
246249
matches_delta = list(set(result.matches) - set(old_result.matches))
@@ -275,6 +278,9 @@ def main(argv: Optional[List[str]] = None) -> int:
275278
def _previous_revision() -> Iterator[None]:
276279
"""Create or update a temporary workdir containing the previous revision."""
277280
worktree_dir = f"{options.cache_dir}/old-rev"
281+
# Update options.exclude_paths to include use the temporary workdir.
282+
rel_exclude_paths = [normpath(p) for p in options.exclude_paths]
283+
options.exclude_paths = [abspath(p, worktree_dir) for p in rel_exclude_paths]
278284
revision = subprocess.run(
279285
["git", "rev-parse", "HEAD^1"],
280286
check=True,
@@ -285,9 +291,12 @@ def _previous_revision() -> Iterator[None]:
285291
p = pathlib.Path(worktree_dir)
286292
p.mkdir(parents=True, exist_ok=True)
287293
os.system(f"git worktree add -f {worktree_dir} 2>/dev/null")
288-
with cwd(worktree_dir):
289-
os.system(f"git checkout {revision}")
290-
yield
294+
try:
295+
with cwd(worktree_dir):
296+
os.system(f"git checkout {revision}")
297+
yield
298+
finally:
299+
options.exclude_paths = [abspath(p, os.getcwd()) for p in rel_exclude_paths]
291300

292301

293302
def _run_cli_entrypoint() -> None:

0 commit comments

Comments
 (0)