Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions install-gitleaks-global.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,21 @@ Write-Host ""

# Step 2: Global config
Write-Step "Step 2: Setting up global configuration..."
New-Item -ItemType Directory -Path $CONFIG_DIR -Force | Out-Null
try {
New-Item -ItemType Directory -Path $CONFIG_DIR -Force -ErrorAction Stop | Out-Null
} catch {
Write-Fail "Failed to create config directory: $CONFIG_DIR - $($_.Exception.Message)"
exit 1
}
$configSource = Join-Path $PSScriptRoot ".gitleaks.toml"
if (Test-Path $configSource) {
Copy-Item -Path $configSource -Destination (Join-Path $CONFIG_DIR "gitleaks.toml") -Force
Write-Ok "Copied gitleaks config to $CONFIG_DIR\gitleaks.toml"
try {
Copy-Item -Path $configSource -Destination (Join-Path $CONFIG_DIR "gitleaks.toml") -Force -ErrorAction Stop
Write-Ok "Copied gitleaks config to $CONFIG_DIR\gitleaks.toml"
} catch {
Write-Fail "Failed to copy config file: $($_.Exception.Message)"
exit 1
}
} else {
Write-Warn ".gitleaks.toml not found in script dir; config not copied. Create $CONFIG_DIR\gitleaks.toml manually if needed."
}
Expand All @@ -101,7 +111,12 @@ Write-Host ""

# Step 3: Git template and hooks
Write-Step "Step 3: Creating git template directory..."
New-Item -ItemType Directory -Path $TEMPLATE_HOOKS -Force | Out-Null
try {
New-Item -ItemType Directory -Path $TEMPLATE_HOOKS -Force -ErrorAction Stop | Out-Null
} catch {
Write-Fail "Failed to create template hooks directory: $TEMPLATE_HOOKS - $($_.Exception.Message)"
exit 1
}

$preCommitHook = @'
#!/bin/bash
Expand Down Expand Up @@ -210,17 +225,28 @@ exit 0
# Write hooks with LF line endings (Git for Windows runs them with bash)
$preCommitPath = Join-Path $TEMPLATE_HOOKS "pre-commit"
$commitMsgPath = Join-Path $TEMPLATE_HOOKS "commit-msg"
[System.IO.File]::WriteAllText($preCommitPath, $preCommitHook.Replace("`r`n", "`n"))
[System.IO.File]::WriteAllText($commitMsgPath, $commitMsgHook.Replace("`r`n", "`n"))
Write-Ok "Created pre-commit and commit-msg hooks in $TEMPLATE_HOOKS"
try {
[System.IO.File]::WriteAllText($preCommitPath, $preCommitHook.Replace("`r`n", "`n"))
[System.IO.File]::WriteAllText($commitMsgPath, $commitMsgHook.Replace("`r`n", "`n"))
Write-Ok "Created pre-commit and commit-msg hooks in $TEMPLATE_HOOKS"
} catch {
Write-Fail "Failed to write hook files: $($_.Exception.Message)"
exit 1
}

Write-Host ""

# Step 4: Configure git template
Write-Step "Step 4: Configuring git to use template directory..."
$templateDirNorm = $TEMPLATE_DIR -replace '\\', '/'
git config --global init.templateDir $templateDirNorm
Write-Ok "Set global git template directory"
try {
git config --global init.templateDir $templateDirNorm
if ($LASTEXITCODE -ne 0) { throw "git config exited with code $LASTEXITCODE" }
Write-Ok "Set global git template directory"
} catch {
Write-Fail "Failed to set git template directory: $($_.Exception.Message)"
Write-Warn "You can set it manually: git config --global init.templateDir '$templateDirNorm'"
}

Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Expand Down
23 changes: 18 additions & 5 deletions update-all-repos.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ function Get-GitRepos {
if ($Depth -eq 1) {
Write-Host " Scanning $Path" -ForegroundColor Gray
}
if (Test-Path (Join-Path $Path ".git")) {
$script:ReposFoundList.Add($Path) | Out-Null
try {
if (Test-Path (Join-Path $Path ".git") -ErrorAction SilentlyContinue) {
$script:ReposFoundList.Add($Path) | Out-Null
}
} catch {
# Silently skip paths we don't have permission to read
}
if ($MaxDepth -gt 0 -and $Depth -ge $MaxDepth) { return }
Get-ChildItem -Path $Path -Directory -ErrorAction SilentlyContinue | ForEach-Object {
Expand All @@ -117,12 +121,21 @@ function Get-GitRepos {
function Install-Hooks {
param([string]$RepoDir)
$hooksDir = Join-Path $RepoDir ".git\hooks"
if (-not (Test-Path $hooksDir)) { return $false }
# Create hooks directory if it doesn't exist
if (-not (Test-Path $hooksDir)) {
try {
New-Item -ItemType Directory -Path $hooksDir -Force -ErrorAction Stop | Out-Null
} catch {
Write-Fail "Cannot create hooks dir: $hooksDir - $($_.Exception.Message)"
return $false
}
}
try {
Copy-Item -Path $preCommitSrc -Destination (Join-Path $hooksDir "pre-commit") -Force
Copy-Item -Path $commitMsgSrc -Destination (Join-Path $hooksDir "commit-msg") -Force
Copy-Item -Path $preCommitSrc -Destination (Join-Path $hooksDir "pre-commit") -Force -ErrorAction Stop
Copy-Item -Path $commitMsgSrc -Destination (Join-Path $hooksDir "commit-msg") -Force -ErrorAction Stop
return $true
} catch {
Write-Fail "Hook copy error: $($_.Exception.Message)"
return $false
}
}
Expand Down
Loading