@@ -276,15 +276,24 @@ def normalize_path_maybe_ignore(
276276 return root_relative_path
277277
278278
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 ,
281284) -> 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.
282288 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 :
285292 break
286293 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+ )
288297 return True
289298 return False
290299
@@ -326,7 +335,9 @@ def gen_python_files(
326335 continue
327336
328337 # 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+ ):
330341 continue
331342
332343 # Then ignore with `--exclude` `--extend-exclude` and `--force-exclude` options.
0 commit comments