From 96d684e8e2bd5778084d74a610bb0ec12e24191d Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Wed, 4 Feb 2026 20:06:49 +0000 Subject: [PATCH] Add detector modules --- confsync/detectors/git.py | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 confsync/detectors/git.py diff --git a/confsync/detectors/git.py b/confsync/detectors/git.py new file mode 100644 index 0000000..de796f4 --- /dev/null +++ b/confsync/detectors/git.py @@ -0,0 +1,58 @@ +"""Git configuration file detectors.""" + +from pathlib import Path +from typing import List, TYPE_CHECKING + +from confsync.detectors.base import BaseDetector, detector +from confsync.models.config_models import ConfigCategory + +if TYPE_CHECKING: + from confsync.models.config_models import ConfigFile + + +@detector +class GitConfigDetector(BaseDetector): + """Detector for Git configurations.""" + + category = ConfigCategory.GIT + tool_name = "git" + + def get_default_locations(self) -> List[str]: + """Get Git config locations.""" + return [ + str(Path.home() / ".gitconfig"), + str(Path.home() / ".gitattributes"), + str(Path.home() / ".gitignore"), + str(Path.home() / ".config" / "git"), + ] + + def get_file_patterns(self) -> List[str]: + """Get Git file patterns.""" + return [".gitconfig", ".gitattributes", ".gitignore"] + + def detect(self) -> List["ConfigFile"]: + """Detect Git configuration files.""" + configs = [] + home = Path.home() + + git_files = [ + home / ".gitconfig", + home / ".gitattributes", + home / ".gitignore", + ] + + for git_file in git_files: + if git_file.exists(): + config = self._create_config_file(str(git_file)) + config.metadata = {"version_control": "git"} + configs.append(config) + + git_config_dir = home / ".config" / "git" + if git_config_dir.exists() and git_config_dir.is_dir(): + for file_path in git_config_dir.iterdir(): + if file_path.is_file(): + config = self._create_config_file(str(file_path)) + config.metadata = {"version_control": "git", "xdg": True} + configs.append(config) + + return configs