Skip to content
Open
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
5 changes: 5 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 3 additions & 5 deletions script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down