Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add completions to gm repo fetch branch #138

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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