Skip to content

Commit

Permalink
add completions to gm repo fetch branch (#138)
Browse files Browse the repository at this point in the history
as per title
  • Loading branch information
amtoine authored Dec 14, 2023
1 parent 3c67d27 commit 0e54f60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
9 changes: 6 additions & 3 deletions docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ fetch a remote branch locally, without pulling down the whole remote
## Parameters
- parameter_name: remote
- parameter_type: positional
- syntax_shape: string
- syntax_shape: completable<string>
- is_optional: false
- description: the branch to fetch
- custom_completion: get-remotes
---
- parameter_name: branch
- parameter_type: positional
- syntax_shape: string
- syntax_shape: completable<string>
- is_optional: false
- description: the remote to fetch the branch from
- custom_completion: get-branches
---
- parameter_name: strategy
- parameter_type: named
- syntax_shape: string
- syntax_shape: completable<string>
- is_optional: true
- description: the merge strategy to use
- custom_completion: get-strategies
- parameter_default: none

## Signatures
Expand Down
14 changes: 14 additions & 0 deletions src/nu-git-manager-sugar/completions/nu-complete.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ export const GIT_QUERY_TABLES = ["refs", "commits", "diffs", "branches", "tags"]
export def git-query-tables []: nothing -> list<string> {
$GIT_QUERY_TABLES
}

export const GIT_STRATEGIES = ["merge", "rebase", "none"]

export def get-remotes []: nothing -> list<string> {
^git remote --verbose show | lines | parse "{remote}\t{rest}" | get remote | uniq
}

export def get-branches []: nothing -> list<string> {
^git branch | lines | str substring 2..
}

export def get-strategies []: nothing -> list<string> {
$GIT_STRATEGIES
}
12 changes: 7 additions & 5 deletions src/nu-git-manager-sugar/git/mod.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std log

use ../git/lib/lib.nu [get-status]

use ../completions/nu-complete.nu [GIT_QUERY_TABLES, git-query-tables]
use ../completions/nu-complete.nu [
GIT_QUERY_TABLES, GIT_STRATEGIES, git-query-tables, get-remotes, get-branches, get-strategies
]

# get the commit hash of any revision
#
Expand Down Expand Up @@ -164,9 +166,9 @@ export def "gm repo remote list" []: nothing -> table<remote: string, fetch: str

# fetch a remote branch locally, without pulling down the whole remote
export def "gm repo fetch branch" [
remote: string, # the branch to fetch
branch: string, # the remote to fetch the branch from
--strategy: string = "none" # the merge strategy to use
remote: string@get-remotes, # the branch to fetch
branch: string@get-branches, # the remote to fetch the branch from
--strategy: string@get-strategies = "none" # the merge strategy to use
]: nothing -> nothing {
^git fetch $remote $branch

Expand All @@ -190,7 +192,7 @@ export def "gm repo fetch branch" [
error make {
msg: $"(ansi red_bold)invalid_strategy(ansi reset)"
label: {
text: "expected one of ['merge', 'rebase', 'none']"
text: $"expected one of ($GIT_STRATEGIES)"
span: (metadata $strategy).span
}
}
Expand Down

0 comments on commit 0e54f60

Please sign in to comment.