From b32bf2261617d30019d25d04ce451a29e7297c14 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 30 Apr 2016 16:21:41 +0200 Subject: Add repository/refspec completion to git A few commands (fetch, pull and push at least) take a "repository" (aka "remote") and then a "refspec" (we currently do branches here). Fixes #2525 (seems that man is still alive) --- share/completions/git.fish | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'share') diff --git a/share/completions/git.fish b/share/completions/git.fish index becc984c..1bfe80b8 100644 --- a/share/completions/git.fish +++ b/share/completions/git.fish @@ -171,12 +171,29 @@ function __fish_git_custom_commands end end +# Suggest branches for the specified remote - returns 1 if no known remote is specified +function __fish_git_branch_for_remote + set -l remotes (__fish_git_remotes) + set -l remote + set -l cmd (commandline -opc) + for r in $remotes + if contains -- $r $cmd + set remote $r + break + end + end + set -q remote[1]; or return 1 + __fish_git_branches | string match -- "$remote/*" | string replace -- "$remote/" '' +end + # general options complete -f -c git -l help -d 'Display the manual of a git command' #### fetch complete -f -c git -n '__fish_git_needs_command' -a fetch -d 'Download objects and refs from another repository' -complete -f -c git -n '__fish_git_using_command fetch' -a '(__fish_git_remotes)' -d 'Remote' +# Suggest "repository", then "refspec" - this also applies to e.g. push/pull +complete -f -c git -n '__fish_git_using_command fetch; and not __fish_git_branch_for_remote' -a '(__fish_git_remotes)' -d 'Remote' +complete -f -c git -n '__fish_git_using_command fetch; and __fish_git_branch_for_remote' -a '(__fish_git_branch_for_remote)' -d 'Branch' complete -f -c git -n '__fish_git_using_command fetch' -s q -l quiet -d 'Be quiet' complete -f -c git -n '__fish_git_using_command fetch' -s v -l verbose -d 'Be verbose' complete -f -c git -n '__fish_git_using_command fetch' -s a -l append -d 'Append ref names and object names' @@ -393,15 +410,14 @@ complete -f -c git -n '__fish_git_using_command pull' -s k -l keep -d 'Keep down complete -f -c git -n '__fish_git_using_command pull' -l no-tags -d 'Disable automatic tag following' # TODO --upload-pack complete -f -c git -n '__fish_git_using_command pull' -l progress -d 'Force progress status' -complete -f -c git -n '__fish_git_using_command pull' -a '(git remote)' -d 'Remote alias' -complete -f -c git -n '__fish_git_using_command pull' -a '(__fish_git_branches)' -d 'Branch' -complete -f -c git -n '__fish_git_using_command pull' -a '(__fish_git_unique_remote_branches)' -d 'Remote branch' +complete -f -c git -n '__fish_git_using_command pull; and not __fish_git_branch_for_remote' -a '(__fish_git_remotes)' -d 'Remote alias' +complete -f -c git -n '__fish_git_using_command pull; and __fish_git_branch_for_remote' -a '(__fish_git_branch_for_remote)' -d 'Branch' # TODO other options ### push complete -f -c git -n '__fish_git_needs_command' -a push -d 'Update remote refs along with associated objects' -complete -f -c git -n '__fish_git_using_command push' -a '(git remote)' -d 'Remote alias' -complete -f -c git -n '__fish_git_using_command push' -a '(__fish_git_branches)' -d 'Branch' +complete -f -c git -n '__fish_git_using_command push; and not __fish_git_branch_for_remote' -a '(__fish_git_remotes)' -d 'Remote alias' +complete -f -c git -n '__fish_git_using_command push; and __fish_git_branch_for_remote' -a '(__fish_git_branches)' -d 'Branch' complete -f -c git -n '__fish_git_using_command push' -l all -d 'Push all refs under refs/heads/' complete -f -c git -n '__fish_git_using_command push' -l prune -d "Remove remote branches that don't have a local counterpart" complete -f -c git -n '__fish_git_using_command push' -l mirror -d 'Push all refs under refs/' @@ -418,7 +434,7 @@ complete -f -c git -n '__fish_git_using_command push' -l progress -d 'Force prog ### rebase complete -f -c git -n '__fish_git_needs_command' -a rebase -d 'Forward-port local commits to the updated upstream head' -complete -f -c git -n '__fish_git_using_command rebase' -a '(git remote)' -d 'Remote alias' +complete -f -c git -n '__fish_git_using_command rebase' -a '(__fish_git_remotes)' -d 'Remote alias' complete -f -c git -n '__fish_git_using_command rebase' -a '(__fish_git_branches)' -d 'Branch' complete -f -c git -n '__fish_git_using_command rebase' -l continue -d 'Restart the rebasing process' complete -f -c git -n '__fish_git_using_command rebase' -l abort -d 'Abort the rebase operation' -- cgit v1.2.3