Skip to content

Commit

Permalink
show the deleted branches with gm repo branch clean (#202)
Browse files Browse the repository at this point in the history
`gm repo branch clean` will now return a `table<name: string, revision:
string>` so that deleted branches can be easily resurrected.
  • Loading branch information
amtoine authored Dec 6, 2024
1 parent 55e0c97 commit 2cc0ee1
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-bisect.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo bisect` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L440))
# `gm repo bisect` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L446))
bisect a worktree by running a piece of code repeatedly

# Examples
Expand Down
6 changes: 3 additions & 3 deletions docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ gm repo branch clean


## Signatures
| input | output |
| --------- | --------- |
| `nothing` | `nothing` |
| input | output |
| --------- | --------------------------------------- |
| `nothing` | `table<name: string, revision: string>` |
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo branch fetch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L229))
# `gm repo branch fetch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L235))
fetch a remote branch locally, without pulling down the whole remote


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo branch interactive-delete` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L286))
# `gm repo branch interactive-delete` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L292))
remove a branch interactively


Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-branch-wipe.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo branch wipe` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L125))
# `gm repo branch wipe` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L131))
wipe a branch completely, i.e. both locally and remotely


Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-is-ancestor.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo is-ancestor` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L152))
# `gm repo is-ancestor` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L158))
return true iif the first revision is an ancestor of the second

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-ls.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo ls` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L330))
# `gm repo ls` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L336))
get some information about a repo


Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-query.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo query` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L380))
# `gm repo query` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L386))
queries the `.git/` directory as a database with `nu_plugin_git_query`

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-remote-add.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo remote add` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L202))
# `gm repo remote add` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L208))
add a remote to the current repository

> **Note**
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-remote-list.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo remote list` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L173))
# `gm repo remote list` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L179))
get the list of all the remotes in the current repository

## Examples
Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-remote.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo remote` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L159))
# `gm repo remote` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L165))



Expand Down
2 changes: 1 addition & 1 deletion docs/nu-git-manager-sugar/git/gm-repo-switch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gm repo switch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L306))
# `gm repo switch` from `nu-git-manager-sugar git` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu#L312))
switch between branches interactively


Expand Down
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 2cc0ee1

Please sign in to comment.