Skip to content

Commit

Permalink
fix gm repo branches clean when HEAD is detached (#155)
Browse files Browse the repository at this point in the history
- add a test that should pass
- fix the command when `HEAD` is detached
  • Loading branch information
amtoine authored Dec 23, 2023
1 parent 0d45894 commit 937f4a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export def --env "gm repo goto root" []: nothing -> nothing {
export def "gm repo branches" [
--clean # clean all dangling branches
]: nothing -> table<branch: string, remotes: list<string>> {
let local_branches = ^git branch --list | lines | str replace --regex '..' ""
let local_branches = ^git branch --list
| lines
| find --invert --regex '\(HEAD detached at .*\)'
| str replace --regex '..' ""
let remote_branches = ^git branch --remotes
| lines
| str trim
Expand Down
15 changes: 15 additions & 0 deletions pkgs/nu-git-manager-sugar/tests/git.nu
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ export def branches-checked-out [] {
clean $repo
}

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

let hash = commit "init" | first

^git branch bar
^git branch foo
^git checkout $hash

gm repo branches --clean
assert equal (gm repo branches) []

clean $repo
}

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

Expand Down

0 comments on commit 937f4a8

Please sign in to comment.