FossilRepo
Fix fossil CLI: set USER=fossilrepo env var on all subprocess calls
Commit
d14eafa37f159720bb7fb02de22d70668d5e2379f87c9894918518f9b6d3afdb
Parent
4c30590c93bde6c…
1 file changed
+12
-6
+12
-6
| --- fossil/cli.py | ||
| +++ fossil/cli.py | ||
| @@ -12,13 +12,19 @@ | ||
| 12 | 12 | from constance import config |
| 13 | 13 | |
| 14 | 14 | binary = config.FOSSIL_BINARY_PATH |
| 15 | 15 | self.binary = binary |
| 16 | 16 | |
| 17 | + @property | |
| 18 | + def _env(self): | |
| 19 | + import os | |
| 20 | + | |
| 21 | + return {**os.environ, "USER": "fossilrepo"} | |
| 22 | + | |
| 17 | 23 | def _run(self, *args: str, timeout: int = 30) -> subprocess.CompletedProcess: |
| 18 | 24 | cmd = [self.binary, *args] |
| 19 | - return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, check=True) | |
| 25 | + return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, check=True, env=self._env) | |
| 20 | 26 | |
| 21 | 27 | def init(self, path: Path) -> Path: |
| 22 | 28 | """Create a new .fossil repository.""" |
| 23 | 29 | path.parent.mkdir(parents=True, exist_ok=True) |
| 24 | 30 | self._run("init", str(path)) |
| @@ -91,11 +97,11 @@ | ||
| 91 | 97 | "user": m.group(3).strip(), |
| 92 | 98 | "text": m.group(4), |
| 93 | 99 | } |
| 94 | 100 | ) |
| 95 | 101 | # Close checkout |
| 96 | - subprocess.run([self.binary, "close", "--force"], capture_output=True, cwd=tmpdir, timeout=10) | |
| 102 | + subprocess.run([self.binary, "close", "--force"], capture_output=True, cwd=tmpdir, timeout=10, env=self._env) | |
| 97 | 103 | except Exception: |
| 98 | 104 | pass |
| 99 | 105 | finally: |
| 100 | 106 | import shutil |
| 101 | 107 | |
| @@ -137,31 +143,31 @@ | ||
| 137 | 143 | def wiki_commit(self, repo_path: Path, page_name: str, content: str, user: str = "") -> bool: |
| 138 | 144 | """Create or update a wiki page. Pipes content to fossil wiki commit.""" |
| 139 | 145 | cmd = [self.binary, "wiki", "commit", page_name, "-R", str(repo_path)] |
| 140 | 146 | if user: |
| 141 | 147 | cmd.extend(["--technote-user", user]) |
| 142 | - result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30) | |
| 148 | + result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30, env=self._env) | |
| 143 | 149 | return result.returncode == 0 |
| 144 | 150 | |
| 145 | 151 | def wiki_create(self, repo_path: Path, page_name: str, content: str) -> bool: |
| 146 | 152 | """Create a new wiki page.""" |
| 147 | 153 | cmd = [self.binary, "wiki", "create", page_name, "-R", str(repo_path)] |
| 148 | - result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30) | |
| 154 | + result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30, env=self._env) | |
| 149 | 155 | return result.returncode == 0 |
| 150 | 156 | |
| 151 | 157 | def ticket_add(self, repo_path: Path, fields: dict) -> bool: |
| 152 | 158 | """Add a new ticket. Fields dict maps field names to values.""" |
| 153 | 159 | cmd = [self.binary, "ticket", "add", "-R", str(repo_path)] |
| 154 | 160 | for key, value in fields.items(): |
| 155 | 161 | cmd.append(f"{key}") |
| 156 | 162 | cmd.append(f"{value}") |
| 157 | - result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) | |
| 163 | + result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, env=self._env) | |
| 158 | 164 | return result.returncode == 0 |
| 159 | 165 | |
| 160 | 166 | def ticket_change(self, repo_path: Path, uuid: str, fields: dict) -> bool: |
| 161 | 167 | """Update an existing ticket.""" |
| 162 | 168 | cmd = [self.binary, "ticket", "change", uuid, "-R", str(repo_path)] |
| 163 | 169 | for key, value in fields.items(): |
| 164 | 170 | cmd.append(f"{key}") |
| 165 | 171 | cmd.append(f"{value}") |
| 166 | - result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) | |
| 172 | + result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, env=self._env) | |
| 167 | 173 | return result.returncode == 0 |
| 168 | 174 |
| --- fossil/cli.py | |
| +++ fossil/cli.py | |
| @@ -12,13 +12,19 @@ | |
| 12 | from constance import config |
| 13 | |
| 14 | binary = config.FOSSIL_BINARY_PATH |
| 15 | self.binary = binary |
| 16 | |
| 17 | def _run(self, *args: str, timeout: int = 30) -> subprocess.CompletedProcess: |
| 18 | cmd = [self.binary, *args] |
| 19 | return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, check=True) |
| 20 | |
| 21 | def init(self, path: Path) -> Path: |
| 22 | """Create a new .fossil repository.""" |
| 23 | path.parent.mkdir(parents=True, exist_ok=True) |
| 24 | self._run("init", str(path)) |
| @@ -91,11 +97,11 @@ | |
| 91 | "user": m.group(3).strip(), |
| 92 | "text": m.group(4), |
| 93 | } |
| 94 | ) |
| 95 | # Close checkout |
| 96 | subprocess.run([self.binary, "close", "--force"], capture_output=True, cwd=tmpdir, timeout=10) |
| 97 | except Exception: |
| 98 | pass |
| 99 | finally: |
| 100 | import shutil |
| 101 | |
| @@ -137,31 +143,31 @@ | |
| 137 | def wiki_commit(self, repo_path: Path, page_name: str, content: str, user: str = "") -> bool: |
| 138 | """Create or update a wiki page. Pipes content to fossil wiki commit.""" |
| 139 | cmd = [self.binary, "wiki", "commit", page_name, "-R", str(repo_path)] |
| 140 | if user: |
| 141 | cmd.extend(["--technote-user", user]) |
| 142 | result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30) |
| 143 | return result.returncode == 0 |
| 144 | |
| 145 | def wiki_create(self, repo_path: Path, page_name: str, content: str) -> bool: |
| 146 | """Create a new wiki page.""" |
| 147 | cmd = [self.binary, "wiki", "create", page_name, "-R", str(repo_path)] |
| 148 | result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30) |
| 149 | return result.returncode == 0 |
| 150 | |
| 151 | def ticket_add(self, repo_path: Path, fields: dict) -> bool: |
| 152 | """Add a new ticket. Fields dict maps field names to values.""" |
| 153 | cmd = [self.binary, "ticket", "add", "-R", str(repo_path)] |
| 154 | for key, value in fields.items(): |
| 155 | cmd.append(f"{key}") |
| 156 | cmd.append(f"{value}") |
| 157 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) |
| 158 | return result.returncode == 0 |
| 159 | |
| 160 | def ticket_change(self, repo_path: Path, uuid: str, fields: dict) -> bool: |
| 161 | """Update an existing ticket.""" |
| 162 | cmd = [self.binary, "ticket", "change", uuid, "-R", str(repo_path)] |
| 163 | for key, value in fields.items(): |
| 164 | cmd.append(f"{key}") |
| 165 | cmd.append(f"{value}") |
| 166 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) |
| 167 | return result.returncode == 0 |
| 168 |
| --- fossil/cli.py | |
| +++ fossil/cli.py | |
| @@ -12,13 +12,19 @@ | |
| 12 | from constance import config |
| 13 | |
| 14 | binary = config.FOSSIL_BINARY_PATH |
| 15 | self.binary = binary |
| 16 | |
| 17 | @property |
| 18 | def _env(self): |
| 19 | import os |
| 20 | |
| 21 | return {**os.environ, "USER": "fossilrepo"} |
| 22 | |
| 23 | def _run(self, *args: str, timeout: int = 30) -> subprocess.CompletedProcess: |
| 24 | cmd = [self.binary, *args] |
| 25 | return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, check=True, env=self._env) |
| 26 | |
| 27 | def init(self, path: Path) -> Path: |
| 28 | """Create a new .fossil repository.""" |
| 29 | path.parent.mkdir(parents=True, exist_ok=True) |
| 30 | self._run("init", str(path)) |
| @@ -91,11 +97,11 @@ | |
| 97 | "user": m.group(3).strip(), |
| 98 | "text": m.group(4), |
| 99 | } |
| 100 | ) |
| 101 | # Close checkout |
| 102 | subprocess.run([self.binary, "close", "--force"], capture_output=True, cwd=tmpdir, timeout=10, env=self._env) |
| 103 | except Exception: |
| 104 | pass |
| 105 | finally: |
| 106 | import shutil |
| 107 | |
| @@ -137,31 +143,31 @@ | |
| 143 | def wiki_commit(self, repo_path: Path, page_name: str, content: str, user: str = "") -> bool: |
| 144 | """Create or update a wiki page. Pipes content to fossil wiki commit.""" |
| 145 | cmd = [self.binary, "wiki", "commit", page_name, "-R", str(repo_path)] |
| 146 | if user: |
| 147 | cmd.extend(["--technote-user", user]) |
| 148 | result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30, env=self._env) |
| 149 | return result.returncode == 0 |
| 150 | |
| 151 | def wiki_create(self, repo_path: Path, page_name: str, content: str) -> bool: |
| 152 | """Create a new wiki page.""" |
| 153 | cmd = [self.binary, "wiki", "create", page_name, "-R", str(repo_path)] |
| 154 | result = subprocess.run(cmd, input=content, capture_output=True, text=True, timeout=30, env=self._env) |
| 155 | return result.returncode == 0 |
| 156 | |
| 157 | def ticket_add(self, repo_path: Path, fields: dict) -> bool: |
| 158 | """Add a new ticket. Fields dict maps field names to values.""" |
| 159 | cmd = [self.binary, "ticket", "add", "-R", str(repo_path)] |
| 160 | for key, value in fields.items(): |
| 161 | cmd.append(f"{key}") |
| 162 | cmd.append(f"{value}") |
| 163 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, env=self._env) |
| 164 | return result.returncode == 0 |
| 165 | |
| 166 | def ticket_change(self, repo_path: Path, uuid: str, fields: dict) -> bool: |
| 167 | """Update an existing ticket.""" |
| 168 | cmd = [self.binary, "ticket", "change", uuid, "-R", str(repo_path)] |
| 169 | for key, value in fields.items(): |
| 170 | cmd.append(f"{key}") |
| 171 | cmd.append(f"{value}") |
| 172 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=30, env=self._env) |
| 173 | return result.returncode == 0 |
| 174 |