is_ignored() broken for .gitignore in subdirectories
Closed this issue · 2 comments
dtrifiro commented
is_ignored()
is broken when dealing with nested .gitignore
files
import os
import sys
from scmrepo.git import Git
dirname = "ignore_issue_repo"
try:
os.mkdir(dirname)
except FileExistsError:
print(f"Delete {dirname} and try again", file=sys.stderr)
exit(1)
os.chdir(dirname)
repo = Git.init(".")
print("Initialized repo")
subdir = "subdir"
os.mkdir(subdir)
# create a .gitignore in the subdirectory
ignored_files = ("ignoredfile1", "ignoredfile2")
with open(f"{subdir}/.gitignore", "w") as fh:
for name in ignored_files:
fh.write(f"{name}\n")
# create dummy (gitignored) files
for file in ignored_files:
with open(f"{subdir}/{file}", "w") as fh:
fh.write("dummy")
repo.add(f"{subdir}/.gitignore")
repo.commit("add subdir gitignore")
ignored_files_ignored = [repo.is_ignored(f"{subdir}/file") for file in ignored_files]
assert all(ignored_files_ignored) # fails
dtrifiro commented
This was a false positive, I could not reproduce the issue anymore