-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-push-optimusdb.ps1
More file actions
138 lines (117 loc) Β· 4.37 KB
/
git-push-optimusdb.ps1
File metadata and controls
138 lines (117 loc) Β· 4.37 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# ============================================
# Git Push Script - OptimusDB LSA
# ============================================
# Define the expected project directory
$EXPECTED_DIR = "C:\Users\georg\GolandProjects\optimusdb-lsa"
Write-Host "π OptimusDB LSA - Git Push Script" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Check current directory
$currentDir = Get-Location
Write-Host "π Current directory: $currentDir" -ForegroundColor Yellow
# Validate we're in the correct directory
if ($currentDir.Path -ne $EXPECTED_DIR) {
Write-Host "β οΈ You are not in the OptimusDB-LSA project directory!" -ForegroundColor Yellow
Write-Host " Expected: $EXPECTED_DIR" -ForegroundColor White
Write-Host " Current: $currentDir" -ForegroundColor White
Write-Host ""
$changeDir = Read-Host "Do you want to change to the correct directory? (y/n)"
if ($changeDir -eq "y") {
if (Test-Path $EXPECTED_DIR) {
Set-Location $EXPECTED_DIR
Write-Host "β
Changed to: $EXPECTED_DIR" -ForegroundColor Green
Write-Host ""
} else {
Write-Host "β Directory does not exist: $EXPECTED_DIR" -ForegroundColor Red
exit 1
}
} else {
Write-Host "β Aborted. Please run this script from: $EXPECTED_DIR" -ForegroundColor Red
exit 1
}
}
Write-Host "β
Running from correct directory: $EXPECTED_DIR" -ForegroundColor Green
Write-Host ""
# Check if git is installed
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host "β Git is not installed or not in PATH" -ForegroundColor Red
exit 1
}
# Check if we're in a git repository
if (-not (Test-Path .git)) {
Write-Host "β Not a git repository. Run 'git init' first." -ForegroundColor Red
exit 1
}
# Show current branch
$currentBranch = git branch --show-current
Write-Host "π Current branch: $currentBranch" -ForegroundColor Yellow
Write-Host ""
# Show status
Write-Host "π Git Status:" -ForegroundColor Cyan
git status --short
Write-Host ""
# Check if there are any changes
$changes = git status --porcelain
if ([string]::IsNullOrWhiteSpace($changes)) {
Write-Host "β
Nothing to commit - working tree clean" -ForegroundColor Green
exit 0
}
# Ask for confirmation
$confirm = Read-Host "Do you want to stage all changes? (y/n)"
if ($confirm -ne "y") {
Write-Host "β Aborted by user" -ForegroundColor Red
exit 0
}
# Stage all changes
Write-Host "π¦ Staging all changes..." -ForegroundColor Cyan
git add .
# Show what will be committed
Write-Host ""
Write-Host "π Files to be committed:" -ForegroundColor Cyan
git diff --cached --name-status
Write-Host ""
# Ask for commit message
$commitMessage = Read-Host "Enter commit message"
if ([string]::IsNullOrWhiteSpace($commitMessage)) {
Write-Host "β Commit message cannot be empty" -ForegroundColor Red
exit 1
}
# Commit changes
Write-Host ""
Write-Host "πΎ Committing changes..." -ForegroundColor Cyan
git commit -m "$commitMessage"
if ($LASTEXITCODE -ne 0) {
Write-Host "β Commit failed" -ForegroundColor Red
exit 1
}
# Ask for push confirmation
Write-Host ""
$pushConfirm = Read-Host "Push to remote repository? (y/n)"
if ($pushConfirm -ne "y") {
Write-Host "β
Committed locally. Run 'git push' manually when ready." -ForegroundColor Green
exit 0
}
# Check if remote exists
$remotes = git remote
if ([string]::IsNullOrWhiteSpace($remotes)) {
Write-Host "β οΈ No remote repository configured" -ForegroundColor Yellow
Write-Host ""
Write-Host "To add a remote repository, run:" -ForegroundColor Cyan
Write-Host "git remote add origin https://github.com/YOUR_USERNAME/optimusdb-lsa.git" -ForegroundColor White
exit 0
}
# Push to remote
Write-Host ""
Write-Host "π Pushing to remote..." -ForegroundColor Cyan
git push origin $currentBranch --force
if ($LASTEXITCODE -eq 0) {
Write-Host ""
Write-Host "β
Successfully pushed to GitHub!" -ForegroundColor Green
Write-Host "π All changes are now on remote repository" -ForegroundColor Green
} else {
Write-Host ""
Write-Host "β Push failed. Check your remote configuration and credentials." -ForegroundColor Red
Write-Host ""
Write-Host "You may need to set upstream:" -ForegroundColor Yellow
Write-Host "git push --set-upstream origin $currentBranch" -ForegroundColor White
}