amtoine / nu-git-manager

A collection of Nushell tools to manage Git repositories.
GNU General Public License v3.0
26 stars 2 forks source link

`gm repo branches --clean` fails on checked out branch #130

Closed amtoine closed 9 months ago

amtoine commented 9 months ago

Describe the bug

when using gm repo branches --clean when checked out on a dangling branch, the command will halt because git branch -D fails.

How to reproduce

tk run --clean {
    # setup the repo
    let repo = $nu.temp-path | path join foo
    if ($repo | path exists) {
        rm -f -r $repo
    }
    git init $repo
    cd $repo
    git checkout --orphan main
    git commit --allow-empty --no-gpg-sign --message "init"

    # create two branches and checkout the first one
    git branch bar
    git branch foo
    git checkout bar

    print $"dangling branches: (gm repo branches | where ($it.remotes | is-empty) | get branch)"
    gm repo branches --clean
}
Initialized empty Git repository in /tmp/foo/.git/
Switched to a new branch 'main'
[main (root-commit) e35547d] init
Switched to branch 'bar'
dangling branches: [bar, foo, main]
2023-12-06T16:33:36.290|INF|deleting branch `bar`
error: Cannot delete branch 'bar' checked out at '/tmp/foo'

Expected behavior

i expected gm repo branches --clean to skip branch bar and remove foo without an error.

Configuration

key value
version 0.87.1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.73.0 (cc66ad468 2023-10-03)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.73.0 (9c4383fb5 2023-08-26)
build_time 2023-11-21 18:26:35 +01:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which, zip
installed_plugins clipboard copy, clipboard paste, gstat, notify, nu_plugin_explore, query git

Additional context

No response