Configure private registry and Git repository
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
95
scripts/push-to-private-repo.ps1
Normal file
95
scripts/push-to-private-repo.ps1
Normal file
@@ -0,0 +1,95 @@
|
||||
# 推送代码到私有 Git 仓库
|
||||
# 用途:将代码推送到私有仓库(默认推送到私有仓库)
|
||||
|
||||
param(
|
||||
[string]$CommitMessage = "Update: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')",
|
||||
[switch]$PushToGitHub,
|
||||
[switch]$PushToBoth
|
||||
)
|
||||
|
||||
Write-Host "=== 推送代码到 Git 仓库 ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 检查 Git 状态
|
||||
$status = git status --porcelain 2>$null
|
||||
if ($status) {
|
||||
Write-Host "发现更改的文件:" -ForegroundColor Cyan
|
||||
git status --short
|
||||
Write-Host ""
|
||||
|
||||
# 添加所有更改
|
||||
Write-Host "添加所有更改..." -ForegroundColor Yellow
|
||||
git add .
|
||||
Write-Host "✓ 文件已添加到暂存区" -ForegroundColor Green
|
||||
|
||||
# 提交
|
||||
Write-Host "提交更改..." -ForegroundColor Yellow
|
||||
Write-Host "提交信息: $CommitMessage" -ForegroundColor Gray
|
||||
git commit -m $CommitMessage
|
||||
Write-Host "✓ 更改已提交" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "✓ 没有需要提交的更改" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# 检查远程仓库
|
||||
$privateRemote = git remote get-url private 2>$null
|
||||
$originRemote = git remote get-url origin 2>$null
|
||||
|
||||
if (-not $privateRemote -and -not $originRemote) {
|
||||
Write-Host "错误: 未配置远程仓库" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 确定推送目标
|
||||
if ($PushToBoth) {
|
||||
$pushToPrivate = $true
|
||||
$pushToOrigin = $true
|
||||
} elseif ($PushToGitHub) {
|
||||
$pushToPrivate = $false
|
||||
$pushToOrigin = $true
|
||||
} else {
|
||||
# 默认推送到私有仓库
|
||||
$pushToPrivate = $true
|
||||
$pushToOrigin = $false
|
||||
}
|
||||
|
||||
# 推送到私有仓库
|
||||
if ($pushToPrivate -and $privateRemote) {
|
||||
Write-Host ""
|
||||
Write-Host "推送到私有仓库..." -ForegroundColor Yellow
|
||||
Write-Host "远程仓库: $($privateRemote -replace '://.*@', '://****@')" -ForegroundColor Gray
|
||||
Write-Host "分支: main" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
git push private main
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "✓ 代码已成功推送到私有仓库" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "✗ 推送到私有仓库失败" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
# 推送到 GitHub(如果指定)
|
||||
if ($pushToOrigin -and $originRemote) {
|
||||
Write-Host ""
|
||||
Write-Host "推送到 GitHub..." -ForegroundColor Yellow
|
||||
Write-Host "远程仓库: $($originRemote -replace '://.*@', '://****@')" -ForegroundColor Gray
|
||||
Write-Host "分支: main" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
git push origin main
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "✓ 代码已成功推送到 GitHub" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "✗ 推送到 GitHub 失败" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== 完成 ===" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "使用说明:" -ForegroundColor Cyan
|
||||
Write-Host " - 默认推送到私有仓库: .\scripts\push-to-private-repo.ps1" -ForegroundColor Gray
|
||||
Write-Host " - 推送到 GitHub: .\scripts\push-to-private-repo.ps1 -PushToGitHub" -ForegroundColor Gray
|
||||
Write-Host " - 推送到两个仓库: .\scripts\push-to-private-repo.ps1 -PushToBoth" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user