Commit 13f1e66
authored
🤖 fix: clean stale git index.lock before worktree operations (#1003)
## Problem
When using Mux, git operations (worktree create/delete/rename) can get
interrupted (user cancel, crash, terminal closed), leaving orphaned
`.git/index.lock` files in the main repository. This causes subsequent
git operations to fail with:
```
fatal: Unable to create '/Users/.../mux/.git/index.lock': File exists.
Another git process seems to be running in this repository...
```
## Solution
Added `cleanStaleLock()` helper that removes lock files older than 5
seconds before git operations that touch the main repository's index:
- `createWorktree`
- `removeWorktree`
- `pruneWorktrees`
- `WorktreeRuntime.createWorkspace`
- `WorktreeRuntime.renameWorkspace`
- `WorktreeRuntime.deleteWorkspace`
The 5-second threshold ensures we only remove orphaned locks, not locks
from legitimately running processes.
## Testing
Added unit tests for the `cleanStaleLock` function:
- Removes lock files older than threshold
- Does not remove recent lock files
- Handles missing lock files gracefully
---
_Generated with `mux`_1 parent 5cc443d commit 13f1e66
3 files changed
+96
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
7 | 34 | | |
8 | 35 | | |
9 | 36 | | |
| |||
79 | 106 | | |
80 | 107 | | |
81 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
82 | 112 | | |
83 | 113 | | |
84 | 114 | | |
| |||
192 | 222 | | |
193 | 223 | | |
194 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
195 | 228 | | |
196 | 229 | | |
197 | 230 | | |
| |||
206 | 239 | | |
207 | 240 | | |
208 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
209 | 245 | | |
210 | 246 | | |
211 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
178 | 184 | | |
179 | 185 | | |
180 | 186 | | |
| |||
209 | 215 | | |
210 | 216 | | |
211 | 217 | | |
| 218 | + | |
| 219 | + | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
| |||
0 commit comments