Skip to content

Commit

Permalink
add completions to gm repo fetch branch
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Dec 14, 2023
1 parent 3c67d27 commit 39d300c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
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 39d300c

Please sign in to comment.