Skip to content

Commit

Permalink
git addon: support user global gitignore
Browse files Browse the repository at this point in the history
Resolves: #671
Resolves: #672
Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Mar 23, 2024
1 parent 2ed2a36 commit 39dd2fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pkgcheck/addons/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,14 @@ def __init__(self, *args):
def _gitignore(self):
"""Load a repo's .gitignore and .git/info/exclude files for path matching."""
patterns = []
for path in (".gitignore", ".git/info/exclude"):
paths = (
pjoin(self.options.target_repo.location, ".gitignore"),
pjoin(self.options.target_repo.location, ".git/info/exclude"),
pjoin(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "git/ignore"),
)
for path in paths:
try:
with open(pjoin(self.options.target_repo.location, path)) as f:
with open(path) as f:
patterns.extend(f)
except (FileNotFoundError, IOError):
pass
Expand Down
4 changes: 4 additions & 0 deletions tests/addons/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pkgcore.ebuild.atom import atom as atom_cls
from pkgcore.restrictions import packages
from snakeoil.cli.exceptions import UserException
from snakeoil.contexts import os_environ
from snakeoil.fileutils import touch
from snakeoil.osutils import pjoin
from snakeoil.process import CommandNotFound, find_binary
Expand Down Expand Up @@ -466,6 +467,9 @@ def _setup(self, tool, tmp_path, repo):
self.addon = git.GitAddon(options)
self.cache_file = self.addon.cache_file(self.repo)

with os_environ(XDG_CONFIG_HOME=self.cache_dir):
yield

def test_git_unavailable(self, tool):
args = ["scan", "--cache-dir", self.cache_dir, "--repo", self.repo.location]
options, _ = tool.parse_args(args)
Expand Down

0 comments on commit 39dd2fb

Please sign in to comment.