From 286311a2767317f1d4199040cdf3ab0014ac1aae Mon Sep 17 00:00:00 2001 From: Virendra Vyas Date: Thu, 12 Feb 2026 17:04:30 +0530 Subject: [PATCH 1/5] fixed windows script for scanning all drives --- IT-DEPLOYMENT-GUIDE.md | 11 ++++++++--- install-gitleaks-global.ps1 | 3 ++- update-all-repos.ps1 | 32 +++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/IT-DEPLOYMENT-GUIDE.md b/IT-DEPLOYMENT-GUIDE.md index 97d60fb01..bda54a375 100644 --- a/IT-DEPLOYMENT-GUIDE.md +++ b/IT-DEPLOYMENT-GUIDE.md @@ -36,10 +36,15 @@ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # if need *No admin required. Installs gitleaks to `%LOCALAPPDATA%\gitleaks\bin` and adds it to your user PATH.* #### 2. Update All Repositories +Run with **no arguments** to scan all local drives (C:\, D:\, E:\, etc.) and install hooks in every repo. One command for the whole machine. ```powershell -.\update-all-repos.ps1 # current directory only -.\update-all-repos.ps1 C:\Projects # all repos under C:\Projects -$env:MAX_DEPTH = 3; .\update-all-repos.ps1 C:\Projects # limit depth +.\update-all-repos.ps1 +``` +Optional: limit to one drive or folder (faster): +```powershell +.\update-all-repos.ps1 C:\Projects +.\update-all-repos.ps1 C:\ D:\ +$env:MAX_DEPTH = 4; .\update-all-repos.ps1 C:\ # limit depth on C: ``` #### 3. Uninstall diff --git a/install-gitleaks-global.ps1 b/install-gitleaks-global.ps1 index e245eb057..64dac7cc7 100644 --- a/install-gitleaks-global.ps1 +++ b/install-gitleaks-global.ps1 @@ -235,7 +235,8 @@ Write-Host " * Hooks: pre-commit, commit-msg" Write-Host "`nNext steps:" -ForegroundColor Cyan Write-Host " 1. All NEW git repositories will automatically get gitleaks hooks." -Write-Host " 2. For EXISTING repos, run: .\update-all-repos.ps1 [directory]" +Write-Host " 2. For EXISTING repos, run (updates all repos on all local drives):" +Write-Host " .\update-all-repos.ps1" -ForegroundColor Gray Write-Host " 3. Or in each repo: git init (re-run to apply template)" Write-Host "`nNote: If gitleaks is not found in a new terminal, close and reopen PowerShell, or run:" Write-Host " `$env:Path += `";$GITLEAKS_BIN_DIR`"" diff --git a/update-all-repos.ps1 b/update-all-repos.ps1 index 7138adae5..f795ed026 100644 --- a/update-all-repos.ps1 +++ b/update-all-repos.ps1 @@ -1,10 +1,10 @@ #Requires -Version 5.1 # Installs gitleaks pre-commit hooks in existing repositories (Windows). # Usage: -# .\update-all-repos.ps1 # Current directory only -# .\update-all-repos.ps1 C:\Projects # All repos under C:\Projects +# .\update-all-repos.ps1 # All local drives (C:\, D:\, E:\, etc.) - single command for all repos +# .\update-all-repos.ps1 C:\Projects # Only repos under C:\Projects # .\update-all-repos.ps1 C:\Projects C:\Sites -# Optional: $MAX_DEPTH = 3; .\update-all-repos.ps1 C:\Projects +# Optional: $MAX_DEPTH = 3; .\update-all-repos.ps1 C:\ # Limit depth on a drive param( [Parameter(ValueFromRemainingArguments = $true)] @@ -35,8 +35,16 @@ if (-not (Test-Path (Join-Path $TEMPLATE_HOOKS "pre-commit"))) { $preCommitSrc = Join-Path $TEMPLATE_HOOKS "pre-commit" $commitMsgSrc = Join-Path $TEMPLATE_HOOKS "commit-msg" +# No path given = scan all local fixed drives (C:\, D:\, E:\, etc.) if ($TargetPaths.Count -eq 0) { - $TargetPaths = @(Get-Location).Path + $TargetPaths = [System.IO.DriveInfo]::GetDrives() | Where-Object { $_.DriveType -eq 'Fixed' -and $_.IsReady } | ForEach-Object { $_.Root.TrimEnd('\') + '\' } + if ($TargetPaths.Count -eq 0) { + Write-Fail "No local drives found." + exit 1 + } + Write-Host "No path specified: scanning all local drives ( $($TargetPaths -join ', ') )" -ForegroundColor Cyan + Write-Host "This may take a while on large drives. Press Ctrl+C to cancel." -ForegroundColor Gray + Write-Host "" } $script:Updated = 0 @@ -45,10 +53,16 @@ $script:Failed = 0 function Get-GitRepos { param([string]$Root, [int]$MaxDepth = 0) + $repos = @() + # Include root if it is itself a git repo (Get-ChildItem -Recurse only returns subdirs, not root) + if (Test-Path (Join-Path $Root ".git")) { + $repos += $Root + } $params = @{ Path = $Root; Directory = $true; Recurse = $true; ErrorAction = 'SilentlyContinue' } if ($MaxDepth -gt 0) { $params['Depth'] = $MaxDepth } - $dirs = Get-ChildItem @params | Where-Object { Test-Path (Join-Path $_.FullName ".git") } - $dirs | ForEach-Object { $_.FullName } + $subdirs = Get-ChildItem @params | Where-Object { Test-Path (Join-Path $_.FullName ".git") } + $repos += ($subdirs | ForEach-Object { $_.FullName }) + $repos | Sort-Object -Unique } function Install-Hooks { @@ -77,7 +91,6 @@ foreach ($target in $TargetPaths) { $maxDepth = if ($env:MAX_DEPTH) { [int]$env:MAX_DEPTH } else { 0 } Write-Step "Scanning $root for git repositories..." $repos = Get-GitRepos -Root $root -MaxDepth $maxDepth - $repos = $repos | Sort-Object -Unique $i = 0 foreach ($repo in $repos) { $i++ @@ -94,4 +107,9 @@ foreach ($target in $TargetPaths) { Write-Host "" Write-Host "Done. Updated: $($script:Updated), Failed: $($script:Failed)" -ForegroundColor Cyan +if ($script:Updated -eq 0 -and $script:Failed -eq 0) { + Write-Host "" + Write-Warn "No git repositories were found in the scanned path(s)." + Write-Host " To scan only a specific folder: .\update-all-repos.ps1 C:\Projects" -ForegroundColor Gray +} if ($script:Failed -gt 0) { exit 1 } From bec074b74697020d1df67501ea8e641ceb9a7b33 Mon Sep 17 00:00:00 2001 From: Virendra Vyas Date: Thu, 12 Feb 2026 17:16:39 +0530 Subject: [PATCH 2/5] fixed windows script for null drive issue --- update-all-repos.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-all-repos.ps1 b/update-all-repos.ps1 index f795ed026..7a4a29a8c 100644 --- a/update-all-repos.ps1 +++ b/update-all-repos.ps1 @@ -37,7 +37,7 @@ $commitMsgSrc = Join-Path $TEMPLATE_HOOKS "commit-msg" # No path given = scan all local fixed drives (C:\, D:\, E:\, etc.) if ($TargetPaths.Count -eq 0) { - $TargetPaths = [System.IO.DriveInfo]::GetDrives() | Where-Object { $_.DriveType -eq 'Fixed' -and $_.IsReady } | ForEach-Object { $_.Root.TrimEnd('\') + '\' } + $TargetPaths = [System.IO.DriveInfo]::GetDrives() | Where-Object { $_.DriveType -eq 'Fixed' -and $_.IsReady -and $null -ne $_.Root } | ForEach-Object { $_.Root.TrimEnd('\') + '\' } if ($TargetPaths.Count -eq 0) { Write-Fail "No local drives found." exit 1 From b9ca456774d0f6735be519dc6e9bb339c913dda2 Mon Sep 17 00:00:00 2001 From: Virendra Vyas Date: Thu, 12 Feb 2026 17:19:20 +0530 Subject: [PATCH 3/5] fixed windows script for null drive issue name --- update-all-repos.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update-all-repos.ps1 b/update-all-repos.ps1 index 7a4a29a8c..842a59539 100644 --- a/update-all-repos.ps1 +++ b/update-all-repos.ps1 @@ -37,7 +37,8 @@ $commitMsgSrc = Join-Path $TEMPLATE_HOOKS "commit-msg" # No path given = scan all local fixed drives (C:\, D:\, E:\, etc.) if ($TargetPaths.Count -eq 0) { - $TargetPaths = [System.IO.DriveInfo]::GetDrives() | Where-Object { $_.DriveType -eq 'Fixed' -and $_.IsReady -and $null -ne $_.Root } | ForEach-Object { $_.Root.TrimEnd('\') + '\' } + # Use .Name (e.g. "C:") to avoid null .Root on some Windows setups + $TargetPaths = [System.IO.DriveInfo]::GetDrives() | Where-Object { $_.DriveType -eq 'Fixed' -and $_.IsReady } | ForEach-Object { $_.Name + '\' } if ($TargetPaths.Count -eq 0) { Write-Fail "No local drives found." exit 1 From 7ec177a03c9806546cd1b7e0d88023b29d3f30bc Mon Sep 17 00:00:00 2001 From: Virendra Vyas Date: Thu, 12 Feb 2026 18:18:55 +0530 Subject: [PATCH 4/5] added logs for progress counter in windows script --- update-all-repos.ps1 | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/update-all-repos.ps1 b/update-all-repos.ps1 index 842a59539..6f5fd8194 100644 --- a/update-all-repos.ps1 +++ b/update-all-repos.ps1 @@ -52,18 +52,34 @@ $script:Updated = 0 $script:Skipped = 0 $script:Failed = 0 +# Progress counter: update every N folders so user sees activity during long scans +$script:ProgressInterval = 500 + function Get-GitRepos { param([string]$Root, [int]$MaxDepth = 0) - $repos = @() - # Include root if it is itself a git repo (Get-ChildItem -Recurse only returns subdirs, not root) - if (Test-Path (Join-Path $Root ".git")) { - $repos += $Root + $script:DirsScanned = 0 + $script:ReposFoundList = [System.Collections.Generic.List[string]]::new() + $script:LastProgressAt = 0 + + function Search-Dirs { + param([string]$Path, [int]$Depth) + $script:DirsScanned++ + if (($script:DirsScanned - $script:LastProgressAt) -ge $script:ProgressInterval) { + Write-Host " ... checked $($script:DirsScanned) folders, found $($script:ReposFoundList.Count) repos" -ForegroundColor Gray + $script:LastProgressAt = $script:DirsScanned + } + if (Test-Path (Join-Path $Path ".git")) { + $script:ReposFoundList.Add($Path) | Out-Null + } + if ($MaxDepth -gt 0 -and $Depth -ge $MaxDepth) { return } + Get-ChildItem -Path $Path -Directory -ErrorAction SilentlyContinue | ForEach-Object { + Search-Dirs -Path $_.FullName -Depth ($Depth + 1) + } } - $params = @{ Path = $Root; Directory = $true; Recurse = $true; ErrorAction = 'SilentlyContinue' } - if ($MaxDepth -gt 0) { $params['Depth'] = $MaxDepth } - $subdirs = Get-ChildItem @params | Where-Object { Test-Path (Join-Path $_.FullName ".git") } - $repos += ($subdirs | ForEach-Object { $_.FullName }) - $repos | Sort-Object -Unique + + Search-Dirs -Path $Root -Depth 0 + Write-Host " Scan complete: checked $($script:DirsScanned) folders, found $($script:ReposFoundList.Count) repos" -ForegroundColor Cyan + $script:ReposFoundList | Sort-Object -Unique } function Install-Hooks { From 927693ce9b324542368b0693fa1058845920da3e Mon Sep 17 00:00:00 2001 From: Virendra Vyas Date: Thu, 12 Feb 2026 18:28:33 +0530 Subject: [PATCH 5/5] updated logs for progress counter in windows script --- update-all-repos.ps1 | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/update-all-repos.ps1 b/update-all-repos.ps1 index 6f5fd8194..de60174b2 100644 --- a/update-all-repos.ps1 +++ b/update-all-repos.ps1 @@ -52,21 +52,15 @@ $script:Updated = 0 $script:Skipped = 0 $script:Failed = 0 -# Progress counter: update every N folders so user sees activity during long scans -$script:ProgressInterval = 500 - function Get-GitRepos { param([string]$Root, [int]$MaxDepth = 0) - $script:DirsScanned = 0 $script:ReposFoundList = [System.Collections.Generic.List[string]]::new() - $script:LastProgressAt = 0 function Search-Dirs { param([string]$Path, [int]$Depth) - $script:DirsScanned++ - if (($script:DirsScanned - $script:LastProgressAt) -ge $script:ProgressInterval) { - Write-Host " ... checked $($script:DirsScanned) folders, found $($script:ReposFoundList.Count) repos" -ForegroundColor Gray - $script:LastProgressAt = $script:DirsScanned + # Log only parent-level folders (direct children of drive or of the given root) + if ($Depth -eq 1) { + Write-Host " Scanning $Path" -ForegroundColor Gray } if (Test-Path (Join-Path $Path ".git")) { $script:ReposFoundList.Add($Path) | Out-Null @@ -78,7 +72,7 @@ function Get-GitRepos { } Search-Dirs -Path $Root -Depth 0 - Write-Host " Scan complete: checked $($script:DirsScanned) folders, found $($script:ReposFoundList.Count) repos" -ForegroundColor Cyan + Write-Host " Scan complete: found $($script:ReposFoundList.Count) repos" -ForegroundColor Cyan $script:ReposFoundList | Sort-Object -Unique }