summaryrefslogtreecommitdiff
path: root/Completion/Unix/Command/_git
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Command/_git')
-rw-r--r--Completion/Unix/Command/_git273
1 files changed, 178 insertions, 95 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index c4e386b15..979e3e76f 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -4,7 +4,7 @@
#
# Say you got your own git sub-commands (git will run a program `git-foo'
# when you run "git foo") and you want "git f<tab>" to complete that sub
-# commands name for you. You can make that sub-command know to the completion
+# commands name for you. You can make that sub-command known to the completion
# via the user-command style:
#
# % zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'
@@ -20,17 +20,13 @@
# completion as well. Place such a function inside an autoloaded #compdef file
# and you should be all set. You can add a description to such a function by
# adding a line matching
-#
+#
# #description DESCRIPTION
#
# as the second line in the file. See
# Completion/Debian/Command/_git-buildpackage in the Zsh sources for an
# example.
#
-# As this solution is so much better than the user-commands zstyle method, the
-# zstyle method is now DEPRECATED. It will most likely be removed in the next
-# major release of Zsh (5.0).
-#
# When _git does not know a given sub-command (say `bar'), it falls back to
# completing file names for all arguments to that sub command. I.e.:
#
@@ -651,8 +647,8 @@ _git-commit () {
# TODO: --interactive isn't explicitly listed in the documentation.
_arguments -w -S -s \
'(-a --all --interactive -o --only -i --include *)'{-a,--all}'[stage all modified and deleted paths]' \
- '--fixup=[construct a commit message for use with rebase --autosquash]:' \
- '--squash=[construct a commit message for use with rebase --autosquash]:' \
+ '--fixup=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
+ '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
$reset_author_opt \
'( --porcelain --dry-run)--short[output dry run in short format]' \
'(--short --dry-run)--porcelain[output dry run in porcelain-ready format]' \
@@ -1339,13 +1335,13 @@ _git-rebase () {
'(-i --interactive --ignore-whitespace --whitespace --committer-date-is-author-date)'{-i,--interactive}'[make a list of commits to be rebased and open in $EDITOR]' \
'--edit-todo[edit interactive instruction sheet in an editor]' \
'(-p --preserve-merges --interactive)'{-p,--preserve-merges}'[try to recreate merges instead of ignoring them]' \
- {-x,--exec}'[with -i\: append "exec <cmd>" after each line]:command' \
+ {-x,--exec=}'[with -i\: append "exec <cmd>" after each line]:command:_command_names -e' \
'(1)--root[rebase all reachable commits]' \
$autosquash_opts \
'(--autostash --no-autostash)--autostash[stash uncommitted changes before rebasing and apply them afterwards]' \
'(--autostash --no-autostash)--no-autostash[do not stash uncommitted changes before rebasing and apply them afterwards]' \
'--no-ff[cherry-pick all rebased commits with --interactive, otherwise synonymous to --force-rebase]' \
- '--onto[start new branch with HEAD equal to given revision]:newbase:__git_revisions' \
+ '--onto=[start new branch with HEAD equal to given revision]:newbase:__git_revisions' \
':upstream branch:__git_revisions' \
'::working branch:__git_branch_names'
}
@@ -1523,6 +1519,7 @@ _git-stash () {
case $state in
(command)
local -a commands
+ local -a save_arguments
commands=(
save:'save your local modifications to a new stash'
@@ -1535,19 +1532,24 @@ _git-stash () {
drop:'remove a single stashed state from the stash list'
create:'create a stash without storing it in the ref namespace')
+ save_arguments=(
+ '(--keep-index)--patch[interactively select hunks from diff between HEAD and working tree to stash]' \
+ '( --no-keep-index)--keep-index[all changes already added to the index are left intact]' \
+ '(--keep-index )--no-keep-index[all changes already added to the index are undone]' \
+ '(-q --quiet)'{-q,--quiet}'[suppress all output]' \
+ '(-u --include-untracked)'{-u,--include-untracked}'[include untracked files]' \
+ )
_describe -t commands command commands && ret=0
+ _arguments -S $save_arguments && ret=0 # "stash" defaults to "save", but without "message".
;;
(option-or-argument)
curcontext=${curcontext%:*}-$line[1]:
case $line[1] in
(save)
+ _arguments -S $save_arguments && ret=0
_arguments -S \
- '(--keep-index)--patch[interactively select hunks from diff between HEAD and working tree to stash]' \
- '( --no-keep-index)--keep-index[all changes already added to the index are left intact]' \
- '(--keep-index )--no-keep-index[all changes already added to the index are undone]' \
- '(-q --quiet)'{-q,--quiet}'[suppress all output]' \
- '(-u --include-untracked)'{-u,--include-untracked}'[include untracked files]' \
+ $save_arguments \
':: :_guard "([^-]?#|)" message' && ret=0
;;
(list)
@@ -3161,7 +3163,15 @@ _git-remote () {
'(-m --master)'{-m,--master=}'[set HEAD of remote to point to given master branch]: :__git_branch_names' \
'--mirror[do not use separate remotes]' \
':name:__git_remotes' \
- ':url:_urls' && ret=0
+ ':repository:->repository' && ret=0
+ case $state in
+ (repository)
+ _alternative \
+ 'local-repositories::__git_local_repositories' \
+ 'remote-repositories::__git_remote_repositories' \
+ 'urls::_urls' && ret=0
+ ;;
+ esac
;;
(rename)
_arguments \
@@ -3326,7 +3336,7 @@ _git-count-objects () {
_git-difftool () {
# TODO: Is this fine, or do we need to modify the context or similar?
_git-diff \
- '--dir-diff[diff a whole tree by prepare a temporary copy]' \
+ '(-d --dir-diff)'{-d,--dir-diff}'[diff a whole tree by preparing a temporary copy]' \
'(-y --no-prompt --prompt)'{-y,--no-prompt}'[do not prompt before invocation of diff tool]' \
'(-y --no-prompt)--prompt[prompt before invocation of diff tool]' \
'(-t --tool -x --extcmd)'{-t,--tool=-}'[merge resolution program to use]: :__git_difftools' \
@@ -3721,7 +3731,7 @@ _git-send-email () {
'(--format-patch )--no-format-patch[interpret ambiguous arguments file-name arguments]' \
'--quiet[be less verbose]' \
'( --no-validate)--validate[perform sanity checks on patches]' \
- '(--validate )--validate[do not perform sanity checks on patches]' \
+ '(--validate )--no-validate[do not perform sanity checks on patches]' \
'--force[send emails even if safety checks would prevent it]' \
'*: :_files'
}
@@ -5198,20 +5208,60 @@ _git_commands () {
integer ret=1
- # TODO: Is this the correct way of doing it? Should we be using _alternative
- # and separate functions for each set of commands instead?
- _describe -t aliases alias unique_aliases && ret=0
- _describe -t main-porcelain-commands 'main porcelain command' main_porcelain_commands && ret=0
- _describe -t user-commands 'user command' user_commands && ret=0
- _describe -t third-party-commands 'third-party command' third_party_commands && ret=0
- _describe -t ancillary-manipulator-commands 'ancillary manipulator command' ancillary_manipulator_commands && ret=0
- _describe -t ancillary-interrogator-commands 'ancillary interrogator command' ancillary_interrogator_commands && ret=0
- _describe -t interaction-commands 'interaction command' interaction_commands && ret=0
- _describe -t plumbing-manipulator-commands 'plumbing manipulator command' plumbing_manipulator_commands && ret=0
- _describe -t plumbing-interrogator-commands 'plumbing interrogator command' plumbing_interrogator_commands && ret=0
- _describe -t plumbing-sync-commands 'plumbing sync command' plumbing_sync_commands && ret=0
- _describe -t plumbing-sync-helper-commands 'plumbing sync helper command' plumbing_sync_helper_commands && ret=0
- _describe -t plumbing-internal-helper-commands 'plumbing internal helper command' plumbing_internal_helper_commands && ret=0
+ _tags \
+ aliases \
+ main-porcelain-commands \
+ user-commands \
+ third-party-commands \
+ ancillary-manipulator-commands \
+ ancillary-interrogator-commands \
+ interaction-commands \
+ plumbing-manipulator-commands \
+ plumbing-interrogator-commands \
+ plumbing-sync-commands \
+ plumbing-sync-helper-commands \
+ plumbing-internal-helper-commands
+
+ while _tags; do
+
+ _requested aliases && \
+ _describe -t aliases 'alias' unique_aliases && ret=0
+
+ _requested main-porcelain-commands && \
+ _describe -t main-porcelain-commands 'main porcelain command' main_porcelain_commands && ret=0
+
+ _requested user-commands && \
+ _describe -t user-commands 'user command' user_commands && ret=0
+
+ _requested third-party-commands && \
+ _describe -t third-party-commands 'third-party command' third_party_commands && ret=0
+
+ _requested ancillary-manipulator-commands && \
+ _describe -t ancillary-manipulator-commands 'ancillary manipulator command' ancillary_manipulator_commands && ret=0
+
+ _requested ancillary-interrogator-commands && \
+ _describe -t ancillary-interrogator-commands 'ancillary interrogator command' ancillary_interrogator_commands && ret=0
+
+ _requested interaction-commands && \
+ _describe -t interaction-commands 'interaction command' interaction_commands && ret=0
+
+ _requested plumbing-manipulator-commands && \
+ _describe -t plumbing-manipulator-commands 'plumbing manipulator command' plumbing_manipulator_commands && ret=0
+
+ _requested plumbing-interrogator-commands && \
+ _describe -t plumbing-interrogator-commands 'plumbing interrogator command' plumbing_interrogator_commands && ret=0
+
+ _requested plumbing-sync-commands && \
+ _describe -t plumbing-sync-commands 'plumbing sync command' plumbing_sync_commands && ret=0
+
+ _requested plumbing-sync-helper-commands && \
+ _describe -t plumbing-sync-helper-commands 'plumbing sync helper command' plumbing_sync_helper_commands && ret=0
+
+ _requested plumbing-internal-helper-commands && \
+ _describe -t plumbing-internal-helper-commands 'plumbing internal helper command' plumbing_internal_helper_commands && ret=0
+
+ (( ret )) || break
+ done
return ret
}
@@ -5262,12 +5312,10 @@ __git_gpg_secret_keys () {
(( $+functions[__git_merge_strategies] )) ||
__git_merge_strategies () {
local expl
- local -a merge_strategies
- merge_strategies=(${=${${(M)${(f)"$(_call_program merge-strategies "git merge -s '' 2>&1")"}:#[Aa]vailable (custom )#strategies are: *}#[Aa]vailable (custom )#strategies are: }%.})
- __git_command_successful $pipestatus || return 1
-
- _wanted merge-strategies expl 'merge strategy' compadd $* - $merge_strategies
+ _wanted merge-strategies expl 'merge strategy' compadd "$@" - \
+ ${=${${${(M)${(f)"$(_call_program merge-strategies \
+ "git merge -s '' 2>&1")"}:#[Aa]vailable (custom )#strategies are: *}#[Aa]vailable (custom )#strategies are: }%.}:-octopus ours recursive resolve subtree}
}
(( $+functions[__git_encodings] )) ||
@@ -5299,8 +5347,9 @@ __git_remotes () {
local remotes expl
remotes=(${(f)"$(_call_program remotes git remote 2>/dev/null)"})
+ __git_command_successful $pipestatus || return 1
- _wanted remotes expl remote compadd $* - $remotes
+ _wanted remotes expl remote compadd "$@" -a - remotes
}
(( $+functions[__git_ref_specs] )) ||
@@ -5431,13 +5480,7 @@ __git_reflog_entries () {
reflog_entries=(${${${(f)"$(_call_program reflog-entries git reflog 2>/dev/null)"}#* }%%:*})
__git_command_successful $pipestatus || return 1
- if compset -P '*@'; then
- reflog_entries=(${${(M)reflog_entries:#$IPREFIX*}#$IPREFIX})
- _wanted reflog-entries expl 'reflog entry' compadd $* - $reflog_entries
- else
- reflog_entries=(${reflog_entries%@*})
- _wanted reflog-entries expl 'reflog entry' compadd -qS @ $* - $reflog_entries
- fi
+ _wanted reflog-entries expl 'reflog entry' _multi_parts @ reflog_entries
}
(( $+functions[__git_ref_sort_keys] )) ||
@@ -5492,7 +5535,7 @@ __git_stashes () {
stashes=(${${(f)"$(_call_program stashes git stash list 2>/dev/null)"}/: */})
__git_command_successful $pipestatus || return 1
- _wanted stashes expl stash compadd $* - $stashes
+ _wanted stashes expl stash compadd "$@" -a - stashes
}
(( $+functions[__git_svn_revisions] )) ||
@@ -5531,7 +5574,7 @@ __git_branch_names () {
branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
__git_command_successful $pipestatus || return 1
- _wanted branch-names expl branch-name compadd $* - $branch_names
+ _wanted branch-names expl branch-name compadd "$@" -a - branch_names
}
(( $+functions[__git_remote_branch_names] )) ||
@@ -5542,7 +5585,7 @@ __git_remote_branch_names () {
branch_names=(${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/})
__git_command_successful $pipestatus || return 1
- _wanted remote-branch-names expl 'remote branch name' compadd $* - $branch_names
+ _wanted remote-branch-names expl 'remote branch name' compadd "$@" -a - branch_names
}
(( $+functions[__git_remote_branch_names_noprefix] )) ||
@@ -5553,7 +5596,7 @@ __git_remote_branch_names_noprefix () {
branch_names=(${${${(f)"$(_call_program remote-branch-refs-noprefix git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}##*/}:#HEAD})
__git_command_successful $pipestatus || return 1
- _wanted remote-branch-names-noprefix expl 'remote branch name' compadd $* - $branch_names
+ _wanted remote-branch-names-noprefix expl 'remote branch name' compadd "$@" -a - branch_names
}
(( $+functions[__git_commits] )) ||
@@ -5580,14 +5623,57 @@ __git_heads () {
for f in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
[[ -f $gitdir/$f ]] && heads+=$f
done
+ [[ -f $gitdir/refs/stash ]] && heads+=stash
fi
- _wanted heads expl head compadd $* - $heads
+ _wanted heads expl head compadd "$@" -a - heads
}
(( $+functions[__git_commit_objects] )) ||
__git_commit_objects () {
- _guard '[[:xdigit:]](#c,40)' 'commit object name'
+ local gitdir expl start
+ declare -a commits
+
+ # Note: the after-the-colon part must be unique across the entire array;
+ # see workers/34768
+ : ${(A)commits::=${(f)"$(_call_program commits git --no-pager log -20 --format='%h:\\\[%h\\\]\ %s')"}}
+ __git_command_successful $pipestatus || return 1
+
+ _describe -V -t commits 'commit object name' commits || _guard '[[:xdigit:]](#c,40)' 'commit object name'
+}
+
+(( $+functions[__git_recent_commits] )) ||
+__git_recent_commits () {
+ local gitdir expl start
+ declare -a descr tags heads commits
+ local i j k
+
+ # Careful: most %d will expand to the empty string. Quote properly!
+ : "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%d%n%s')"}}"
+ __git_command_successful $pipestatus || return 1
+
+ for i j k in "$commits[@]" ; do
+ # Note: the after-the-colon part must be unique across the entire array;
+ # see workers/34768
+ descr+=("$i:[$i] $k")
+ j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
+ for j in ${(s:, :)j}; do
+ if [[ $j == 'tag: '* ]] ; then
+ tags+=( ${j#tag: } )
+ else
+ heads+=( $j )
+ fi
+ done
+ done
+
+ ret=1
+ # Resetting expl to avoid it 'leaking' from one line to the next.
+ expl=()
+ _wanted commit-tags expl 'commit tag' compadd "$@" -a - tags && ret=0
+ expl=()
+ _wanted heads expl 'head' compadd "$@" -a - heads && ret=0
+ expl=()
+ _describe -2Vx -t commits 'commit object name' descr && ret=0
}
(( $+functions[__git_blob_objects] )) ||
@@ -5678,7 +5764,7 @@ __git_submodules () {
submodules=(${${${(f)"$(_call_program submodules git submodule 2>/dev/null)"}#?* }%% *})
__git_command_successful $pipestatus || return 1
- _wanted submodules expl submodule compadd $* - $submodules
+ _wanted submodules expl submodule compadd "$@" -a - submodules
}
# Tag Argument Types
@@ -5691,7 +5777,7 @@ __git_tags () {
tags=(${${(f)"$(_call_program tagrefs git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
__git_command_successful $pipestatus || return 1
- _wanted tags expl tag compadd $* - $tags
+ _wanted tags expl tag compadd "$@" -a - tags
}
(( $+functions[__git_commit_tags] )) ||
@@ -5714,7 +5800,7 @@ __git_tags_of_type () {
tags=(${${(M)${(f)"$(_call_program $type-tag-refs "git for-each-ref --format='%(*objecttype)%(objecttype) %(refname)' refs/tags 2>/dev/null")"}:#$type(tag|) *}#$type(tag|) refs/tags/})
__git_command_successful $pipestatus || return 1
- _wanted $type-tags expl "$type tag" compadd $* - $tags
+ _wanted $type-tags expl "$type tag" compadd "$@" -a - tags
}
# Reference Argument Types
@@ -5737,7 +5823,7 @@ __git_references () {
_git_refs_cache_pwd=$PWD
fi
- _wanted references expl 'references' compadd - $_git_refs_cache
+ _wanted references expl 'reference' compadd -a - _git_refs_cache
}
(( $+functions[__git_local_references] )) ||
@@ -5750,7 +5836,7 @@ __git_local_references () {
_git_local_refs_cache_pwd=$PWD
fi
- _wanted references expl 'references' compadd - $_git_local_refs_cache
+ _wanted references expl 'reference' compadd -a - _git_local_refs_cache
}
(( $+functions[__git_remote_references] )) ||
@@ -5766,7 +5852,7 @@ __git_notes_refs () {
notes_refs=(${${(f)"$(_call_program notes-refs git for-each-ref --format='"%(refname)"' refs/notes 2>/dev/null)"}#$type refs/notes/})
__git_command_successful $pipestatus || return 1
- _wanted notes-refs expl 'notes ref' compadd $* - $notes_refs
+ _wanted notes-refs expl 'notes ref' compadd "$@" -a - notes_refs
}
# File Argument Types
@@ -6406,7 +6492,6 @@ __git_config_values () {
# Git Config Sections and Types
(( $+functions[__git_browsers] )) ||
__git_browsers () {
- integer ret=1
local expl
declare -a userbrowsers builtinbrowsers
@@ -6431,16 +6516,9 @@ __git_browsers () {
cygstart
xdg-open)
- _tags user-browsers builtin-browsers
-
- while _tags; do
- _requested user-browsers expl 'user-defined browser' compadd $* - $userbrowsers && ret=0
- _requested builtin-browsers expl 'builtin browser' compadd $* - $builtinbrowsers && ret=0
-
- (( ret )) || break
- done
-
- return ret
+ _alternative \
+ 'user-browsers:user-defined browser:compadd -a - userbrowsers' \
+ 'builtin-browsers:builtin browser:compadd -a - builtinbrowsers'
}
(( $+functions[__git_difftools] )) ||
@@ -6458,21 +6536,28 @@ __git_diff-or-merge-tools () {
[[ $type == diff ]] && __git_config_get_regexp '^difftool\..+\.cmd$' userdifftools
__git_config_get_regexp '^mergetool\..+\.cmd$' usermergetools
builtintools=(
+ araxis
+ bc
+ bc3
+ codecompare
+ deltawalker
+ diffmerge
+ diffuse
+ ecmerge
+ emerge
+ gvimdiff
+ gvimdiff2
+ gvimdiff3
kdiff3
- tkdiff
- xxdiff
meld
opendiff
+ p4merge
+ tkdiff
+ tortoisemerge
vimdiff
- gvimdiff
vimdiff2
vimdiff3
- gvimdiff2
- emerge
- ecmerge
- diffuse
- araxis
- p4merge)
+ xxdiff)
builtindifftools=($builtintools kompare)
builtinmergetools=($builtintools tortoisemerge)
@@ -6483,10 +6568,10 @@ __git_diff-or-merge-tools () {
esac
while _tags; do
- _requested user-difftools expl 'user-defined difftool' compadd $* - $userdifftools && ret=0
- _requested user-mergetools expl 'user-defined mergetool' compadd $* - $usermergetools && ret=0
- _requested builtin-difftools expl 'builtin difftool' compadd $* - $builtindifftools && ret=0
- _requested builtin-mergetools expl 'builtin mergetool' compadd $* - $builtinmergetools && ret=0
+ _requested user-difftools expl 'user-defined difftool' compadd "$@" -a - userdifftools && ret=0
+ _requested user-mergetools expl 'user-defined mergetool' compadd "$@" -a - usermergetools && ret=0
+ _requested builtin-difftools expl 'builtin difftool' compadd "$@" -a - builtindifftools && ret=0
+ _requested builtin-mergetools expl 'builtin mergetool' compadd "$@" -a - builtinmergetools && ret=0
(( ret )) || break
done
@@ -6577,20 +6662,18 @@ __git_sendemail_suppresscc_values () {
(( $+functions[__git_colors] )) ||
__git_colors () {
- declare -a colors
+ declare -a expl
- colors=(black red green yellow blue magenta cyan white)
-
- _describe -t colors color colors $*
+ _wanted colors expl color compadd "$@" - \
+ black red green yellow blue magenta cyan white
}
(( $+functions[__git_color_attributes] )) ||
__git_color_attributes () {
- declare -a attributes
-
- attributes=(bold dim ul blink reverse)
+ declare -a expl
- _describe -t attributes attribute attributes $*
+ _wanted attributes expl attribute compadd "$@" - \
+ bold dim ul blink reverse
}
# Now, for the main drive...
@@ -6657,12 +6740,12 @@ _git() {
(option-or-argument)
curcontext=${curcontext%:*:*}:git-$words[1]:
- if (( $+functions[_git-$words[1]] )); then
- _call_function ret _git-$words[1]
- elif zstyle -T :completion:$curcontext: use-fallback; then
- _files && ret=0
- else
- _message 'unknown sub-command'
+ if ! _call_function ret _git-$words[1]; then
+ if zstyle -T :completion:$curcontext: use-fallback; then
+ _default && ret=0
+ else
+ _message "unknown sub-command: $words[1]"
+ fi
fi
;;
esac