claude-dev-env 8.112.0 → 8.112.1
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.
package/package.json
CHANGED
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
- When the fast-forward fails because the files were already copied in,
|
|
18
18
|
moves HEAD with a mixed reset, which writes no files. It keeps that move
|
|
19
19
|
only when every file the remote changed now matches the remote
|
|
20
|
+
- When a -Mirror tree diverged from the remote, keeps the old tip under
|
|
21
|
+
refs/mirror-backup/, moves HEAD with a mixed reset, and stashes every
|
|
22
|
+
tracked file that still differs from the remote
|
|
20
23
|
- Logs and exits non-zero on skip, diverge, or failure so a Task Scheduler
|
|
21
24
|
history row can surface a problem instead of a silent no-op
|
|
22
25
|
|
|
23
26
|
Exit codes: 0 success, 1 git operation failed, 2 configuration or repo
|
|
24
|
-
problem, 3 skipped by a safety rule, 4 diverged from the remote
|
|
27
|
+
problem, 3 skipped by a safety rule, 4 diverged from the remote (a -Mirror
|
|
28
|
+
tree realigns instead).
|
|
25
29
|
|
|
26
30
|
.PARAMETER RepoPath
|
|
27
31
|
Absolute path to the git working tree. Required.
|
|
@@ -58,6 +62,15 @@
|
|
|
58
62
|
back to the old checkout and the run exits 1. Without the switch, any
|
|
59
63
|
other checkout is skipped.
|
|
60
64
|
|
|
65
|
+
A mirror whose history diverged from the remote, as after a rewrite of the
|
|
66
|
+
remote history, realigns instead of exiting 4. The old tip stays reachable
|
|
67
|
+
as refs/mirror-backup/<yyyy-MM-dd>-<tip>, HEAD and the index move to the
|
|
68
|
+
remote tip with a mixed reset, and every tracked file that still differs is
|
|
69
|
+
stashed as "mirror realign <yyyy-MM-dd>: tree before moving <tip> to
|
|
70
|
+
<remote>/<branch>". Untracked files are never touched. A staged index skips
|
|
71
|
+
the realign. When a step fails, HEAD goes back to the old tip and the run
|
|
72
|
+
exits 1.
|
|
73
|
+
|
|
61
74
|
.PARAMETER LogPath
|
|
62
75
|
Absolute path to the run log (default: $HOME\.claude\logs\sync-repo-main.log).
|
|
63
76
|
#>
|
|
@@ -284,6 +297,67 @@ function Invoke-AdoptCopiedTree {
|
|
|
284
297
|
return $false
|
|
285
298
|
}
|
|
286
299
|
|
|
300
|
+
function Invoke-MirrorRealign {
|
|
301
|
+
<#
|
|
302
|
+
Moves a mirror whose history diverged from the remote onto the remote
|
|
303
|
+
tip. A rewritten remote history leaves a mirror with commits the remote
|
|
304
|
+
no longer holds, and a fast-forward can never reach it again.
|
|
305
|
+
|
|
306
|
+
The old tip is kept under refs/mirror-backup/ first. A mixed reset then
|
|
307
|
+
moves HEAD and the index to the remote tip and writes no files. Every
|
|
308
|
+
tracked file that still differs from the remote is stashed, which puts the
|
|
309
|
+
remote content in its place and keeps the old content in the stash list.
|
|
310
|
+
Untracked files stay. A failure after the reset puts HEAD back on the old
|
|
311
|
+
tip, so the next run meets the same state and tries again.
|
|
312
|
+
#>
|
|
313
|
+
param(
|
|
314
|
+
[Parameter(Mandatory)]
|
|
315
|
+
[string]$LocalTip,
|
|
316
|
+
[Parameter(Mandatory)]
|
|
317
|
+
[string]$RemoteRef
|
|
318
|
+
)
|
|
319
|
+
$stagedResult = Invoke-Git -Arguments @('diff', '--cached', '--quiet')
|
|
320
|
+
if ($stagedResult.ExitCode -ne 0) {
|
|
321
|
+
Write-SyncLog -Level 'ERROR' -Message 'realign skipped: the index holds staged changes'
|
|
322
|
+
return $false
|
|
323
|
+
}
|
|
324
|
+
$backupRef = 'refs/mirror-backup/{0}-{1}' -f (Get-Date -Format 'yyyy-MM-dd'), $LocalTip.Substring(0, 12)
|
|
325
|
+
$backupResult = Invoke-Git -Arguments @('update-ref', $backupRef, $LocalTip)
|
|
326
|
+
if ($backupResult.ExitCode -ne 0) {
|
|
327
|
+
Write-SyncLog -Level 'ERROR' -Message "realign skipped: cannot keep the old tip under ${backupRef}: $($backupResult.Output)"
|
|
328
|
+
return $false
|
|
329
|
+
}
|
|
330
|
+
$resetResult = Invoke-Git -Arguments @('reset', '-q', $RemoteRef)
|
|
331
|
+
if ($resetResult.ExitCode -ne 0) {
|
|
332
|
+
Write-SyncLog -Level 'ERROR' -Message "realign skipped: mixed reset failed: $($resetResult.Output)"
|
|
333
|
+
return $false
|
|
334
|
+
}
|
|
335
|
+
$differResult = Invoke-Git -Arguments @('diff', '--name-only', '--no-renames', '-z')
|
|
336
|
+
$stashNote = 'every tracked file already matched'
|
|
337
|
+
$failure = if ($differResult.ExitCode -ne 0) { "cannot list the files that differ: $($differResult.Output)" }
|
|
338
|
+
if (-not $failure) {
|
|
339
|
+
$allDifferingPaths = @(Get-NulSeparatedPaths -Output $differResult.Output)
|
|
340
|
+
if ($allDifferingPaths.Count -gt 0) {
|
|
341
|
+
$realignStashMessage = 'mirror realign {0}: tree before moving {1} to {2}' -f (Get-Date -Format 'yyyy-MM-dd'), $LocalTip, $RemoteRef
|
|
342
|
+
$stashResult = Invoke-Git -Arguments @('stash', 'push', '-m', $realignStashMessage)
|
|
343
|
+
if ($stashResult.ExitCode -ne 0) {
|
|
344
|
+
$failure = "stashing $($allDifferingPaths.Count) differing file(s) failed: $($stashResult.Output)"
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
$stashNote = "$($allDifferingPaths.Count) differing file(s) are stashed as '$realignStashMessage'"
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if ($failure) {
|
|
352
|
+
$revertResult = Invoke-Git -Arguments @('reset', '-q', $LocalTip)
|
|
353
|
+
$revertNote = if ($revertResult.ExitCode -eq 0) { "HEAD is back at $LocalTip" } else { "putting HEAD back at $LocalTip also failed: $($revertResult.Output)" }
|
|
354
|
+
Write-SyncLog -Level 'ERROR' -Message "realign failed, $failure; $revertNote"
|
|
355
|
+
return $false
|
|
356
|
+
}
|
|
357
|
+
Write-SyncLog -Level 'MIRROR' -Message "realigned onto ${RemoteRef}: old tip $LocalTip is kept as $backupRef; $stashNote"
|
|
358
|
+
return $true
|
|
359
|
+
}
|
|
360
|
+
|
|
287
361
|
function Get-RunLockName {
|
|
288
362
|
$lockPath = [System.IO.Path]::TrimEndingDirectorySeparator([System.IO.Path]::GetFullPath($RepoPath))
|
|
289
363
|
$resolveLinkTarget = [System.IO.Directory].GetMethod('ResolveLinkTarget', [type[]]([string], [bool]))
|
|
@@ -361,8 +435,17 @@ try {
|
|
|
361
435
|
$ancestorResult = Invoke-Git -Arguments @('merge-base', '--is-ancestor', $Branch, "$Remote/$Branch")
|
|
362
436
|
if ($ancestorResult.ExitCode -ne 0) {
|
|
363
437
|
$countResult = Invoke-Git -Arguments @('rev-list', '--left-right', '--count', "${Branch}...${Remote}/${Branch}")
|
|
364
|
-
|
|
365
|
-
|
|
438
|
+
if (-not $Mirror) {
|
|
439
|
+
Write-SyncLog -Level 'ERROR' -Message "diverged from $Remote/$Branch (counts=$($countResult.Output)); fast-forward refused. local=$localTip remote=$remoteTip"
|
|
440
|
+
exit 4
|
|
441
|
+
}
|
|
442
|
+
Write-SyncLog -Level 'MIRROR' -Message "diverged from $Remote/$Branch (counts=$($countResult.Output)); realigning the mirror. local=$localTip remote=$remoteTip"
|
|
443
|
+
if (-not (Invoke-MirrorRealign -LocalTip $localTip -RemoteRef "$Remote/$Branch")) {
|
|
444
|
+
exit 1
|
|
445
|
+
}
|
|
446
|
+
$subject = Get-GitDecoration -Arguments @('log', '-1', '--format=%h %s') -Placeholder '<subject unavailable>'
|
|
447
|
+
Write-SyncLog -Level 'OK' -Message "$Branch $localTip -> $remoteTip realigned | $subject"
|
|
448
|
+
exit 0
|
|
366
449
|
}
|
|
367
450
|
|
|
368
451
|
$didStash = $false
|
|
@@ -86,6 +86,23 @@ BeforeAll {
|
|
|
86
86
|
Invoke-TestGit -RepoPath $Fixture.MirrorPath -Arguments @('commit', '-q', '-am', 'feature edit') | Out-Null
|
|
87
87
|
return Invoke-TestGit -RepoPath $Fixture.MirrorPath -Arguments @('rev-parse', 'HEAD')
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
function New-MirrorDivergedFromRemote {
|
|
91
|
+
<#
|
|
92
|
+
Builds the mirror from New-MirrorBehindRemote, then commits local-only.txt
|
|
93
|
+
on the mirror's main. The mirror then holds a commit the remote lacks and
|
|
94
|
+
misses the remote's newer commit, the way a mirror looks after the remote
|
|
95
|
+
history was rewritten.
|
|
96
|
+
#>
|
|
97
|
+
param([string]$Name)
|
|
98
|
+
$fixture = New-MirrorBehindRemote -Name $Name
|
|
99
|
+
Write-TestFile -RepoPath $fixture.MirrorPath -RelativePath 'local-only.txt' -Content "local commit`n"
|
|
100
|
+
Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('add', '-A') | Out-Null
|
|
101
|
+
Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('commit', '-q', '-m', 'local only') | Out-Null
|
|
102
|
+
$localTip = Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('rev-parse', 'HEAD')
|
|
103
|
+
$fixture | Add-Member -NotePropertyName LocalTip -NotePropertyValue $localTip
|
|
104
|
+
return $fixture
|
|
105
|
+
}
|
|
89
106
|
}
|
|
90
107
|
|
|
91
108
|
Describe 'Sync-RepoMain' {
|
|
@@ -149,6 +166,44 @@ Describe 'Sync-RepoMain' {
|
|
|
149
166
|
[System.IO.File]::ReadAllText((Join-Path $fixture.MirrorPath 'tracked.txt')) | Should -Be "new`n"
|
|
150
167
|
}
|
|
151
168
|
|
|
169
|
+
It 'refuses a diverged tree with exit 4 when -Mirror is absent' {
|
|
170
|
+
$fixture = New-MirrorDivergedFromRemote -Name 'diverged-no-mirror'
|
|
171
|
+
|
|
172
|
+
$exitCode = Invoke-SyncScript -Fixture $fixture
|
|
173
|
+
|
|
174
|
+
$exitCode | Should -Be 4
|
|
175
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('rev-parse', 'HEAD')) | Should -Be $fixture.LocalTip
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
It 'realigns a diverged mirror onto the remote tip and stashes a tracked file that differs' {
|
|
179
|
+
$fixture = New-MirrorDivergedFromRemote -Name 'diverged-mirror'
|
|
180
|
+
Write-TestFile -RepoPath $fixture.MirrorPath -RelativePath 'tracked.txt' -Content "local edit`n"
|
|
181
|
+
$backupRef = 'refs/mirror-backup/{0}-{1}' -f (Get-Date -Format 'yyyy-MM-dd'), $fixture.LocalTip.Substring(0, 12)
|
|
182
|
+
|
|
183
|
+
$exitCode = Invoke-MirrorSyncScript -Fixture $fixture
|
|
184
|
+
|
|
185
|
+
$exitCode | Should -Be 0
|
|
186
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('rev-parse', 'HEAD')) | Should -Be $fixture.RemoteTip
|
|
187
|
+
[System.IO.File]::ReadAllText((Join-Path $fixture.MirrorPath 'tracked.txt')) | Should -Be "new`n"
|
|
188
|
+
[System.IO.File]::ReadAllText((Join-Path $fixture.MirrorPath 'added.txt')) | Should -Be "added`n"
|
|
189
|
+
[System.IO.File]::ReadAllText((Join-Path $fixture.MirrorPath 'local-only.txt')) | Should -Be "local commit`n"
|
|
190
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('rev-parse', $backupRef)) | Should -Be $fixture.LocalTip
|
|
191
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('stash', 'list')) | Should -Match 'mirror realign'
|
|
192
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('show', 'stash@{0}:tracked.txt')) | Should -Be 'local edit'
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
It 'keeps the old tip when the index holds staged changes during a realign' {
|
|
196
|
+
$fixture = New-MirrorDivergedFromRemote -Name 'diverged-staged'
|
|
197
|
+
Write-TestFile -RepoPath $fixture.MirrorPath -RelativePath 'tracked.txt' -Content "staged edit`n"
|
|
198
|
+
Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('add', 'tracked.txt') | Out-Null
|
|
199
|
+
|
|
200
|
+
$exitCode = Invoke-MirrorSyncScript -Fixture $fixture
|
|
201
|
+
|
|
202
|
+
$exitCode | Should -Be 1
|
|
203
|
+
(Invoke-TestGit -RepoPath $fixture.MirrorPath -Arguments @('rev-parse', 'HEAD')) | Should -Be $fixture.LocalTip
|
|
204
|
+
(Get-Content -LiteralPath $fixture.LogPath -Raw) | Should -Match 'realign skipped: the index holds staged changes'
|
|
205
|
+
}
|
|
206
|
+
|
|
152
207
|
It 'skips without fetching while another sync of the same repo holds the run lock' {
|
|
153
208
|
$fixture = New-MirrorBehindRemote -Name 'lock-held'
|
|
154
209
|
$lockPath = [System.IO.Path]::TrimEndingDirectorySeparator([System.IO.Path]::GetFullPath($fixture.MirrorPath))
|
|
@@ -11,6 +11,7 @@ _PWSH = shutil.which("pwsh") or "pwsh"
|
|
|
11
11
|
_SKIPPED_EXIT_CODE = 3
|
|
12
12
|
_SUCCESS_EXIT_CODE = 0
|
|
13
13
|
_FAILURE_EXIT_CODE = 1
|
|
14
|
+
_DIVERGED_EXIT_CODE = 4
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
def _git(repository_path: Path, *arguments: str) -> str:
|
|
@@ -74,6 +75,21 @@ def _mirror_on_feature_branch_behind_remote(
|
|
|
74
75
|
return mirror_path, feature_tip, remote_tip
|
|
75
76
|
|
|
76
77
|
|
|
78
|
+
def _mirror_diverged_from_remote(root_path: Path) -> tuple[Path, str, str]:
|
|
79
|
+
mirror_path, _, _ = _mirror_on_feature_branch_behind_remote(
|
|
80
|
+
root_path, should_advance_remote=False
|
|
81
|
+
)
|
|
82
|
+
_git(mirror_path, "switch", "-q", "main")
|
|
83
|
+
(mirror_path / "tracked.txt").write_text("local\n", encoding="utf-8")
|
|
84
|
+
_git(mirror_path, "commit", "-q", "-am", "local only edit")
|
|
85
|
+
local_tip = _git(mirror_path, "rev-parse", "HEAD")
|
|
86
|
+
author_path = root_path / "author"
|
|
87
|
+
(author_path / "tracked.txt").write_text("new\n", encoding="utf-8")
|
|
88
|
+
_git(author_path, "commit", "-q", "-am", "second")
|
|
89
|
+
_git(author_path, "push", "-q", "origin", "main")
|
|
90
|
+
return mirror_path, local_tip, _git(author_path, "rev-parse", "HEAD")
|
|
91
|
+
|
|
92
|
+
|
|
77
93
|
def _run_sync(mirror_path: Path, log_path: Path, *switches: str) -> int:
|
|
78
94
|
completed = subprocess.run(
|
|
79
95
|
[
|
|
@@ -224,3 +240,47 @@ def test_should_skip_a_checkout_with_staged_changes(tmp_path: Path) -> None:
|
|
|
224
240
|
assert _git(mirror_path, "branch", "--show-current") == "feature"
|
|
225
241
|
assert _git(mirror_path, "rev-parse", "HEAD") == feature_tip
|
|
226
242
|
assert _git(mirror_path, "diff", "--cached", "--name-only") == "tracked.txt"
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def test_should_exit_diverged_without_mirror(tmp_path: Path) -> None:
|
|
246
|
+
mirror_path, local_tip, _ = _mirror_diverged_from_remote(tmp_path)
|
|
247
|
+
log_path = tmp_path / "sync.log"
|
|
248
|
+
|
|
249
|
+
assert _run_sync(mirror_path, log_path, "-StashDirty") == _DIVERGED_EXIT_CODE
|
|
250
|
+
assert _git(mirror_path, "rev-parse", "HEAD") == local_tip
|
|
251
|
+
assert _git(mirror_path, "for-each-ref", "refs/mirror-backup") == ""
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def test_should_realign_a_diverged_mirror_onto_the_remote(tmp_path: Path) -> None:
|
|
255
|
+
mirror_path, local_tip, remote_tip = _mirror_diverged_from_remote(tmp_path)
|
|
256
|
+
log_path = tmp_path / "sync.log"
|
|
257
|
+
|
|
258
|
+
assert (
|
|
259
|
+
_run_sync(mirror_path, log_path, "-StashDirty", "-Mirror")
|
|
260
|
+
== _SUCCESS_EXIT_CODE
|
|
261
|
+
)
|
|
262
|
+
assert _git(mirror_path, "rev-parse", "HEAD") == remote_tip
|
|
263
|
+
assert (mirror_path / "tracked.txt").read_text(encoding="utf-8") == "new\n"
|
|
264
|
+
assert _git(mirror_path, "status", "--porcelain") == ""
|
|
265
|
+
assert (
|
|
266
|
+
_git(mirror_path, "for-each-ref", "refs/mirror-backup", "--format=%(objectname)")
|
|
267
|
+
== local_tip
|
|
268
|
+
)
|
|
269
|
+
assert f"tree before moving {local_tip}" in _git(mirror_path, "stash", "list")
|
|
270
|
+
assert "realigning the mirror" in log_path.read_text(encoding="utf-8")
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def test_should_skip_a_diverged_mirror_with_tracked_changes_without_stash_dirty(
|
|
274
|
+
tmp_path: Path,
|
|
275
|
+
) -> None:
|
|
276
|
+
mirror_path, local_tip, _ = _mirror_diverged_from_remote(tmp_path)
|
|
277
|
+
(mirror_path / "tracked.txt").write_text("staged\n", encoding="utf-8")
|
|
278
|
+
_git(mirror_path, "add", "tracked.txt")
|
|
279
|
+
log_path = tmp_path / "sync.log"
|
|
280
|
+
|
|
281
|
+
assert _run_sync(mirror_path, log_path, "-Mirror") == _SKIPPED_EXIT_CODE
|
|
282
|
+
assert _git(mirror_path, "rev-parse", "HEAD") == local_tip
|
|
283
|
+
assert _git(mirror_path, "for-each-ref", "refs/mirror-backup") == ""
|
|
284
|
+
assert "tracked changes present; refusing sync" in log_path.read_text(
|
|
285
|
+
encoding="utf-8"
|
|
286
|
+
)
|