Skip to content

Commit

Permalink
return table of branch and revision when cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Dec 6, 2024
1 parent 55e0c97 commit 88c69ac
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,28 @@ export def "gm repo branch list" []: nothing -> table<branch: string, remotes: l
# # clean all dangling branches
# gm repo branch clean
# ```
export def "gm repo branch clean" []: nothing -> nothing {
export def "gm repo branch clean" []: nothing -> table<name: string, revision: string> {
let dangling_branches = gm repo branch list | where remotes == []

if ($dangling_branches | is-empty) {
log warning "no dangling branches"
return
}

for branch in $dangling_branches.branch {
$dangling_branches.branch | each { |branch|
if $branch == (^git branch --show-current) {
log warning $"($branch) is currently checked out and cannot be deleted"
continue
} else {
log info $"deleting branch `($branch)`"
let revision = ^git branch --delete --force $branch
| lines
| parse "Deleted branch {br} (was {rev})."
| into record
| get rev
| ^git rev-parse $in

{ name: $branch, revision: $revision }
}

log info $"deleting branch `($branch)`"
^git branch --quiet --delete --force $branch
}
}

Expand Down

0 comments on commit 88c69ac

Please sign in to comment.