filekeeper-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ """Advisory "this path is version-control ignored" warning.
2
+
3
+ Warn-only: Filekeeper still performs the write, but the result carries a warning
4
+ so an agent can notice that a file it just wrote will not be committed. Git is
5
+ consulted through an argument list (never a shell) with a short timeout, and any
6
+ failure degrades to "unknown" rather than an error.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import subprocess
12
+ from pathlib import Path
13
+
14
+ _TIMEOUT_SECONDS = 3.0
15
+
16
+
17
+ def _inside_git_worktree(root: Path, target: Path) -> bool:
18
+ for candidate in (root, *root.parents):
19
+ if (candidate / ".git").exists():
20
+ return True
21
+ return False
22
+
23
+
24
+ def git_ignored(root: Path, target: Path) -> bool | None:
25
+ """True/False when git can answer, ``None`` when it cannot or does not apply."""
26
+
27
+ if not _inside_git_worktree(root, target):
28
+ return None
29
+ try:
30
+ completed = subprocess.run(
31
+ ["git", "-C", str(root), "check-ignore", "--quiet", "--", str(target)],
32
+ capture_output=True,
33
+ timeout=_TIMEOUT_SECONDS,
34
+ check=False,
35
+ )
36
+ except (OSError, subprocess.SubprocessError):
37
+ return None
38
+ if completed.returncode == 0:
39
+ return True
40
+ if completed.returncode == 1:
41
+ return False
42
+ return None
43
+
44
+
45
+ def ignore_warning(root: Path, target: Path, relative_path: str) -> str | None:
46
+ if git_ignored(root, target) is True:
47
+ return (
48
+ f"{relative_path} is ignored by version control; this change will not "
49
+ "appear in the repository"
50
+ )
51
+ return None