From ea21cbe3b154d0f63bb0304f3cbfd8e3c422af9c Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 10:50:25 +0200 Subject: [PATCH 1/7] add top-level `gm` commands to get help - `gm repo` - `gm repo remote` - `gm gh` --- pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu | 4 ++++ pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu | 2 ++ 2 files changed, 6 insertions(+) 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 ce411dfb..153be319 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 @@ -13,6 +13,8 @@ use completions [ export module prompt.nu +export def "gm repo" [] { help "gm repo" } + # get the commit hash of any revision # # ## Examples @@ -148,6 +150,8 @@ export def "gm repo is-ancestor" [ (do -i { ^git merge-base $a $b --is-ancestor } | complete | get exit_code) == 0 } +export def "gm repo remote" [] { help "gm repo remote" } + # get the list of all the remotes in the current repository # # ## Examples diff --git a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu index 13f52952..24d1430b 100644 --- a/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu +++ b/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu @@ -61,6 +61,8 @@ def "warning make" [ ] } +export def "gm gh" [] { help "gm gh" } + # query the GitHub API for any end point # # > :bulb: **Note** From dddb79e5427248055840cf5be556cb8d2287ac58 Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 10:55:33 +0200 Subject: [PATCH 2/7] refactor `gm repo branch` group of commands --- .../nu-git-manager-sugar/git/mod.nu | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) 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 153be319..da1ea68a 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 @@ -59,7 +59,9 @@ export def --env "gm repo goto root" []: nothing -> nothing { cd (repo-root) } -# inspect local branches +export def "gm repo branch" [] { help "gm repo branch" } + +# list local branches # # > **Note** # > in the following, a "*dangling*" branch refers to a branch that does not have any remote @@ -68,16 +70,9 @@ export def --env "gm repo goto root" []: nothing -> nothing { # ## Examples # ```nushell # # list branches and their associated remotes -# gm repo branches -# ``` -# --- -# ```nushell -# # clean all dangling branches -# gm repo branches --clean +# gm repo branch list # ``` -export def "gm repo branches" [ - --clean # clean all dangling branches -]: nothing -> table> { +export def "gm repo branch list" []: nothing -> table> { let local_branches = ^git branch --list | lines | find --invert --regex '\(HEAD detached at .*\)' @@ -93,25 +88,36 @@ export def "gm repo branches" [ remotes: ($remote_branches | where branch == $branch | get remote) } } - if $clean { - let dangling_branches = $branches | where remotes == [] + $branches +} - if ($dangling_branches | is-empty) { - log warning "no dangling branches" - return - } +# clean local dangling branches +# +# > **Note** +# > in the following, a "*dangling*" branch refers to a branch that does not have any remote +# > counterpart, i.e. it's a purely local branch. +# +# ## Examples +# ```nushell +# # clean all dangling branches +# gm repo branch clean +# ``` +export def "gm repo branch clean" []: nothing -> nothing { + let dangling_branches = gm repo branch list | where remotes == [] - for branch in $dangling_branches.branch { - if $branch == (^git branch --show-current) { - log warning $"($branch) is currently checked out and cannot be deleted" - continue - } + if ($dangling_branches | is-empty) { + log warning "no dangling branches" + return + } - log info $"deleting branch `($branch)`" - ^git branch --quiet --delete --force $branch + for branch in $dangling_branches.branch { + if $branch == (^git branch --show-current) { + log warning $"($branch) is currently checked out and cannot be deleted" + continue } - } else { - $branches + + log info $"deleting branch `($branch)`" + ^git branch --quiet --delete --force $branch } } @@ -179,7 +185,7 @@ export def "gm repo remote list" []: nothing -> table Date: Sat, 20 Apr 2024 10:59:39 +0200 Subject: [PATCH 3/7] add argument completion to `gm repo branch wipe` --- pkgs/nu-git-manager-sugar/nu-git-manager-sugar/git/mod.nu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 da1ea68a..e6845f02 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 @@ -123,8 +123,8 @@ export def "gm repo branch clean" []: nothing -> nothing { # wipe a branch completely, i.e. both locally and remotely export def "gm repo branch wipe" [ - branch: string, # the branch to wipe - remote: string, # the remote to push to + branch: string@"get-branches", # the branch to wipe + remote: string@"get-remotes", # the remote to push to ]: nothing -> nothing { ^git branch --delete --force $branch ^git push $remote --delete $branch From 3506f7c74f60ccfc119c1ab73cf1534a645e3556 Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 11:00:50 +0200 Subject: [PATCH 4/7] generate the documentation --- docs/index.md | 9 +++++++-- .../git/gm-repo-bisect.md | 2 +- .../git/gm-repo-branch-clean.md | 20 +++++++++++++++++++ ...etch-branch.md => gm-repo-branch-fetch.md} | 2 +- .../git/gm-repo-branch-interactive-delete.md | 2 +- ...epo-branches.md => gm-repo-branch-list.md} | 12 +++-------- .../git/gm-repo-branch-wipe.md | 6 +++--- .../git/gm-repo-branch.md | 12 +++++++++++ .../git/gm-repo-compare.md | 2 +- .../git/gm-repo-get-commit.md | 2 +- .../git/gm-repo-goto-root.md | 2 +- .../git/gm-repo-is-ancestor.md | 2 +- docs/nu-git-manager-sugar/git/gm-repo-ls.md | 2 +- .../nu-git-manager-sugar/git/gm-repo-query.md | 2 +- .../git/gm-repo-remote-list.md | 2 +- .../git/gm-repo-remote.md | 12 +++++++++++ .../git/gm-repo-switch.md | 2 +- docs/nu-git-manager-sugar/git/gm-repo.md | 12 +++++++++++ docs/nu-git-manager-sugar/git/index.md | 8 ++++++-- .../github/gm-gh-pr-checkout.md | 2 +- .../github/gm-gh-query-api.md | 2 +- .../github/gm-gh-query-releases.md | 2 +- .../github/gm-gh-query-user.md | 2 +- docs/nu-git-manager-sugar/github/gm-gh.md | 12 +++++++++++ docs/nu-git-manager-sugar/github/index.md | 1 + 25 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md rename docs/nu-git-manager-sugar/git/{gm-repo-fetch-branch.md => gm-repo-branch-fetch.md} (78%) rename docs/nu-git-manager-sugar/git/{gm-repo-branches.md => gm-repo-branch-list.md} (56%) create mode 100644 docs/nu-git-manager-sugar/git/gm-repo-branch.md create mode 100644 docs/nu-git-manager-sugar/git/gm-repo-remote.md create mode 100644 docs/nu-git-manager-sugar/git/gm-repo.md create mode 100644 docs/nu-git-manager-sugar/github/gm-gh.md diff --git a/docs/index.md b/docs/index.md index 1a9c839f..45dc41c1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,20 +14,25 @@ - [`gm cfg`](nu-git-manager-sugar/dotfiles/gm-cfg.md) - [`gm cfg edit`](nu-git-manager-sugar/dotfiles/gm-cfg-edit.md) - [`gm report`](nu-git-manager-sugar/extra/gm-report.md) +- [`gm repo`](nu-git-manager-sugar/git/gm-repo.md) - [`gm repo bisect`](nu-git-manager-sugar/git/gm-repo-bisect.md) +- [`gm repo branch`](nu-git-manager-sugar/git/gm-repo-branch.md) +- [`gm repo branch clean`](nu-git-manager-sugar/git/gm-repo-branch-clean.md) +- [`gm repo branch fetch`](nu-git-manager-sugar/git/gm-repo-branch-fetch.md) - [`gm repo branch interactive-delete`](nu-git-manager-sugar/git/gm-repo-branch-interactive-delete.md) +- [`gm repo branch list`](nu-git-manager-sugar/git/gm-repo-branch-list.md) - [`gm repo branch wipe`](nu-git-manager-sugar/git/gm-repo-branch-wipe.md) -- [`gm repo branches`](nu-git-manager-sugar/git/gm-repo-branches.md) - [`gm repo compare`](nu-git-manager-sugar/git/gm-repo-compare.md) -- [`gm repo fetch branch`](nu-git-manager-sugar/git/gm-repo-fetch-branch.md) - [`gm repo get commit`](nu-git-manager-sugar/git/gm-repo-get-commit.md) - [`gm repo goto root`](nu-git-manager-sugar/git/gm-repo-goto-root.md) - [`gm repo is-ancestor`](nu-git-manager-sugar/git/gm-repo-is-ancestor.md) - [`gm repo ls`](nu-git-manager-sugar/git/gm-repo-ls.md) - [`gm repo query`](nu-git-manager-sugar/git/gm-repo-query.md) +- [`gm repo remote`](nu-git-manager-sugar/git/gm-repo-remote.md) - [`gm repo remote list`](nu-git-manager-sugar/git/gm-repo-remote-list.md) - [`gm repo switch`](nu-git-manager-sugar/git/gm-repo-switch.md) - [`setup`](nu-git-manager-sugar/git/prompt/setup.md) +- [`gm gh`](nu-git-manager-sugar/github/gm-gh.md) - [`gm gh pr checkout`](nu-git-manager-sugar/github/gm-gh-pr-checkout.md) - [`gm gh query-api`](nu-git-manager-sugar/github/gm-gh-query-api.md) - [`gm gh query-releases`](nu-git-manager-sugar/github/gm-gh-query-releases.md) 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 a2ae1746..19678c83 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#L384)) +# `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#L394)) 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 new file mode 100644 index 00000000..09b57f69 --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-clean.md @@ -0,0 +1,20 @@ +# `gm repo branch clean` 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#L105)) +clean local dangling branches + +> **Note** +> in the following, a "*dangling*" branch refers to a branch that does not have any remote +> counterpart, i.e. it's a purely local branch. + +## Examples +```nushell +# clean all dangling branches +gm repo branch clean +``` + +## Parameters + + +## Signatures +| input | output | +| --------- | --------- | +| `nothing` | `nothing` | diff --git a/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md similarity index 78% rename from docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md rename to docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md index 11a1ee7d..78072c68 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-fetch.md @@ -1,4 +1,4 @@ -# `gm repo fetch branch` 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#L178)) +# `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#L188)) 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 e3c6fd76..65303a63 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#L230)) +# `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#L240)) remove a branch interactively diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branches.md b/docs/nu-git-manager-sugar/git/gm-repo-branch-list.md similarity index 56% rename from docs/nu-git-manager-sugar/git/gm-repo-branches.md rename to docs/nu-git-manager-sugar/git/gm-repo-branch-list.md index 383a57aa..ab870825 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-branches.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch-list.md @@ -1,5 +1,5 @@ -# `gm repo branches` 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#L76)) -inspect local branches +# `gm repo branch 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#L75)) +list local branches > **Note** > in the following, a "*dangling*" branch refers to a branch that does not have any remote @@ -8,16 +8,10 @@ inspect local branches ## Examples ```nushell # list branches and their associated remotes -gm repo branches -``` ---- -```nushell -# clean all dangling branches -gm repo branches --clean +gm repo branch list ``` ## Parameters -- `--clean` <`bool`>: clean all dangling branches ## Signatures 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 51515ea4..a6d70c4b 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,11 +1,11 @@ -# `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#L117)) +# `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)) wipe a branch completely, i.e. both locally and remotely ## Parameters -- `branch` <`string`>: the branch to wipe -- `remote` <`string`>: the remote to push to +- `branch` <`string@get-branches`>: the branch to wipe +- `remote` <`string@get-remotes`>: the remote to push to ## Signatures diff --git a/docs/nu-git-manager-sugar/git/gm-repo-branch.md b/docs/nu-git-manager-sugar/git/gm-repo-branch.md new file mode 100644 index 00000000..4e83c863 --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-branch.md @@ -0,0 +1,12 @@ +# `gm repo branch` 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#L62)) + + + + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/git/gm-repo-compare.md b/docs/nu-git-manager-sugar/git/gm-repo-compare.md index c4a9dec1..bd7eace3 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-compare.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-compare.md @@ -1,4 +1,4 @@ -# `gm repo compare` 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#L35)) +# `gm repo compare` 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#L37)) compare the changes between two revisions, from a target to the "head" diff --git a/docs/nu-git-manager-sugar/git/gm-repo-get-commit.md b/docs/nu-git-manager-sugar/git/gm-repo-get-commit.md index 4beb0934..68b82ce7 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-get-commit.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-get-commit.md @@ -1,4 +1,4 @@ -# `gm repo get commit` 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#L28)) +# `gm repo get commit` 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#L30)) get the commit hash of any revision ## Examples diff --git a/docs/nu-git-manager-sugar/git/gm-repo-goto-root.md b/docs/nu-git-manager-sugar/git/gm-repo-goto-root.md index 6d73d5cc..2787c34a 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-goto-root.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-goto-root.md @@ -1,4 +1,4 @@ -# `gm repo goto root` 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#L56)) +# `gm repo goto root` 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#L58)) go to the root of the repository from anywhere in the worktree ## Examples 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 6498d560..00ee41d0 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#L144)) +# `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)) 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 8851002b..ea8ba60f 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#L274)) +# `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#L284)) 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 db3737c2..71dfa3c3 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#L324)) +# `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#L334)) 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-list.md b/docs/nu-git-manager-sugar/git/gm-repo-remote-list.md index f9e399b7..cc6aaa12 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#L163)) +# `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)) 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 new file mode 100644 index 00000000..ce6629ce --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-remote.md @@ -0,0 +1,12 @@ +# `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)) + + + + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | 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 95b7b832..27932460 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#L250)) +# `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#L260)) switch between branches interactively diff --git a/docs/nu-git-manager-sugar/git/gm-repo.md b/docs/nu-git-manager-sugar/git/gm-repo.md new file mode 100644 index 00000000..0486c09f --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo.md @@ -0,0 +1,12 @@ +# `gm repo` 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#L16)) + + + + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/git/index.md b/docs/nu-git-manager-sugar/git/index.md index 74bd78e6..1f5630a7 100644 --- a/docs/nu-git-manager-sugar/git/index.md +++ b/docs/nu-git-manager-sugar/git/index.md @@ -5,17 +5,21 @@ ships a bunch of helper commands that augments the capabilities of Git. /!\ this module is part of the optional NGM. /!\ ## Commands +- [`gm repo`](gm-repo.md) - [`gm repo bisect`](gm-repo-bisect.md) +- [`gm repo branch`](gm-repo-branch.md) +- [`gm repo branch clean`](gm-repo-branch-clean.md) +- [`gm repo branch fetch`](gm-repo-branch-fetch.md) - [`gm repo branch interactive-delete`](gm-repo-branch-interactive-delete.md) +- [`gm repo branch list`](gm-repo-branch-list.md) - [`gm repo branch wipe`](gm-repo-branch-wipe.md) -- [`gm repo branches`](gm-repo-branches.md) - [`gm repo compare`](gm-repo-compare.md) -- [`gm repo fetch branch`](gm-repo-fetch-branch.md) - [`gm repo get commit`](gm-repo-get-commit.md) - [`gm repo goto root`](gm-repo-goto-root.md) - [`gm repo is-ancestor`](gm-repo-is-ancestor.md) - [`gm repo ls`](gm-repo-ls.md) - [`gm repo query`](gm-repo-query.md) +- [`gm repo remote`](gm-repo-remote.md) - [`gm repo remote list`](gm-repo-remote-list.md) - [`gm repo switch`](gm-repo-switch.md) diff --git a/docs/nu-git-manager-sugar/github/gm-gh-pr-checkout.md b/docs/nu-git-manager-sugar/github/gm-gh-pr-checkout.md index b85b4fc2..e03e36d4 100644 --- a/docs/nu-git-manager-sugar/github/gm-gh-pr-checkout.md +++ b/docs/nu-git-manager-sugar/github/gm-gh-pr-checkout.md @@ -1,4 +1,4 @@ -# `gm gh pr checkout` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L215)) +# `gm gh pr checkout` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L217)) checkout one of the repo's PR interactively diff --git a/docs/nu-git-manager-sugar/github/gm-gh-query-api.md b/docs/nu-git-manager-sugar/github/gm-gh-query-api.md index f87b0c85..3a25be48 100644 --- a/docs/nu-git-manager-sugar/github/gm-gh-query-api.md +++ b/docs/nu-git-manager-sugar/github/gm-gh-query-api.md @@ -1,4 +1,4 @@ -# `gm gh query-api` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L87)) +# `gm gh query-api` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L89)) query the GitHub API for any end point > :bulb: **Note** diff --git a/docs/nu-git-manager-sugar/github/gm-gh-query-releases.md b/docs/nu-git-manager-sugar/github/gm-gh-query-releases.md index 7698bef3..b3176f39 100644 --- a/docs/nu-git-manager-sugar/github/gm-gh-query-releases.md +++ b/docs/nu-git-manager-sugar/github/gm-gh-query-releases.md @@ -1,4 +1,4 @@ -# `gm gh query-releases` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L192)) +# `gm gh query-releases` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L194)) list the releases of a GitHub repository ## Examples diff --git a/docs/nu-git-manager-sugar/github/gm-gh-query-user.md b/docs/nu-git-manager-sugar/github/gm-gh-query-user.md index 7a47a7a3..813ec1e5 100644 --- a/docs/nu-git-manager-sugar/github/gm-gh-query-user.md +++ b/docs/nu-git-manager-sugar/github/gm-gh-query-user.md @@ -1,4 +1,4 @@ -# `gm gh query-user` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L207)) +# `gm gh query-user` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L209)) get information about a GitHub user ## Examples: diff --git a/docs/nu-git-manager-sugar/github/gm-gh.md b/docs/nu-git-manager-sugar/github/gm-gh.md new file mode 100644 index 00000000..a1008514 --- /dev/null +++ b/docs/nu-git-manager-sugar/github/gm-gh.md @@ -0,0 +1,12 @@ +# `gm gh` from `nu-git-manager-sugar github` (see [source](https://github.com/amtoine/nu-git-manager/blob/main/pkgs/nu-git-manager-sugar/nu-git-manager-sugar/github.nu#L64)) + + + + +## Parameters + + +## Signatures +| input | output | +| ----- | ------ | +| `any` | `any` | diff --git a/docs/nu-git-manager-sugar/github/index.md b/docs/nu-git-manager-sugar/github/index.md index e8b5d731..9916a58e 100644 --- a/docs/nu-git-manager-sugar/github/index.md +++ b/docs/nu-git-manager-sugar/github/index.md @@ -5,6 +5,7 @@ provides helper commands to simplify the use of the GitHub CLI. /!\ this module is part of the optional NGM. /!\ ## Commands +- [`gm gh`](gm-gh.md) - [`gm gh pr checkout`](gm-gh-pr-checkout.md) - [`gm gh query-api`](gm-gh-query-api.md) - [`gm gh query-releases`](gm-gh-query-releases.md) From 42b4278e6d9e209f2fb811d6389f9e57c32f7f34 Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 11:19:21 +0200 Subject: [PATCH 5/7] add `gm repo remote add` --- .../nu-git-manager-sugar/git/mod.nu | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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 e6845f02..98da6f43 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 @@ -184,6 +184,47 @@ export def "gm repo remote list" []: nothing -> table **Note** +# > will throw an error if `$remote` does not appear to be a valid URL. +# +# ## Examples +# ```nushell +# # add `https://www.example.com` to the remotes as `upstream` +# gm repo remote add upstream https://www.example.com +# ``` +# --- +# ```nushell +# # add `https://www.example.com` to the remotes as `upstream`, using the SSH protocol +# gm repo remote add upstream https://www.example.com --ssh +# ``` +export def "gm repo remote add" [name: string, remote: string, --ssh]: nothing -> nothing { + try { + $remote | url parse + } catch { + throw-error { + msg: "remote_not_a_url", + text: "not a valid URL", + span: (metadata $remote).span, + } + } + + let $remote = if $ssh { + $remote | url parse | update scheme "ssh" | url join + } else { + $remote + } + + if $name in (^git remote show | lines) { + log warning $"changing remote '($name)' to '($remote)'" + ^git remote set-url $name $remote + } else { + log info $"adding remote '($name)' as '($remote)'" + ^git remote add $name $remote + } +} + # fetch a remote branch locally, without pulling down the whole remote export def "gm repo branch fetch" [ remote: string@get-remotes, # the branch to fetch From 12373f975197e180cb73c3c0006a273ecf004d1c Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 11:20:15 +0200 Subject: [PATCH 6/7] generate the doc --- docs/index.md | 1 + .../git/gm-repo-bisect.md | 2 +- .../git/gm-repo-branch-fetch.md | 2 +- .../git/gm-repo-branch-interactive-delete.md | 2 +- docs/nu-git-manager-sugar/git/gm-repo-ls.md | 2 +- .../nu-git-manager-sugar/git/gm-repo-query.md | 2 +- .../git/gm-repo-remote-add.md | 27 +++++++++++++++++++ .../git/gm-repo-switch.md | 2 +- docs/nu-git-manager-sugar/git/index.md | 1 + 9 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 docs/nu-git-manager-sugar/git/gm-repo-remote-add.md diff --git a/docs/index.md b/docs/index.md index 45dc41c1..685d2c27 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,6 +29,7 @@ - [`gm repo ls`](nu-git-manager-sugar/git/gm-repo-ls.md) - [`gm repo query`](nu-git-manager-sugar/git/gm-repo-query.md) - [`gm repo remote`](nu-git-manager-sugar/git/gm-repo-remote.md) +- [`gm repo remote add`](nu-git-manager-sugar/git/gm-repo-remote-add.md) - [`gm repo remote list`](nu-git-manager-sugar/git/gm-repo-remote-list.md) - [`gm repo switch`](nu-git-manager-sugar/git/gm-repo-switch.md) - [`setup`](nu-git-manager-sugar/git/prompt/setup.md) 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 19678c83..fe40495a 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#L394)) +# `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#L435)) bisect a worktree by running a piece of code repeatedly # Examples 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 78072c68..8fb924f4 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#L188)) +# `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)) 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 65303a63..be3a5a95 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#L240)) +# `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#L281)) remove a branch interactively 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 ea8ba60f..8d27410e 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#L284)) +# `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#L325)) 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 71dfa3c3..f071d66d 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#L334)) +# `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#L375)) 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 new file mode 100644 index 00000000..9905c0e0 --- /dev/null +++ b/docs/nu-git-manager-sugar/git/gm-repo-remote-add.md @@ -0,0 +1,27 @@ +# `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)) +add a remote to the current repository + +> **Note** +> will throw an error if `$remote` does not appear to be a valid URL. + +## Examples +```nushell +# add `https://www.example.com` to the remotes as `upstream` +gm repo remote add upstream https://www.example.com +``` +--- +```nushell +# add `https://www.example.com` to the remotes as `upstream`, using the SSH protocol +gm repo remote add upstream https://www.example.com --ssh +``` + +## Parameters +- `name` <`string`>: +- `remote` <`string`>: +- `--ssh` <`bool`>: + + +## Signatures +| input | output | +| --------- | --------- | +| `nothing` | `nothing` | 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 27932460..d3d010e5 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#L260)) +# `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#L301)) switch between branches interactively diff --git a/docs/nu-git-manager-sugar/git/index.md b/docs/nu-git-manager-sugar/git/index.md index 1f5630a7..d834d336 100644 --- a/docs/nu-git-manager-sugar/git/index.md +++ b/docs/nu-git-manager-sugar/git/index.md @@ -20,6 +20,7 @@ ships a bunch of helper commands that augments the capabilities of Git. - [`gm repo ls`](gm-repo-ls.md) - [`gm repo query`](gm-repo-query.md) - [`gm repo remote`](gm-repo-remote.md) +- [`gm repo remote add`](gm-repo-remote-add.md) - [`gm repo remote list`](gm-repo-remote-list.md) - [`gm repo switch`](gm-repo-switch.md) From 5ba1913088c4f710701a70723e6c99364950dc27 Mon Sep 17 00:00:00 2001 From: amtoine Date: Sat, 20 Apr 2024 11:25:37 +0200 Subject: [PATCH 7/7] fix tests (commands names and imports) --- pkgs/nu-git-manager-sugar/tests/git.nu | 29 +++++++++++++------------- pkgs/nu-git-manager-sugar/tests/mod.nu | 10 +++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkgs/nu-git-manager-sugar/tests/git.nu b/pkgs/nu-git-manager-sugar/tests/git.nu index e960d1ff..1e98c378 100644 --- a/pkgs/nu-git-manager-sugar/tests/git.nu +++ b/pkgs/nu-git-manager-sugar/tests/git.nu @@ -3,10 +3,11 @@ use std assert use ../../../pkgs/nu-git-manager-sugar/nu-git-manager-sugar/ git [ "gm repo get commit" "gm repo goto root" - "gm repo branches" + "gm repo branch list" + "gm repo branch clean" "gm repo is-ancestor" "gm repo remote list" - "gm repo fetch branch" + "gm repo branch fetch" "gm repo ls" "gm repo branch wipe" "gm repo compare" @@ -62,11 +63,11 @@ export def goto-root [] { export def branches [] { let repo = init-repo-and-cd-into - assert equal (gm repo branches) [] + assert equal (gm repo branch list) [] commit "init" - assert equal (gm repo branches) [{branch: main, remotes: []}] + assert equal (gm repo branch list) [{branch: main, remotes: []}] clean $repo } @@ -80,8 +81,8 @@ export def branches-checked-out [] { ^git branch foo ^git checkout bar - gm repo branches --clean - assert equal (gm repo branches) [{branch: bar, remotes: []}, ] + gm repo branch clean + assert equal (gm repo branch list) [{branch: bar, remotes: []}, ] clean $repo } @@ -95,8 +96,8 @@ export def branches-detached [] { ^git branch foo ^git checkout $hash - gm repo branches --clean - assert equal (gm repo branches) [] + gm repo branch clean + assert equal (gm repo branch list) [] clean $repo } @@ -145,7 +146,7 @@ export def branch-fetch [] { do { cd $bar - gm repo fetch branch $"file://($foo)" foo + gm repo branch fetch $"file://($foo)" foo assert simple-git-tree-equal [ "(foo) c2", @@ -158,7 +159,7 @@ export def branch-fetch [] { do { cd $bar - gm repo fetch branch $"file://($foo)" foo + gm repo branch fetch $"file://($foo)" foo assert simple-git-tree-equal [ "(foo) c4", @@ -175,7 +176,7 @@ export def branch-fetch [] { do { cd $bar - gm repo fetch branch $"file://($foo)" foo + gm repo branch fetch $"file://($foo)" foo assert simple-git-tree-equal --extra-revs ["FETCH_HEAD"] [ "c6", @@ -190,7 +191,7 @@ export def branch-fetch [] { do { cd $bar - gm repo fetch branch $"file://($foo)" foo --strategy "rebase" + gm repo branch fetch $"file://($foo)" foo --strategy "rebase" assert simple-git-tree-equal [ "(HEAD -> foo) c6", @@ -207,7 +208,7 @@ export def branch-fetch [] { do { cd $bar - gm repo fetch branch $"file://($foo)" foo --strategy "merge" + gm repo branch fetch $"file://($foo)" foo --strategy "merge" assert simple-git-tree-equal [ "(HEAD -> foo) c8", @@ -222,7 +223,7 @@ export def branch-fetch [] { ] } - assert error { gm repo fetch branch $"file://($foo)" foo --strategy "" } + assert error { gm repo branch fetch $"file://($foo)" foo --strategy "" } clean $foo clean $bar diff --git a/pkgs/nu-git-manager-sugar/tests/mod.nu b/pkgs/nu-git-manager-sugar/tests/mod.nu index e44c0ca7..126ea0f2 100644 --- a/pkgs/nu-git-manager-sugar/tests/mod.nu +++ b/pkgs/nu-git-manager-sugar/tests/mod.nu @@ -14,17 +14,22 @@ export module imports { export def git [] { assert imports $MODULE "git" [ + "gm repo", "gm repo bisect", + "gm repo branch", + "gm repo branch clean", + "gm repo branch fetch", "gm repo branch interactive-delete", + "gm repo branch list", "gm repo branch wipe", - "gm repo branches", "gm repo compare", - "gm repo fetch branch", "gm repo get commit", "gm repo goto root", "gm repo is-ancestor", "gm repo ls", "gm repo query", + "gm repo remote", + "gm repo remote add", "gm repo remote list", "gm repo switch", "prompt setup", @@ -33,6 +38,7 @@ export module imports { export def github [] { assert imports $MODULE "github" [ + "gm gh", "gm gh pr checkout", "gm gh query-api", "gm gh query-releases",