Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gm repo branches failing on checked out branch #131

Merged
merged 3 commits into from
Dec 6, 2023
Merged
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 src/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export def "gm repo branches" [
}

for branch in $dangling_branches.branch {
if $branch == (^git branch --show-current) {
log warning $"($branch) is currently checked out and cannot be deleted"
continue
}

log info $"deleting branch `($branch)`"
^git branch --quiet --delete --force $branch
}
Expand Down
15 changes: 15 additions & 0 deletions tests/sugar/git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ export def branches [] {
clean $repo
}

export def branches-checked-out [] {
let repo = init-repo-and-cd-into

commit "init"

^git branch bar
^git branch foo
^git checkout bar

gm repo branches --clean
assert equal (gm repo branches) [{branch: bar, remotes: []}, ]

clean $repo
}

export def is-ancestor [] {
let repo = init-repo-and-cd-into

Expand Down