From 2cc0ee18b792645396a05ac2856d466814e59026 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:35:25 +0100 Subject: [PATCH] show the deleted branches with `gm repo branch clean` (#202) `gm repo branch clean` will now return a `table` so that deleted branches can be easily resurrected. --- .../nu-git-manager-sugar/git/gm-repo-bisect.md | 2 +- .../git/gm-repo-branch-clean.md | 6 +++--- .../git/gm-repo-branch-fetch.md | 2 +- .../git/gm-repo-branch-interactive-delete.md | 2 +- .../git/gm-repo-branch-wipe.md | 2 +- .../git/gm-repo-is-ancestor.md | 2 +- docs/nu-git-manager-sugar/git/gm-repo-ls.md | 2 +- docs/nu-git-manager-sugar/git/gm-repo-query.md | 2 +- .../git/gm-repo-remote-add.md | 2 +- .../git/gm-repo-remote-list.md | 2 +- .../nu-git-manager-sugar/git/gm-repo-remote.md | 2 +- .../nu-git-manager-sugar/git/gm-repo-switch.md | 2 +- .../nu-git-manager-sugar/git/mod.nu | 18 ++++++++++++------ 13 files changed, 26 insertions(+), 20 deletions(-) diff --git a/docs/nu-git-manager-sugar/git/gm-repo-bisect.md b/docs/nu-git-manager-sugar/git/gm-repo-bisect.md index 44f4f88..fad0e04 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-bisect.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-bisect.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md index 09b57f6..bd45dd9 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md @@ -15,6 +15,6 @@ gm repo branch clean ## Signatures -| input | output | -| --------- | --------- | -| `nothing` | `nothing` | +| input | output | +| --------- | --------------------------------------- | +| `nothing` | `table` | diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md index 21b2044..e4229a9 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md index e5ee876..8604b21 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branch-wipe.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-wipe.md index a6d70c4..ff52480 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-branch-wipe.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-wipe.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-is-ancestor.md b/docs/nu-git-manager-sugar/git/gm-repo-is-ancestor.md index 00ee41d..51225a3 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-is-ancestor.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-is-ancestor.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-ls.md b/docs/nu-git-manager-sugar/git/gm-repo-ls.md index c231c23..965f3e3 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-ls.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-ls.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-query.md b/docs/nu-git-manager-sugar/git/gm-repo-query.md index ec64aea..7513d5c 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-query.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-query.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-remote-add.md b/docs/nu-git-manager-sugar/git/gm-repo-remote-add.md index 9905c0e..7b9ceff 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-remote-add.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-remote-add.md @@ -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** diff --git a/docs/nu-git-manager-sugar/git/gm-repo-remote-list.md b/docs/nu-git-manager-sugar/git/gm-repo-remote-list.md index cc6aaa1..720c9f5 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-remote-list.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-remote-list.md @@ -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 diff --git a/docs/nu-git-manager-sugar/git/gm-repo-remote.md b/docs/nu-git-manager-sugar/git/gm-repo-remote.md index ce6629c..d314454 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-remote.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-remote.md @@ -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)) diff --git a/docs/nu-git-manager-sugar/git/gm-repo-switch.md b/docs/nu-git-manager-sugar/git/gm-repo-switch.md index 5881af7..4a54026 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-switch.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-switch.md @@ -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 diff --git a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu index 04c8944..e9f872e 100644 --- a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu +++ b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu @@ -102,7 +102,7 @@ export def "gm repo branch list" []: nothing -> table nothing { +export def "gm repo branch clean" []: nothing -> table { let dangling_branches = gm repo branch list | where remotes == [] if ($dangling_branches | is-empty) { @@ -110,14 +110,20 @@ export def "gm repo branch clean" []: nothing -> nothing { 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 } }