44
44
)
45
45
from ansiblelint .config import options
46
46
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
48
48
from ansiblelint .prerun import check_ansible_presence , prepare_environment
49
49
from ansiblelint .skip_utils import normalize_tag
50
50
from ansiblelint .version import __version__
@@ -200,6 +200,7 @@ def main(argv: Optional[List[str]] = None) -> int:
200
200
201
201
initialize_logger (options .verbosity )
202
202
_logger .debug ("Options: %s" , options )
203
+ _logger .debug (os .getcwd ())
203
204
204
205
app = App (options = options )
205
206
@@ -241,6 +242,8 @@ def main(argv: Optional[List[str]] = None) -> int:
241
242
"Matches found, running again on previous revision in order to detect regressions"
242
243
)
243
244
with _previous_revision ():
245
+ _logger .debug ("Options: %s" , options )
246
+ _logger .debug (os .getcwd ())
244
247
old_result = _get_matches (rules , options )
245
248
# remove old matches from current list
246
249
matches_delta = list (set (result .matches ) - set (old_result .matches ))
@@ -275,6 +278,9 @@ def main(argv: Optional[List[str]] = None) -> int:
275
278
def _previous_revision () -> Iterator [None ]:
276
279
"""Create or update a temporary workdir containing the previous revision."""
277
280
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 ]
278
284
revision = subprocess .run (
279
285
["git" , "rev-parse" , "HEAD^1" ],
280
286
check = True ,
@@ -285,9 +291,12 @@ def _previous_revision() -> Iterator[None]:
285
291
p = pathlib .Path (worktree_dir )
286
292
p .mkdir (parents = True , exist_ok = True )
287
293
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 ]
291
300
292
301
293
302
def _run_cli_entrypoint () -> None :
0 commit comments