This commit is contained in:
Dobromir Popov
2025-09-08 09:12:55 +03:00
parent 85542e34fe
commit b5bec14311
9 changed files with 1547 additions and 55 deletions

View File

@@ -0,0 +1,151 @@
# Git Credentials Test Script
# Tests your Git credential setup and provides troubleshooting
Write-Host ""
Write-Host "🧪 Git Credentials Test" -ForegroundColor Cyan
Write-Host "======================" -ForegroundColor Cyan
Write-Host ""
# Check Git installation
try {
$gitVersion = git --version
Write-Host "✅ Git: $gitVersion" -ForegroundColor Green
} catch {
Write-Host "❌ Git not found. Please install Git for Windows." -ForegroundColor Red
Write-Host "Download: https://gitforwindows.org/" -ForegroundColor Yellow
exit 1
}
# Check if we're in a Git repository
if (-not (Test-Path ".git")) {
Write-Host "❌ Not in a Git repository. Please run from the repository root." -ForegroundColor Red
exit 1
}
# Get repository info
Write-Host "📁 Repository Information:" -ForegroundColor Magenta
$remoteUrl = git remote get-url origin
Write-Host "Remote URL: $remoteUrl" -ForegroundColor White
$branch = git branch --show-current
Write-Host "Current Branch: $branch" -ForegroundColor White
Write-Host ""
# Check Git configuration
Write-Host "⚙️ Git Configuration:" -ForegroundColor Magenta
$userName = git config --global user.name
$userEmail = git config --global user.email
$credentialHelper = git config --global credential.helper
Write-Host "User Name: $userName" -ForegroundColor White
Write-Host "User Email: $userEmail" -ForegroundColor White
Write-Host "Credential Helper: $credentialHelper" -ForegroundColor White
Write-Host ""
# Test credential helper
Write-Host "🔍 Testing Credential Setup:" -ForegroundColor Magenta
switch ($credentialHelper) {
"manager" {
Write-Host "✅ Using Git Credential Manager (GCM)" -ForegroundColor Green
Write-Host " GCM will open a browser for authentication" -ForegroundColor Gray
}
"gh" {
Write-Host "✅ Using GitHub CLI" -ForegroundColor Green
Write-Host " Make sure you're logged in: gh auth status" -ForegroundColor Gray
}
"vscode" {
Write-Host "✅ Using VS Code credential helper" -ForegroundColor Green
Write-Host " VS Code will prompt for credentials when needed" -ForegroundColor Gray
}
"store" {
Write-Host "⚠️ Using credential store (plain text)" -ForegroundColor Yellow
Write-Host " Credentials stored in plain text file" -ForegroundColor Gray
}
"" {
Write-Host "❌ No credential helper configured" -ForegroundColor Red
Write-Host " Run setup-git-credentials.ps1 to configure" -ForegroundColor Yellow
}
default {
Write-Host " Using custom credential helper: $credentialHelper" -ForegroundColor Blue
}
}
# Check SSH keys if using SSH
if ($remoteUrl -match "^git@") {
Write-Host ""
Write-Host "🔐 SSH Key Check:" -ForegroundColor Magenta
$sshKeyPath = "$env:USERPROFILE\.ssh\id_ed25519"
if (Test-Path $sshKeyPath) {
Write-Host "✅ SSH key found at: $sshKeyPath" -ForegroundColor Green
# Test SSH connection
Write-Host "Testing SSH connection..." -ForegroundColor Gray
try {
$sshTest = ssh -T git@git.d-popov.com "echo 'SSH connection successful'" 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ SSH connection to git.d-popov.com works" -ForegroundColor Green
} else {
Write-Host "❌ SSH connection failed. Check your SSH key setup." -ForegroundColor Red
}
} catch {
Write-Host "❌ SSH test failed. Make sure SSH is installed." -ForegroundColor Red
}
} else {
Write-Host "❌ SSH key not found at: $sshKeyPath" -ForegroundColor Red
Write-Host " Run setup-git-credentials.ps1 and choose SSH option" -ForegroundColor Yellow
}
}
# Test Git operations
Write-Host ""
Write-Host "🧪 Testing Git Operations:" -ForegroundColor Magenta
Write-Host "Testing git fetch..." -ForegroundColor Gray
try {
git fetch --quiet
Write-Host "✅ git fetch successful" -ForegroundColor Green
} catch {
Write-Host "❌ git fetch failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "Testing git status..." -ForegroundColor Gray
try {
$status = git status --porcelain
Write-Host "✅ git status successful" -ForegroundColor Green
if ($status) {
Write-Host " Repository has uncommitted changes" -ForegroundColor Yellow
} else {
Write-Host " Working directory clean" -ForegroundColor Green
}
} catch {
Write-Host "❌ git status failed: $($_.Exception.Message)" -ForegroundColor Red
}
# Summary and recommendations
Write-Host ""
Write-Host "📋 Summary & Recommendations:" -ForegroundColor Magenta
if (-not $credentialHelper) {
Write-Host "❌ No credential helper configured" -ForegroundColor Red
Write-Host " → Run .\setup-git-credentials.ps1" -ForegroundColor Yellow
} elseif ($credentialHelper -eq "store") {
Write-Host "⚠️ Using plain text credential storage" -ForegroundColor Yellow
Write-Host " → Consider switching to SSH keys or GCM" -ForegroundColor Yellow
} elseif ($remoteUrl -match "^git@" -and -not (Test-Path "$env:USERPROFILE\.ssh\id_ed25519")) {
Write-Host "⚠️ Using SSH but no SSH key found" -ForegroundColor Yellow
Write-Host " → Set up SSH keys for passwordless authentication" -ForegroundColor Yellow
} else {
Write-Host "✅ Credential setup looks good!" -ForegroundColor Green
Write-Host " → You should be able to push/pull without prompts" -ForegroundColor Green
}
Write-Host ""
Write-Host "🔧 Troubleshooting Commands:" -ForegroundColor Cyan
Write-Host "• Clear stored credentials: git config --global --unset credential.helper" -ForegroundColor White
Write-Host "• Reset credential helper: .\setup-git-credentials.ps1" -ForegroundColor White
Write-Host "• Test SSH: ssh -T git@git.d-popov.com" -ForegroundColor White
Write-Host "• Check Git config: git config --list --show-origin" -ForegroundColor White
Write-Host ""
Read-Host "Press Enter to continue"