FossilRepo

Fix fossil CLI: set USER=fossilrepo env var on all subprocess calls

lmata 2026-04-07 02:40 trunk
Commit d14eafa37f159720bb7fb02de22d70668d5e2379f87c9894918518f9b6d3afdb
1 file changed +12 -6
+12 -6
--- fossil/cli.py
+++ fossil/cli.py
@@ -12,13 +12,19 @@
1212
from constance import config
1313
1414
binary = config.FOSSIL_BINARY_PATH
1515
self.binary = binary
1616
17
+ @property
18
+ def _env(self):
19
+ import os
20
+
21
+ return {**os.environ, "USER": "fossilrepo"}
22
+
1723
def _run(self, *args: str, timeout: int = 30) -> subprocess.CompletedProcess:
1824
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)
2026
2127
def init(self, path: Path) -> Path:
2228
"""Create a new .fossil repository."""
2329
path.parent.mkdir(parents=True, exist_ok=True)
2430
self._run("init", str(path))
@@ -91,11 +97,11 @@
9197
"user": m.group(3).strip(),
9298
"text": m.group(4),
9399
}
94100
)
95101
# 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)
97103
except Exception:
98104
pass
99105
finally:
100106
import shutil
101107
@@ -137,31 +143,31 @@
137143
def wiki_commit(self, repo_path: Path, page_name: str, content: str, user: str = "") -> bool:
138144
"""Create or update a wiki page. Pipes content to fossil wiki commit."""
139145
cmd = [self.binary, "wiki", "commit", page_name, "-R", str(repo_path)]
140146
if user:
141147
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)
143149
return result.returncode == 0
144150
145151
def wiki_create(self, repo_path: Path, page_name: str, content: str) -> bool:
146152
"""Create a new wiki page."""
147153
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)
149155
return result.returncode == 0
150156
151157
def ticket_add(self, repo_path: Path, fields: dict) -> bool:
152158
"""Add a new ticket. Fields dict maps field names to values."""
153159
cmd = [self.binary, "ticket", "add", "-R", str(repo_path)]
154160
for key, value in fields.items():
155161
cmd.append(f"{key}")
156162
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)
158164
return result.returncode == 0
159165
160166
def ticket_change(self, repo_path: Path, uuid: str, fields: dict) -> bool:
161167
"""Update an existing ticket."""
162168
cmd = [self.binary, "ticket", "change", uuid, "-R", str(repo_path)]
163169
for key, value in fields.items():
164170
cmd.append(f"{key}")
165171
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)
167173
return result.returncode == 0
168174
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button