diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..d89a9a6 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,5 @@ +## 2025-05-18 - Batch git branch deletion in PowerShell + +**Learning:** Invoking `git branch -D` individually inside a `ForEach-Object` loop introduces significant process spawning overhead (N+1 CLI invocations). Passing an array of branch names directly to a single `git branch -D` command allows PowerShell to expand arguments and execute deletion in a single process invocation. + +**Action:** Whenever performing bulk operations with native CLI executables in PowerShell (e.g., git branch, git rm), collect target names into an array and pass them in a single command invocation rather than iterating over items in a loop. diff --git a/script.ps1 b/script.ps1 index d9ae342..66d70fc 100644 --- a/script.ps1 +++ b/script.ps1 @@ -173,11 +173,9 @@ foreach ($pr in $prs) { # --- Nettoyage des branches locales restantes ------------------------------------ if (-not $DryRun) { - git branch | ForEach-Object { - $branchName = $_.Trim("* ").Trim() - if ($branchName -and $branchName -ne $BaseBranch) { - git branch -D $branchName 2>&1 | Out-Null - } + $branchesToDelete = @(git branch | ForEach-Object { $_.Trim("* ").Trim() } | Where-Object { $_ -and $_ -ne $BaseBranch }) + if ($branchesToDelete.Count -gt 0) { + git branch -D $branchesToDelete 2>&1 | Out-Null } }