git-env 0.4.0__tar.gz → 0.5.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-env
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Sync environment files across linked git worktrees
5
5
  Author: Alex Ward
6
6
  Author-email: Alex Ward <alxwrd@googlemail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "git-env"
3
- version = "0.4.0"
3
+ version = "0.5.0"
4
4
  description = "Sync environment files across linked git worktrees"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -91,7 +91,7 @@ def detect_repository(cwd: Path | None = None) -> Repository:
91
91
  _git("rev-parse", "--path-format=absolute", "--show-toplevel", cwd=cwd).out
92
92
  ).resolve()
93
93
 
94
- _check_pwd_within_worktree(worktree_root)
94
+ _check_pwd_within_worktree(cwd)
95
95
 
96
96
  return Repository(
97
97
  git_dir=git_dir.resolve(),
@@ -101,11 +101,11 @@ def detect_repository(cwd: Path | None = None) -> Repository:
101
101
  )
102
102
 
103
103
 
104
- def _check_pwd_within_worktree(worktree_root: Path) -> None:
104
+ def _check_pwd_within_worktree(cwd: Path) -> None:
105
105
  """Paranoid check (spec: "Safety rails") that the shell-reported `$PWD`
106
- is actually inside the worktree we just resolved. Catches weird
107
- invocations (e.g. a symlinked directory pointing somewhere else) where
108
- the shell's notion of cwd has diverged from the real one.
106
+ is actually the directory we resolved everything else from. Catches
107
+ weird invocations (e.g. a symlinked directory pointing somewhere else)
108
+ where the shell's notion of cwd has diverged from the real one.
109
109
 
110
110
  Skipped if `$PWD` isn't set, since not every caller sets it.
111
111
  """
@@ -113,10 +113,8 @@ def _check_pwd_within_worktree(worktree_root: Path) -> None:
113
113
  if not pwd:
114
114
  return
115
115
  resolved_pwd = Path(pwd).resolve()
116
- if resolved_pwd != worktree_root and worktree_root not in resolved_pwd.parents:
117
- raise RepoError(
118
- f"$PWD ({pwd}) is not within the current worktree at {worktree_root}"
119
- )
116
+ if resolved_pwd != cwd:
117
+ raise RepoError(f"$PWD ({pwd}) is not within the current worktree at {cwd}")
120
118
 
121
119
 
122
120
  def check_primary_clean(
@@ -116,6 +116,22 @@ def _atomic_copy(src: Path, dest: Path) -> None:
116
116
  raise SyncIOError(f"failed to copy {src} -> {dest}: {exc}") from exc
117
117
 
118
118
 
119
+ def _exclude_can_ever_match(config: SyncConfig) -> bool:
120
+ """Whether any filename could possibly satisfy both `config.patterns` and
121
+ `config.exclude` (both are fnmatch globs).
122
+
123
+ Exclude entries are almost always literal filenames (e.g. ".env.example"),
124
+ so testing each one against every include pattern is a cheap, correct
125
+ way to rule out the common case (e.g. patterns=(".env",) can never match
126
+ ".env.example") without walking the filesystem to find out.
127
+ """
128
+ return any(
129
+ fnmatch.fnmatch(exclude, pattern)
130
+ for pattern in config.patterns
131
+ for exclude in config.exclude
132
+ )
133
+
134
+
119
135
  def _cleanup_excluded_in_linked(
120
136
  worktree_root: Path,
121
137
  config: SyncConfig,
@@ -129,6 +145,9 @@ def _cleanup_excluded_in_linked(
129
145
  Excluded patterns are for committed templates (e.g. .env.example) that git
130
146
  checks out into linked worktrees but that sync should never treat as env files.
131
147
  """
148
+ if not _exclude_can_ever_match(config):
149
+ return 0
150
+
132
151
  root = worktree_root
133
152
  search_root = (root / path) if path else root
134
153
  if not search_root.is_dir():
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes