diff --git a/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md b/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md index 535856c3..26f2d0ea 100644 --- a/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md +++ b/docs/nu-git-manager-sugar/git/gm-repo-fetch-branch.md @@ -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 - is_optional: false - description: the branch to fetch +- custom_completion: get-remotes --- - parameter_name: branch - parameter_type: positional -- syntax_shape: string +- syntax_shape: completable - 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 - is_optional: true - description: the merge strategy to use +- custom_completion: get-strategies - parameter_default: none ## Signatures diff --git a/src/nu-git-manager-sugar/completions/nu-complete.nu b/src/nu-git-manager-sugar/completions/nu-complete.nu index 6311a5a9..922fa67e 100644 --- a/src/nu-git-manager-sugar/completions/nu-complete.nu +++ b/src/nu-git-manager-sugar/completions/nu-complete.nu @@ -3,3 +3,17 @@ export const GIT_QUERY_TABLES = ["refs", "commits", "diffs", "branches", "tags"] export def git-query-tables []: nothing -> list { $GIT_QUERY_TABLES } + +export const GIT_STRATEGIES = ["merge", "rebase", "none"] + +export def get-remotes []: nothing -> list { + ^git remote --verbose show | lines | parse "{remote}\t{rest}" | get remote | uniq +} + +export def get-branches []: nothing -> list { + ^git branch | lines | str substring 2.. +} + +export def get-strategies []: nothing -> list { + $GIT_STRATEGIES +} diff --git a/src/nu-git-manager-sugar/git/mod.nu b/src/nu-git-manager-sugar/git/mod.nu index 00f2e243..04d89b5c 100644 --- a/src/nu-git-manager-sugar/git/mod.nu +++ b/src/nu-git-manager-sugar/git/mod.nu @@ -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 # @@ -164,9 +166,9 @@ export def "gm repo remote list" []: nothing -> table nothing { ^git fetch $remote $branch @@ -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 } }