@@ -276,15 +276,24 @@ def normalize_path_maybe_ignore(
276
276
return root_relative_path
277
277
278
278
279
- def path_is_ignored (
280
- path : Path , gitignore_dict : Dict [Path , PathSpec ], report : Report
279
+ def _path_is_ignored (
280
+ root_relative_path : str ,
281
+ root : Path ,
282
+ gitignore_dict : Dict [Path , PathSpec ],
283
+ report : Report ,
281
284
) -> bool :
285
+ path = root / root_relative_path
286
+ # Note that this logic is sensitive to the ordering of gitignore_dict. Callers must
287
+ # ensure that gitignore_dict is ordered from least specific to most specific.
282
288
for gitignore_path , pattern in gitignore_dict .items ():
283
- relative_path = normalize_path_maybe_ignore (path , gitignore_path , report )
284
- if relative_path is None :
289
+ try :
290
+ relative_path = path .relative_to (gitignore_path ).as_posix ()
291
+ except ValueError :
285
292
break
286
293
if pattern .match_file (relative_path ):
287
- report .path_ignored (path , "matches a .gitignore file content" )
294
+ report .path_ignored (
295
+ path .relative_to (root ), "matches a .gitignore file content"
296
+ )
288
297
return True
289
298
return False
290
299
@@ -326,7 +335,9 @@ def gen_python_files(
326
335
continue
327
336
328
337
# First ignore files matching .gitignore, if passed
329
- if gitignore_dict and path_is_ignored (child , gitignore_dict , report ):
338
+ if gitignore_dict and _path_is_ignored (
339
+ normalized_path , root , gitignore_dict , report
340
+ ):
330
341
continue
331
342
332
343
# Then ignore with `--exclude` `--extend-exclude` and `--force-exclude` options.
0 commit comments