-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInitialize-MsxWorkspace.ps1
More file actions
93 lines (74 loc) · 3.32 KB
/
Copy pathInitialize-MsxWorkspace.ps1
File metadata and controls
93 lines (74 loc) · 3.32 KB
1
2
3
4
5
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env pwsh
#Requires -Version 7.0
<#
.SYNOPSIS
Clone or update the MSX central workspace (docs + memory) in a git-isolated location under $HOME.
.DESCRIPTION
The single starting point for every agent. It ensures the central
documentation and memory repositories exist locally under one dedicated
workspace, so an agent reads the same evergreen docs and the same prior
memory regardless of which repository it is working in.
The workspace is deliberately kept separate from the repositories an agent
works in:
- Each clone gets repository-local git config only. Nothing here modifies the
global git config or the working repository's config; git still reads global
and system config as usual, but this script writes only repository-local config.
- Documentation (MSXOrg/docs) is context and is changed through pull requests
only; this script never pushes its main branch.
- Memory (MSXOrg/memory) is append-only context; notes are committed and
pushed to main directly, without a pull request.
The script is idempotent: it clones what is missing and fast-forwards what is
already present.
.PARAMETER Root
The workspace root under which 'docs' and 'memory' are placed. Defaults to ~/.msx.
.PARAMETER UserName
The git author name written to each clone's local config.
.PARAMETER UserEmail
The git author email written to each clone's local config.
.EXAMPLE
./Initialize-MsxWorkspace.ps1
Clones missing repositories and fast-forwards existing ones under ~/.msx.
.EXAMPLE
./Initialize-MsxWorkspace.ps1 -Root /work/.msx -Verbose
Uses a custom workspace root and logs each step.
#>
[CmdletBinding()]
param(
[Parameter()]
[string] $Root = (Join-Path $HOME '.msx'),
[Parameter()]
[string] $UserName = 'Marius Storhaug',
[Parameter()]
[string] $UserEmail = 'MariusStorhaug@users.noreply.github.com'
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repositories = @(
[pscustomobject]@{ Name = 'docs'; Url = 'https://github.com/MSXOrg/docs.git'; Changes = 'pull requests' }
[pscustomobject]@{ Name = 'memory'; Url = 'https://github.com/MSXOrg/memory.git'; Changes = 'push to main' }
)
New-Item -ItemType Directory -Force -Path $Root | Out-Null
$results = foreach ($repo in $repositories) {
$path = Join-Path $Root $repo.Name
if (Test-Path (Join-Path $path '.git')) {
Write-Verbose "Updating $path"
git -C $path fetch origin --quiet
try {
git -C $path pull --ff-only --quiet
} catch {
Write-Warning "Could not fast-forward '$path' (local changes?). Left as-is."
}
} else {
if (Test-Path $path) {
throw "Cannot clone into '$path': it exists but is not a git repository. Remove it or choose a different -Root."
}
Write-Verbose "Cloning $($repo.Url) into $path"
git clone --quiet $repo.Url $path
}
# Isolated identity: repository-local config only, never global or inherited.
git -C $path config user.name $UserName
git -C $path config user.email $UserEmail
[pscustomobject]@{ Repository = $repo.Name; Path = $path; Changes = $repo.Changes }
}
$results | Format-Table -AutoSize
Write-Output 'MSX workspace ready. Read docs and memory here; docs change through pull requests, memory pushes to main.'