commit.ps1
1.91 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
# PowerShell script to ensure Git is in PATH before running czg
# This script ensures Git is available before running czg (commitizen-git)
# Add common Git installation paths to PATH
$gitPaths = @(
"C:\Program Files\Git\cmd",
"C:\Program Files (x86)\Git\cmd",
"$env:LOCALAPPDATA\GitHubDesktop\bin",
"$env:ProgramFiles\Git\cmd"
)
# Get the actual PATH from system/user environment variables
$systemPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$currentPath = $env:PATH
# Merge all PATH sources and deduplicate
$allPaths = ($systemPath, $userPath, $currentPath) -join ';' -split ';' | Where-Object { $_ }
$allPaths += $gitPaths | Where-Object { Test-Path $_ }
$env:PATH = ($allPaths | Select-Object -Unique) -join ';'
# Verify Git is available
try {
$gitVersion = git --version 2>&1
if ($LASTEXITCODE -ne 0 -or $gitVersion -match "error|not found") {
Write-Host "❌ Error: Git is not available in PATH." -ForegroundColor Red
Write-Host "Please install Git from https://git-scm.com/downloads" -ForegroundColor Yellow
Write-Host "Or add Git to your system PATH manually." -ForegroundColor Yellow
exit 1
}
} catch {
Write-Host "❌ Error: Git is not available in PATH." -ForegroundColor Red
Write-Host "Please install Git from https://git-scm.com/downloads" -ForegroundColor Yellow
exit 1
}
# Check if there are staged files
$stagedFiles = git diff --cached --name-only 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Error: Failed to check staged files. Git may not be properly configured." -ForegroundColor Red
exit 1
}
if ([string]::IsNullOrWhiteSpace($stagedFiles)) {
Write-Host "⚠️ Warning: No files staged for commit." -ForegroundColor Yellow
Write-Host "Please run 'git add' to stage files before committing." -ForegroundColor Yellow
Write-Host ""
}
# Run czg
npx czg