@@ -88,11 +88,21 @@ Write-Host ""
8888
8989# Step 2: Global config
9090Write-Step " Step 2: Setting up global configuration..."
91- New-Item - ItemType Directory - Path $CONFIG_DIR - Force | Out-Null
91+ try {
92+ New-Item - ItemType Directory - Path $CONFIG_DIR - Force - ErrorAction Stop | Out-Null
93+ } catch {
94+ Write-Fail " Failed to create config directory: $CONFIG_DIR - $ ( $_.Exception.Message ) "
95+ exit 1
96+ }
9297$configSource = Join-Path $PSScriptRoot " .gitleaks.toml"
9398if (Test-Path $configSource ) {
94- Copy-Item - Path $configSource - Destination (Join-Path $CONFIG_DIR " gitleaks.toml" ) - Force
95- Write-Ok " Copied gitleaks config to $CONFIG_DIR \gitleaks.toml"
99+ try {
100+ Copy-Item - Path $configSource - Destination (Join-Path $CONFIG_DIR " gitleaks.toml" ) - Force - ErrorAction Stop
101+ Write-Ok " Copied gitleaks config to $CONFIG_DIR \gitleaks.toml"
102+ } catch {
103+ Write-Fail " Failed to copy config file: $ ( $_.Exception.Message ) "
104+ exit 1
105+ }
96106} else {
97107 Write-Warn " .gitleaks.toml not found in script dir; config not copied. Create $CONFIG_DIR \gitleaks.toml manually if needed."
98108}
@@ -101,7 +111,12 @@ Write-Host ""
101111
102112# Step 3: Git template and hooks
103113Write-Step " Step 3: Creating git template directory..."
104- New-Item - ItemType Directory - Path $TEMPLATE_HOOKS - Force | Out-Null
114+ try {
115+ New-Item - ItemType Directory - Path $TEMPLATE_HOOKS - Force - ErrorAction Stop | Out-Null
116+ } catch {
117+ Write-Fail " Failed to create template hooks directory: $TEMPLATE_HOOKS - $ ( $_.Exception.Message ) "
118+ exit 1
119+ }
105120
106121$preCommitHook = @'
107122#!/bin/bash
@@ -210,17 +225,28 @@ exit 0
210225# Write hooks with LF line endings (Git for Windows runs them with bash)
211226$preCommitPath = Join-Path $TEMPLATE_HOOKS " pre-commit"
212227$commitMsgPath = Join-Path $TEMPLATE_HOOKS " commit-msg"
213- [System.IO.File ]::WriteAllText($preCommitPath , $preCommitHook.Replace (" `r`n " , " `n " ))
214- [System.IO.File ]::WriteAllText($commitMsgPath , $commitMsgHook.Replace (" `r`n " , " `n " ))
215- Write-Ok " Created pre-commit and commit-msg hooks in $TEMPLATE_HOOKS "
228+ try {
229+ [System.IO.File ]::WriteAllText($preCommitPath , $preCommitHook.Replace (" `r`n " , " `n " ))
230+ [System.IO.File ]::WriteAllText($commitMsgPath , $commitMsgHook.Replace (" `r`n " , " `n " ))
231+ Write-Ok " Created pre-commit and commit-msg hooks in $TEMPLATE_HOOKS "
232+ } catch {
233+ Write-Fail " Failed to write hook files: $ ( $_.Exception.Message ) "
234+ exit 1
235+ }
216236
217237Write-Host " "
218238
219239# Step 4: Configure git template
220240Write-Step " Step 4: Configuring git to use template directory..."
221241$templateDirNorm = $TEMPLATE_DIR -replace ' \\' , ' /'
222- git config -- global init.templateDir $templateDirNorm
223- Write-Ok " Set global git template directory"
242+ try {
243+ git config -- global init.templateDir $templateDirNorm
244+ if ($LASTEXITCODE -ne 0 ) { throw " git config exited with code $LASTEXITCODE " }
245+ Write-Ok " Set global git template directory"
246+ } catch {
247+ Write-Fail " Failed to set git template directory: $ ( $_.Exception.Message ) "
248+ Write-Warn " You can set it manually: git config --global init.templateDir '$templateDirNorm '"
249+ }
224250
225251Write-Host " "
226252Write-Host " ========================================" - ForegroundColor Green
0 commit comments