-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-push.ps1
More file actions
80 lines (65 loc) · 2.5 KB
/
Copy pathgithub-push.ps1
File metadata and controls
80 lines (65 loc) · 2.5 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
# GitHub'a push — sistemde Git yoksa .tools içindeki MinGit kullanilir
$ErrorActionPreference = "Stop"
Set-Location $PSScriptRoot
function Find-Git {
$portable = Join-Path $PSScriptRoot ".tools\mingit\cmd\git.exe"
if (Test-Path $portable) { return $portable }
$paths = @(
"$env:ProgramFiles\Git\cmd\git.exe",
"$env:ProgramFiles\Git\bin\git.exe",
"${env:ProgramFiles(x86)}\Git\cmd\git.exe"
)
foreach ($p in $paths) {
if (Test-Path $p) { return $p }
}
$cmd = Get-Command git -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
return $null
}
function Ensure-PortableGit {
$portable = Join-Path $PSScriptRoot ".tools\mingit\cmd\git.exe"
if (Test-Path $portable) { return $portable }
Write-Host "MinGit indiriliyor (ilk sefer, ~30 sn)..." -ForegroundColor Cyan
$tools = Join-Path $PSScriptRoot ".tools"
$mingit = Join-Path $tools "mingit"
$zip = Join-Path $tools "mingit.zip"
New-Item -ItemType Directory -Force -Path $tools | Out-Null
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.1/MinGit-2.47.1-64-bit.zip" -OutFile $zip -UseBasicParsing
Expand-Archive -Path $zip -DestinationPath $mingit -Force
Remove-Item $zip -Force
return $portable
}
$git = Find-Git
if (-not $git) { $git = Ensure-PortableGit }
$gitDir = Split-Path $git
$env:Path = "$gitDir;$env:Path"
$env:GIT_EXEC_PATH = Join-Path (Split-Path $gitDir) "mingw64\libexec\git-core"
$remote = "https://github.com/ardaozgun/DeployBase.git"
function Run-Git([string[]]$Args) {
Write-Host "> git $($Args -join ' ')" -ForegroundColor DarkGray
& $git @Args
if ($LASTEXITCODE -ne 0) { throw "git hatasi (kod $LASTEXITCODE)" }
}
if (-not (Test-Path ".git")) { Run-Git @("init") }
Run-Git @("add", ".")
try {
Run-Git @("commit", "-m", "first commit")
} catch {
$s = & $git status --porcelain 2>$null
if (-not $s) { Write-Host "Degisiklik yok, onceki commit kullaniliyor." -ForegroundColor Yellow }
else { throw }
}
Run-Git @("branch", "-M", "main")
$remotes = & $git remote 2>$null
if ($remotes -notcontains "origin") {
Run-Git @("remote", "add", "origin", $remote)
} else {
Run-Git @("remote", "set-url", "origin", $remote)
}
Write-Host ""
Write-Host "GitHub giris penceresi acilacak..." -ForegroundColor Cyan
Write-Host "Giris yoksa: https://github.com/settings/tokens -> repo yetkisi -> sifreyi yapıştır" -ForegroundColor Yellow
Write-Host ""
Run-Git @("push", "-u", "origin", "main")
Write-Host ""
Write-Host "Basarili: $remote" -ForegroundColor Green