Created
February 1, 2026 11:32
-
-
Save diegohb/07aa196ad8213a92db8f9598fd65491a to your computer and use it in GitHub Desktop.
The primary goal of these scripts is to allow a developer to remain in a UVCS-first workflow while using IDEs that default to Git. They enforce technical constraints required by the GitServer bridge to prevent data corruption and history mismatches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Consolidated management for UVCS GitServer and GitSync bridges. | |
| #> | |
| function Set-UvcsGitGlobalConfig { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory=$true)] | |
| [string]$RootPath | |
| ) | |
| process { | |
| if (!(Test-Path $RootPath)) { New-Item -ItemType Directory -Force -Path $RootPath | Out-Null } | |
| # Define paths within the root | |
| $script:UvcsRoot = $RootPath | |
| $script:UvcsMappingRoot = Join-Path $RootPath "mappings" | |
| $templateDir = Join-Path $RootPath "git-repo-template" | |
| $hookDir = Join-Path $templateDir "hooks" | |
| # Initialize directories | |
| if (!(Test-Path $script:UvcsMappingRoot)) { New-Item -ItemType Directory -Force -Path $script:UvcsMappingRoot | Out-Null } | |
| if (!(Test-Path $hookDir)) { New-Item -ItemType Directory -Force -Path $hookDir | Out-Null } | |
| # Global Git Settings | |
| git config --global pack.window 0 | |
| # Define safety hook | |
| $hookContent = @" | |
| #!/bin/sh | |
| # UVCS Compatibility Protections | |
| if [ "`$1" = "pre-rebase" ] || [[ "`$@" == *"rebase"* ]]; then | |
| echo "ERROR: Rebase is disabled for UVCS compatibility." | |
| exit 1 | |
| fi | |
| if [[ "`$@" == *"force"* ]]; then | |
| echo "ERROR: Force-push/deletion is disabled to protect UVCS mapping." | |
| exit 1 | |
| fi | |
| if [[ "`$@" == *"worktree"* ]]; then | |
| echo "ERROR: Git worktrees are not supported by the UVCS bridge." | |
| exit 1 | |
| fi | |
| "@ | |
| # Deploy Hooks | |
| @("pre-rebase", "pre-push") | ForEach-Object { | |
| $path = Join-Path $hookDir $_ | |
| Set-Content -Path $path -Value $hookContent -Encoding utf8 | |
| } | |
| # Apply template globally | |
| git config --global init.templateDir $templateDir | |
| Write-Host "Environment configured at $RootPath" -ForegroundColor Green | |
| } | |
| } | |
| function New-UvcsGitRepo { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory=$true)] | |
| [string]$RepoName, | |
| [Parameter(Mandatory=$true)] | |
| [string]$LocalPath, | |
| [string]$ServerHost = "localhost" | |
| ) | |
| process { | |
| # Format URL based on UVCS docs | |
| $gitUrl = "git://$ServerHost/$RepoName" | |
| if (!(Test-Path $LocalPath)) { New-Item -ItemType Directory -Force -Path $LocalPath | Out-Null } | |
| git clone $gitUrl $LocalPath | |
| if ($LASTEXITCODE -eq 0) { | |
| Push-Location $LocalPath | |
| git config pack.window 0 | |
| Pop-Location | |
| } | |
| } | |
| } | |
| function Repair-UvcsGitBridge { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory=$true)] [string]$RepoName, | |
| [Parameter(Mandatory=$true)] [string]$LocalGitPath, | |
| [Parameter(Mandatory=$true)] [ValidateSet("1","2","3")] [string]$Option | |
| ) | |
| process { | |
| $mappingsDir = Join-Path $script:UvcsRoot "mappings" | |
| if (Test-Path $mappingsDir) { Remove-Item -Recurse -Force $mappingsDir } | |
| switch ($Option) { | |
| "1" { # Git is newer -> Override UVCS | |
| $recoveredRepo = "${RepoName}_recovered" | |
| cm repository create $recoveredRepo | |
| $gitFileUrl = "file:///$($LocalGitPath.Replace('\','/'))" | |
| cm sync $recoveredRepo git $gitFileUrl --author | |
| } | |
| "2" { # UVCS is newer -> Override Git | |
| if (Test-Path $LocalGitPath) { Remove-Item -Recurse -Force $LocalGitPath } | |
| New-UvcsGitRepo -RepoName $RepoName -LocalPath $LocalGitPath | |
| } | |
| "3" { Write-Host "Mappings cleared." } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment