# Kit de entrada do dsgit para UM usuario no Windows (PowerShell 5.1 ou 7). Idempotente; desfazer: sair.ps1. # Uso: .\entrar.ps1 (se o Windows bloquear: powershell -ExecutionPolicy Bypass -File .\entrar.ps1) # A parte comum (cofre de credenciais, git, CLI tea, MCP, Claude Code, autoteste) e feita pelo entrar.sh no # Git Bash que vem com o Git for Windows - uma so implementacao. Aqui fica so o que e do PowerShell: # um bloco removivel no perfil ($PROFILE) com o PATH e as funcoes dsgit, dsgit-prs, dsgit-runs, dsgit-log, ... # Token: o entrar.sh pede sem eco, ou reutiliza $env:DSGIT_TOKEN, $env:DSGIT_TOKEN_FILE ou o cofre de credenciais. param([string]$Url) $ErrorActionPreference = 'Stop' $git = (Get-Command git -ErrorAction SilentlyContinue | Select-Object -First 1).Source if (-not $git) { throw 'Instale o Git for Windows (https://git-scm.com) e rode de novo.' } $bash = Join-Path (Split-Path (Split-Path $git)) 'bin\bash.exe' if (-not (Test-Path $bash)) { throw "Nao achei o Git Bash em $bash" } if ($Url) { $env:DSGIT_URL = $Url } $ErrorActionPreference = 'Continue' # no PowerShell 5.1, texto no stderr de programa nativo nao pode virar erro fatal & $bash (($PSScriptRoot -replace '\\', '/') + '/entrar.sh') if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } $ErrorActionPreference = 'Stop' # bloco no perfil do PowerShell (sem token: as funcoes chamam ~/.dsgit/bin/dsgit, que le o cofre) $ini = '# >>> dsgit (posto por entrar.ps1; tirar: sair.ps1) >>>'; $fim = '# <<< dsgit <<<' $bloco = @" $ini if ((`$env:Path -split ';') -notcontains "`$HOME\.dsgit\bin") { `$env:Path = "`$HOME\.dsgit\bin;`$env:Path" } function global:dsgit { & '$bash' "`$HOME/.dsgit/bin/dsgit" @args } foreach (`$c in 'prs','runs','log','rerun','api') { Set-Item "function:global:dsgit-`$c" ([scriptblock]::Create("dsgit `$c @args")) } $fim "@ $dir = Split-Path $PROFILE if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force $dir | Out-Null } $atual = if (Test-Path $PROFILE) { Get-Content $PROFILE -Raw -Encoding UTF8 } else { '' } if ($null -eq $atual) { $atual = '' } $atual = [regex]::Replace($atual, '(?s)\r?\n?# >>> dsgit .*?# <<< dsgit <<<\r?\n?', '').TrimEnd() $novo = if ($atual) { "$atual`r`n$bloco`r`n" } else { "$bloco`r`n" } Set-Content -Path $PROFILE -Value $novo -Encoding UTF8 -NoNewline . ([scriptblock]::Create($bloco)) $eu = (dsgit api /user | ConvertFrom-Json).login if ($eu) { "PASS PowerShell: funcoes carregadas; dsgit api /user responde como '$eu'" } else { 'FAIL PowerShell: dsgit api /user nao respondeu'; exit 1 } if ((Get-ExecutionPolicy) -in 'Restricted', 'AllSigned') { "AVISO: a politica de execucao ($(Get-ExecutionPolicy)) impede o perfil de carregar. Rode: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned" } "Pronto. Abra um PowerShell novo e use: dsgit-prs, dsgit-runs, dsgit-log , tea, dsgit api /user"