1 # bash/zsh completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) git email aliases for git-send-email
14 # *) tree paths within 'ref:path/to/file' expressions
15 # *) file paths within current working directory and index
16 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.bash
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 # If you use complex aliases of form '!f() { ... }; f', you can use the null
27 # command ':' as the first command in the function body to declare the desired
28 # completion style. For example '!f() { : git commit ; ... }; f' will
29 # tell the completion to use commit completion. This also works with aliases
30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
32 # If you have a command that is not part of git, but you would still
33 # like completion, you can use __git_complete:
35 # __git_complete gl git_log
37 # Or if it's a main command (i.e. git or gitk):
39 # __git_complete gk gitk
41 # Compatible with bash 3.2.57.
43 # You can set the following environment variables to influence the behavior of
44 # the completion routines:
46 # GIT_COMPLETION_CHECKOUT_NO_GUESS
48 # When set to "1", do not include "DWIM" suggestions in git-checkout
49 # and git-switch completion (e.g., completing "foo" when "origin/foo"
52 # GIT_COMPLETION_SHOW_ALL_COMMANDS
54 # When set to "1" suggest all commands, including plumbing commands
55 # which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
57 # GIT_COMPLETION_SHOW_ALL
59 # When set to "1" suggest all options, including options which are
60 # typically hidden (e.g. '--allow-empty' for 'git commit').
62 # The following functions are meant to modify COMPREPLY, which should not be
63 # modified directly. The purpose is to localize the modifications so it's
64 # easier to emulate it in Zsh. Every time a new __gitcomp* function is added,
65 # the corresponding function should be added to Zsh.
69 local x i=${#COMPREPLY[@]}
71 if [[ "$x" == "$3"* ]]; then
72 COMPREPLY[i++]="$2$x$4"
77 # Creates completion replies.
78 # It accepts 1 to 4 arguments:
79 # 1: List of possible completion words.
80 # 2: A prefix to be added to each possible completion word (optional).
81 # 3: Generate possible completion matches for this word (optional).
82 # 4: A suffix to be appended to each possible completion word (optional).
86 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
89 # Generates completion reply from newline-separated possible completion words
90 # by appending a space to all of them. The result is appended to COMPREPLY.
91 # It accepts 1 to 4 arguments:
92 # 1: List of possible completion words, separated by a single newline.
93 # 2: A prefix to be added to each possible completion word (optional).
94 # 3: Generate possible completion matches for this word (optional).
95 # 4: A suffix to be appended to each possible completion word instead of
96 # the default space (optional). If specified but empty, nothing is
101 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
104 # Appends prefiltered words to COMPREPLY without any additional processing.
105 # Callers must take care of providing only words that match the current word
106 # to be completed and adding any prefix and/or suffix (trailing space!), if
108 # 1: List of newline-separated matching completion words, complete with
117 # Generates completion reply with compgen from newline-separated possible
118 # completion filenames.
119 # It accepts 1 to 3 arguments:
120 # 1: List of possible completion filenames, separated by a single newline.
121 # 2: A directory prefix to be added to each possible completion filename
123 # 3: Generate possible completion matches for this word (optional).
128 # XXX does not work when the directory prefix contains a tilde,
129 # since tilde expansion is not applied.
130 # This means that COMPREPLY will be empty and Bash default
131 # completion will be used.
132 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
134 # use a hack to enable file mode in bash < 4
135 compopt -o filenames +o nospace 2>/dev/null ||
136 compgen -f /non-existing-dir/ >/dev/null ||
140 # Fills the COMPREPLY array with prefiltered paths without any additional
142 # Callers must take care of providing only paths that match the current path
143 # to be completed and adding any prefix path components, if necessary.
144 # 1: List of newline-separated matching paths, complete with all prefix
146 __gitcomp_file_direct ()
152 # use a hack to enable file mode in bash < 4
153 compopt -o filenames +o nospace 2>/dev/null ||
154 compgen -f /non-existing-dir/ >/dev/null ||
158 # Creates completion replies, reorganizing options and adding suffixes as needed.
159 # It accepts 1 to 4 arguments:
160 # 1: List of possible completion words.
161 # 2: A prefix to be added to each possible completion word (optional).
162 # 3: Generate possible completion matches for this word (optional).
163 # 4: A suffix to be appended to each possible completion word (optional).
166 local cur_="${3-$cur}"
168 if [[ "$cur_" == *= ]]; then
172 local c i=0 IFS=$' \t\n' sfx
174 if [[ $c == "--" ]]; then
175 if [[ "$cur_" == --no-* ]]; then
179 if [[ --no == "$cur_"* ]]; then
180 COMPREPLY[i++]="--no-... "
184 if [[ $c == "$cur_"* ]]; then
185 if [[ -z "${4+set}" ]]; then
193 COMPREPLY[i++]="${2-}$c$sfx"
198 # __gitcomp functions end here
199 # ==============================================================================
201 # Discovers the path to the git repository taking any '--git-dir=<path>' and
202 # '-C <path>' options into account and stores it in the $__git_repo_path
204 __git_find_repo_path ()
206 if [ -n "${__git_repo_path-}" ]; then
207 # we already know where it is
211 if [ -n "${__git_C_args-}" ]; then
212 __git_repo_path="$(git "${__git_C_args[@]}" \
213 ${__git_dir:+--git-dir="$__git_dir"} \
214 rev-parse --absolute-git-dir 2>/dev/null)"
215 elif [ -n "${__git_dir-}" ]; then
216 test -d "$__git_dir" &&
217 __git_repo_path="$__git_dir"
218 elif [ -n "${GIT_DIR-}" ]; then
219 test -d "$GIT_DIR" &&
220 __git_repo_path="$GIT_DIR"
221 elif [ -d .git ]; then
224 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
228 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead
229 # __gitdir accepts 0 or 1 arguments (i.e., location)
230 # returns location of .git repo
233 if [ -z "${1-}" ]; then
234 __git_find_repo_path || return 1
235 echo "$__git_repo_path"
236 elif [ -d "$1/.git" ]; then
243 # Runs git with all the options given as argument, respecting any
244 # '--git-dir=<path>' and '-C <path>' options present on the command line
247 git ${__git_C_args:+"${__git_C_args[@]}"} \
248 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
251 # Removes backslash escaping, single quotes and double quotes from a word,
252 # stores the result in the variable $dequoted_word.
253 # 1: The word to dequote.
256 local rest="$1" len ch
260 while test -n "$rest"; do
261 len=${#dequoted_word}
262 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
263 rest="${rest:$((${#dequoted_word}-$len))}"
265 case "${rest:0:1}" in
272 dequoted_word="$dequoted_word$ch"
279 len=${#dequoted_word}
280 dequoted_word="$dequoted_word${rest%%\'*}"
281 rest="${rest:$((${#dequoted_word}-$len+1))}"
285 while test -n "$rest" ; do
286 len=${#dequoted_word}
287 dequoted_word="$dequoted_word${rest%%[\\\"]*}"
288 rest="${rest:$((${#dequoted_word}-$len))}"
289 case "${rest:0:1}" in
294 dequoted_word="$dequoted_word$ch"
299 dequoted_word="$dequoted_word\\$ch"
315 # Clear the variables caching builtins' options when (re-)sourcing
316 # the completion script.
317 if [[ -n ${ZSH_VERSION-} ]]; then
318 unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
320 unset $(compgen -v __gitcomp_builtin_)
323 __gitcomp_builtin_add_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --sparse --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-sparse --no-chmod --no-pathspec-from-file --no-pathspec-file-nul"
324 __gitcomp_builtin_am_default=" --interactive --3way --quiet --signoff --utf8 --keep --keep-non-patch --message-id --keep-cr --no-keep-cr --scissors --quoted-cr= --whitespace= --ignore-space-change --ignore-whitespace --directory= --exclude= --include= --patch-format= --reject --resolvemsg= --continue --resolved --skip --abort --quit --show-current-patch --allow-empty --committer-date-is-author-date --ignore-date --rerere-autoupdate --gpg-sign --empty= -- --no-interactive --no-3way --no-quiet --no-signoff --no-utf8 --no-keep --no-keep-non-patch --no-message-id --no-scissors --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-directory --no-exclude --no-include --no-patch-format --no-reject --no-resolvemsg --no-committer-date-is-author-date --no-ignore-date --no-rerere-autoupdate --no-gpg-sign"
325 __gitcomp_builtin_apply_default=" --exclude= --include= --no-add --stat --numstat --summary --check --index --intent-to-add --cached --apply --3way --build-fake-ancestor= --whitespace= --ignore-space-change --ignore-whitespace --reverse --unidiff-zero --reject --allow-overlap --verbose --quiet --inaccurate-eof --recount --directory= --allow-empty --add -- --no-stat --no-numstat --no-summary --no-check --no-index --no-intent-to-add --no-cached --no-apply --no-3way --no-build-fake-ancestor --no-whitespace --no-ignore-space-change --no-ignore-whitespace --no-reverse --no-unidiff-zero --no-reject --no-allow-overlap --no-verbose --no-quiet --no-inaccurate-eof --no-recount --no-directory --no-allow-empty"
326 __gitcomp_builtin_archive_default=" --output= --remote= --exec= --no-output -- --no-remote --no-exec"
327 __gitcomp_builtin_bisect__helper_default=" --bisect-reset --bisect-next-check --bisect-terms --bisect-start --bisect-next --bisect-state --bisect-log --bisect-replay --bisect-skip --bisect-visualize --bisect-run --no-log --log"
328 __gitcomp_builtin_blame_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev"
329 __gitcomp_builtin_branch_default=" --verbose --quiet --track --set-upstream-to= --unset-upstream --color --remotes --contains --no-contains --abbrev --all --delete --move --copy --list --show-current --create-reflog --edit-description --merged --no-merged --column --sort= --points-at= --ignore-case --recurse-submodules --format= -- --no-verbose --no-quiet --no-track --no-set-upstream-to --no-unset-upstream --no-color --no-remotes --no-abbrev --no-all --no-delete --no-move --no-copy --no-list --no-show-current --no-create-reflog --no-edit-description --no-column --no-sort --no-points-at --no-ignore-case --no-recurse-submodules --no-format"
330 __gitcomp_builtin_bugreport_default=" --output-directory= --suffix= --no-output-directory -- --no-suffix"
331 __gitcomp_builtin_cat_file_default=" --allow-unknown-type --batch --batch-check --batch-command --batch-all-objects --buffer --follow-symlinks --unordered --textconv --filters --path= --no-allow-unknown-type -- --no-buffer --no-follow-symlinks --no-unordered --no-path"
332 __gitcomp_builtin_check_attr_default=" --all --cached --stdin --no-all -- --no-cached --no-stdin"
333 __gitcomp_builtin_check_ignore_default=" --quiet --verbose --stdin --non-matching --no-index --index -- --no-quiet --no-verbose --no-stdin --no-non-matching"
334 __gitcomp_builtin_check_mailmap_default=" --stdin --no-stdin"
335 __gitcomp_builtin_checkout_default=" --guess --overlay --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-guess -- --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul"
336 __gitcomp_builtin_checkout__worker_default=" --prefix= --no-prefix"
337 __gitcomp_builtin_checkout_index_default=" --all --ignore-skip-worktree-bits --force --quiet --no-create --index --stdin --temp --prefix= --stage= --create -- --no-all --no-ignore-skip-worktree-bits --no-force --no-quiet --no-index --no-stdin --no-temp --no-prefix"
338 __gitcomp_builtin_cherry_default=" --abbrev --verbose --no-abbrev -- --no-verbose"
339 __gitcomp_builtin_cherry_pick_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --ff --allow-empty --allow-empty-message --keep-redundant-commits --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign --no-ff --no-allow-empty --no-allow-empty-message --no-keep-redundant-commits"
340 __gitcomp_builtin_clean_default=" --quiet --dry-run --interactive --exclude= --no-quiet -- --no-dry-run --no-interactive"
341 __gitcomp_builtin_clone_default=" --verbose --quiet --progress --reject-shallow --no-checkout --bare --mirror --local --no-hardlinks --shared --recurse-submodules --jobs= --template= --reference= --reference-if-able= --dissociate --origin= --branch= --upload-pack= --depth= --shallow-since= --shallow-exclude= --single-branch --no-tags --shallow-submodules --separate-git-dir= --config= --server-option= --ipv4 --ipv6 --filter= --also-filter-submodules --remote-submodules --sparse --checkout --hardlinks --tags -- --no-verbose --no-quiet --no-progress --no-reject-shallow --no-bare --no-mirror --no-local --no-shared --no-recurse-submodules --no-recursive --no-jobs --no-template --no-reference --no-reference-if-able --no-dissociate --no-origin --no-branch --no-upload-pack --no-depth --no-shallow-since --no-shallow-exclude --no-single-branch --no-shallow-submodules --no-separate-git-dir --no-config --no-server-option --no-ipv4 --no-ipv6 --no-filter --no-also-filter-submodules --no-remote-submodules --no-sparse"
342 __gitcomp_builtin_column_default=" --command= --mode --raw-mode= --width= --indent= --nl= --padding= --no-command -- --no-mode --no-raw-mode --no-width --no-indent --no-nl --no-padding"
343 __gitcomp_builtin_commit_default=" --quiet --verbose --file= --author= --date= --message= --reedit-message= --reuse-message= --fixup= --squash= --reset-author --trailer= --signoff --template= --edit --cleanup= --status --gpg-sign --all --include --interactive --patch --only --no-verify --dry-run --short --branch --ahead-behind --porcelain --long --null --amend --no-post-rewrite --untracked-files --pathspec-from-file= --pathspec-file-nul --verify --post-rewrite -- --no-quiet --no-verbose --no-file --no-author --no-date --no-message --no-reedit-message --no-reuse-message --no-fixup --no-squash --no-reset-author --no-signoff --no-template --no-edit --no-cleanup --no-status --no-gpg-sign --no-all --no-include --no-interactive --no-patch --no-only --no-dry-run --no-short --no-branch --no-ahead-behind --no-porcelain --no-long --no-null --no-amend --no-untracked-files --no-pathspec-from-file --no-pathspec-file-nul"
344 __gitcomp_builtin_commit_graph_default=" --object-dir= --no-object-dir"
345 __gitcomp_builtin_config_default=" --global --system --local --worktree --file= --blob= --get --get-all --get-regexp --get-urlmatch --replace-all --add --unset --unset-all --rename-section --remove-section --list --fixed-value --edit --get-color --get-colorbool --type= --bool --int --bool-or-int --bool-or-str --path --expiry-date --null --name-only --includes --show-origin --show-scope --default= --no-global -- --no-system --no-local --no-worktree --no-file --no-blob --no-get --no-get-all --no-get-regexp --no-get-urlmatch --no-replace-all --no-add --no-unset --no-unset-all --no-rename-section --no-remove-section --no-list --no-fixed-value --no-edit --no-get-color --no-get-colorbool --no-type --no-null --no-name-only --no-includes --no-show-origin --no-show-scope --no-default"
346 __gitcomp_builtin_count_objects_default=" --verbose --human-readable --no-verbose -- --no-human-readable"
347 __gitcomp_builtin_credential_cache_default=" --timeout= --socket= --no-timeout -- --no-socket"
348 __gitcomp_builtin_credential_cache__daemon_default=" --debug --no-debug"
349 __gitcomp_builtin_credential_store_default=" --file= --no-file"
350 __gitcomp_builtin_describe_default=" --contains --debug --all --tags --long --first-parent --abbrev --exact-match --candidates= --match= --exclude= --always --dirty --broken --no-contains -- --no-debug --no-all --no-tags --no-long --no-first-parent --no-abbrev --no-exact-match --no-candidates --no-match --no-exclude --no-always --no-dirty --no-broken"
351 __gitcomp_builtin_difftool_default=" --gui --dir-diff --no-prompt --symlinks --tool= --tool-help --trust-exit-code --extcmd= --no-index --index -- --no-gui --no-dir-diff --no-symlinks --no-tool --no-tool-help --no-trust-exit-code --no-extcmd"
352 __gitcomp_builtin_env__helper_default=" --type= --default= --exit-code --no-default -- --no-exit-code"
353 __gitcomp_builtin_fast_export_default=" --progress= --signed-tags= --tag-of-filtered-object= --reencode= --export-marks= --import-marks= --import-marks-if-exists= --fake-missing-tagger --full-tree --use-done-feature --no-data --refspec= --anonymize --anonymize-map= --reference-excluded-parents --show-original-ids --mark-tags --data -- --no-progress --no-signed-tags --no-tag-of-filtered-object --no-reencode --no-export-marks --no-import-marks --no-import-marks-if-exists --no-fake-missing-tagger --no-full-tree --no-use-done-feature --no-refspec --no-anonymize --no-reference-excluded-parents --no-show-original-ids --no-mark-tags"
354 __gitcomp_builtin_fetch_default=" --verbose --quiet --all --set-upstream --append --atomic --upload-pack= --force --multiple --tags --jobs= --prefetch --prune --prune-tags --recurse-submodules --dry-run --write-fetch-head --keep --update-head-ok --progress --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --refetch --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --negotiate-only --filter= --auto-maintenance --auto-gc --show-forced-updates --write-commit-graph --stdin --no-verbose -- --no-quiet --no-all --no-set-upstream --no-append --no-atomic --no-upload-pack --no-force --no-multiple --no-tags --no-jobs --no-prefetch --no-prune --no-prune-tags --no-recurse-submodules --no-dry-run --no-write-fetch-head --no-keep --no-update-head-ok --no-progress --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-negotiate-only --no-filter --no-auto-maintenance --no-auto-gc --no-show-forced-updates --no-write-commit-graph --no-stdin"
355 __gitcomp_builtin_fmt_merge_msg_default=" --log --message= --into-name= --file= --no-log -- --no-message --no-into-name --no-file"
356 __gitcomp_builtin_for_each_ref_default=" --shell --perl --python --tcl --count= --format= --color --sort= --points-at= --merged --no-merged --contains --no-contains --ignore-case -- --no-shell --no-perl --no-python --no-tcl --no-count --no-format --no-color --no-sort --no-points-at --no-ignore-case"
357 __gitcomp_builtin_for_each_repo_default=" --config= --no-config"
358 __gitcomp_builtin_format_patch_default=" --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --to= --cc= --from --in-reply-to= --attach --inline --thread --signature= --base= --signature-file= --quiet --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-numbered --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-to --no-cc --no-from --no-in-reply-to --no-attach --no-thread --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor"
359 __gitcomp_builtin_fsck_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects"
360 __gitcomp_builtin_fsck_objects_default=" --verbose --unreachable --dangling --tags --root --cache --reflogs --full --connectivity-only --strict --lost-found --progress --name-objects --no-verbose -- --no-unreachable --no-dangling --no-tags --no-root --no-cache --no-reflogs --no-full --no-connectivity-only --no-strict --no-lost-found --no-progress --no-name-objects"
361 __gitcomp_builtin_fsmonitor__daemon_default=""
362 __gitcomp_builtin_gc_default=" --quiet --prune --aggressive --keep-largest-pack --no-quiet -- --no-prune --no-aggressive --no-keep-largest-pack"
363 __gitcomp_builtin_grep_default=" --cached --no-index --untracked --exclude-standard --recurse-submodules --invert-match --ignore-case --word-regexp --text --textconv --recursive --max-depth= --extended-regexp --basic-regexp --fixed-strings --perl-regexp --line-number --column --full-name --files-with-matches --name-only --files-without-match --only-matching --count --color --break --heading --context= --before-context= --after-context= --threads= --show-function --function-context --and --or --not --quiet --all-match --index -- --no-cached --no-untracked --no-exclude-standard --no-recurse-submodules --no-invert-match --no-ignore-case --no-word-regexp --no-text --no-textconv --no-recursive --no-extended-regexp --no-basic-regexp --no-fixed-strings --no-perl-regexp --no-line-number --no-column --no-full-name --no-files-with-matches --no-name-only --no-files-without-match --no-only-matching --no-count --no-color --no-break --no-heading --no-context --no-before-context --no-after-context --no-threads --no-show-function --no-function-context --no-or --no-quiet --no-all-match"
364 __gitcomp_builtin_hash_object_default=" --stdin --stdin-paths --no-filters --literally --path= --filters -- --no-stdin --no-stdin-paths --no-literally --no-path"
365 __gitcomp_builtin_help_default=" --all --external-commands --aliases --man --web --info --verbose --guides --config --no-external-commands -- --no-aliases --no-man --no-web --no-info --no-verbose"
366 __gitcomp_builtin_hook_default=""
367 __gitcomp_builtin_init_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format"
368 __gitcomp_builtin_init_db_default=" --template= --bare --shared --quiet --separate-git-dir= --initial-branch= --object-format= --no-template -- --no-bare --no-quiet --no-separate-git-dir --no-initial-branch --no-object-format"
369 __gitcomp_builtin_interpret_trailers_default=" --in-place --trim-empty --where= --if-exists= --if-missing= --only-trailers --only-input --unfold --parse --no-divider --trailer= --divider -- --no-in-place --no-trim-empty --no-where --no-if-exists --no-if-missing --no-only-trailers --no-only-input --no-unfold --no-trailer"
370 __gitcomp_builtin_log_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate"
371 __gitcomp_builtin_ls_files_default=" --cached --deleted --modified --others --ignored --stage --killed --directory --eol --empty-directory --unmerged --resolve-undo --exclude= --exclude-from= --exclude-per-directory= --exclude-standard --full-name --recurse-submodules --error-unmatch --with-tree= --abbrev --debug --deduplicate --sparse --no-cached -- --no-deleted --no-modified --no-others --no-ignored --no-stage --no-killed --no-directory --no-eol --no-empty-directory --no-unmerged --no-resolve-undo --no-exclude-per-directory --no-recurse-submodules --no-error-unmatch --no-with-tree --no-abbrev --no-debug --no-deduplicate --no-sparse"
372 __gitcomp_builtin_ls_remote_default=" --quiet --upload-pack= --tags --heads --refs --get-url --sort= --symref --server-option= --no-quiet -- --no-upload-pack --no-tags --no-heads --no-refs --no-get-url --no-sort --no-symref --no-server-option"
373 __gitcomp_builtin_ls_tree_default=" --long --name-only --name-status --object-only --full-name --full-tree --format= --abbrev --no-full-name -- --no-full-tree --no-abbrev"
374 __gitcomp_builtin_merge_default=" --stat --summary --log --squash --commit --edit --cleanup= --ff --ff-only --rerere-autoupdate --verify-signatures --strategy= --strategy-option= --message= --file --into-name= --verbose --quiet --abort --quit --continue --allow-unrelated-histories --progress --gpg-sign --autostash --overwrite-ignore --signoff --no-verify --verify -- --no-stat --no-summary --no-log --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-rerere-autoupdate --no-verify-signatures --no-strategy --no-strategy-option --no-message --no-into-name --no-verbose --no-quiet --no-abort --no-quit --no-continue --no-allow-unrelated-histories --no-progress --no-gpg-sign --no-autostash --no-overwrite-ignore --no-signoff"
375 __gitcomp_builtin_merge_base_default=" --all --octopus --independent --is-ancestor --fork-point --no-all"
376 __gitcomp_builtin_merge_file_default=" --stdout --diff3 --zdiff3 --ours --theirs --union --marker-size= --quiet --no-stdout -- --no-diff3 --no-zdiff3 --no-ours --no-theirs --no-union --no-marker-size --no-quiet"
377 __gitcomp_builtin_mktree_default=" --missing --batch --no-missing -- --no-batch"
378 __gitcomp_builtin_multi_pack_index_default=" --object-dir= --no-object-dir"
379 __gitcomp_builtin_mv_default=" --verbose --dry-run --sparse --no-verbose -- --no-dry-run --no-sparse"
380 __gitcomp_builtin_name_rev_default=" --name-only --tags --refs= --exclude= --all --stdin --annotate-stdin --undefined --always --no-name-only -- --no-tags --no-refs --no-exclude --no-all --no-stdin --no-annotate-stdin --no-undefined --no-always"
381 __gitcomp_builtin_notes_default=" --ref= --no-ref"
382 __gitcomp_builtin_pack_objects_default=" --quiet --progress --all-progress --all-progress-implied --index-version= --max-pack-size= --local --incremental --window= --window-memory= --depth= --reuse-delta --reuse-object --delta-base-offset --threads= --non-empty --revs --unpacked --all --reflog --indexed-objects --stdin-packs --stdout --include-tag --keep-unreachable --pack-loose-unreachable --unpack-unreachable --sparse --thin --shallow --honor-pack-keep --keep-pack= --compression= --keep-true-parents --use-bitmap-index --write-bitmap-index --filter= --missing= --exclude-promisor-objects --delta-islands --uri-protocol= --no-quiet -- --no-progress --no-all-progress --no-all-progress-implied --no-local --no-incremental --no-window --no-depth --no-reuse-delta --no-reuse-object --no-delta-base-offset --no-threads --no-non-empty --no-revs --no-stdin-packs --no-stdout --no-include-tag --no-keep-unreachable --no-pack-loose-unreachable --no-unpack-unreachable --no-sparse --no-thin --no-shallow --no-honor-pack-keep --no-keep-pack --no-compression --no-keep-true-parents --no-use-bitmap-index --no-write-bitmap-index --no-filter --no-exclude-promisor-objects --no-delta-islands --no-uri-protocol"
383 __gitcomp_builtin_pack_refs_default=" --all --prune --no-all -- --no-prune"
384 __gitcomp_builtin_pickaxe_default=" --incremental --root --show-stats --progress --score-debug --show-name --show-number --porcelain --line-porcelain --show-email --ignore-rev= --ignore-revs-file= --color-lines --color-by-age --minimal --contents= --abbrev --no-incremental -- --no-root --no-show-stats --no-progress --no-score-debug --no-show-name --no-show-number --no-porcelain --no-line-porcelain --no-show-email --no-ignore-rev --no-ignore-revs-file --no-color-lines --no-color-by-age --no-minimal --no-contents --no-abbrev"
385 __gitcomp_builtin_prune_default=" --dry-run --verbose --progress --expire= --exclude-promisor-objects --no-dry-run -- --no-verbose --no-progress --no-expire --no-exclude-promisor-objects"
386 __gitcomp_builtin_prune_packed_default=" --dry-run --quiet --no-dry-run -- --no-quiet"
387 __gitcomp_builtin_pull_default=" --verbose --quiet --progress --recurse-submodules --rebase --stat --log --signoff --squash --commit --edit --cleanup= --ff --ff-only --verify --verify-signatures --autostash --strategy= --strategy-option= --gpg-sign --allow-unrelated-histories --all --append --upload-pack= --force --tags --prune --jobs --dry-run --keep --depth= --shallow-since= --shallow-exclude= --deepen= --unshallow --update-shallow --refmap= --server-option= --ipv4 --ipv6 --negotiation-tip= --show-forced-updates --set-upstream --no-verbose -- --no-quiet --no-progress --no-recurse-submodules --no-rebase --no-stat --no-log --no-signoff --no-squash --no-commit --no-edit --no-cleanup --no-ff --no-verify --no-verify-signatures --no-autostash --no-strategy --no-strategy-option --no-gpg-sign --no-allow-unrelated-histories --no-all --no-append --no-upload-pack --no-force --no-tags --no-prune --no-jobs --no-dry-run --no-keep --no-depth --no-shallow-since --no-shallow-exclude --no-deepen --no-update-shallow --no-server-option --no-ipv4 --no-ipv6 --no-negotiation-tip --no-show-forced-updates --no-set-upstream"
388 __gitcomp_builtin_push_default=" --verbose --quiet --repo= --all --mirror --delete --tags --dry-run --porcelain --force --force-with-lease --force-if-includes --recurse-submodules= --receive-pack= --exec= --set-upstream --progress --prune --no-verify --follow-tags --signed --atomic --push-option= --ipv4 --ipv6 --verify -- --no-verbose --no-quiet --no-repo --no-all --no-mirror --no-delete --no-tags --no-dry-run --no-porcelain --no-force --no-force-with-lease --no-force-if-includes --no-recurse-submodules --no-receive-pack --no-exec --no-set-upstream --no-progress --no-prune --no-follow-tags --no-signed --no-atomic --no-push-option --no-ipv4 --no-ipv6"
389 __gitcomp_builtin_range_diff_default=" --creation-factor= --no-dual-color --notes --left-only --right-only --patch --no-patch --unified --function-context --raw --patch-with-raw --patch-with-stat --numstat --shortstat --dirstat --cumulative --dirstat-by-file --check --summary --name-only --name-status --stat --stat-width= --stat-name-width= --stat-graph-width= --stat-count= --compact-summary --binary --full-index --color --ws-error-highlight= --abbrev --src-prefix= --dst-prefix= --line-prefix= --no-prefix --inter-hunk-context= --output-indicator-new= --output-indicator-old= --output-indicator-context= --break-rewrites --find-renames --irreversible-delete --find-copies --find-copies-harder --no-renames --rename-empty --follow --minimal --ignore-all-space --ignore-space-change --ignore-space-at-eol --ignore-cr-at-eol --ignore-blank-lines --ignore-matching-lines= --indent-heuristic --patience --histogram --diff-algorithm= --anchored= --word-diff --word-diff-regex= --color-words --color-moved --color-moved-ws= --relative --text --exit-code --quiet --ext-diff --textconv --ignore-submodules --submodule --ita-invisible-in-index --ita-visible-in-index --pickaxe-all --pickaxe-regex --rotate-to= --skip-to= --find-object= --diff-filter= --output= --dual-color -- --no-creation-factor --no-notes --no-left-only --no-right-only --no-function-context --no-compact-summary --no-full-index --no-color --no-abbrev --no-find-copies-harder --no-rename-empty --no-follow --no-minimal --no-ignore-matching-lines --no-indent-heuristic --no-color-moved --no-color-moved-ws --no-relative --no-text --no-exit-code --no-quiet --no-ext-diff --no-textconv"
390 __gitcomp_builtin_read_tree_default=" --index-output= --empty --verbose --trivial --aggressive --reset --prefix= --exclude-per-directory= --dry-run --no-sparse-checkout --debug-unpack --recurse-submodules --quiet --sparse-checkout -- --no-empty --no-verbose --no-trivial --no-aggressive --no-reset --no-dry-run --no-debug-unpack --no-recurse-submodules --no-quiet"
391 __gitcomp_builtin_rebase_default=" --onto= --keep-base --no-verify --quiet --verbose --no-stat --signoff --committer-date-is-author-date --reset-author-date --ignore-whitespace --whitespace= --force-rebase --no-ff --continue --skip --abort --quit --edit-todo --show-current-patch --apply --merge --interactive --rerere-autoupdate --empty= --autosquash --gpg-sign --autostash --exec= --rebase-merges --fork-point --strategy= --strategy-option= --root --reschedule-failed-exec --reapply-cherry-picks --verify --stat --ff -- --no-onto --no-keep-base --no-quiet --no-verbose --no-signoff --no-committer-date-is-author-date --no-reset-author-date --no-ignore-whitespace --no-whitespace --no-force-rebase --no-rerere-autoupdate --no-autosquash --no-gpg-sign --no-autostash --no-exec --no-rebase-merges --no-fork-point --no-strategy --no-strategy-option --no-root --no-reschedule-failed-exec --no-reapply-cherry-picks"
392 __gitcomp_builtin_receive_pack_default=" --quiet --no-quiet"
393 __gitcomp_builtin_reflog_default=""
394 __gitcomp_builtin_remote_default=" --verbose --no-verbose"
395 __gitcomp_builtin_repack_default=" --quiet --local --write-bitmap-index --delta-islands --unpack-unreachable= --keep-unreachable --window= --window-memory= --depth= --threads= --max-pack-size= --pack-kept-objects --keep-pack= --geometric= --write-midx --no-quiet -- --no-local --no-write-bitmap-index --no-delta-islands --no-unpack-unreachable --no-keep-unreachable --no-window --no-window-memory --no-depth --no-threads --no-max-pack-size --no-pack-kept-objects --no-keep-pack --no-geometric --no-write-midx"
396 __gitcomp_builtin_replace_default=" --list --delete --edit --graft --convert-graft-file --raw --format= --no-raw -- --no-format"
397 __gitcomp_builtin_rerere_default=" --rerere-autoupdate --no-rerere-autoupdate"
398 __gitcomp_builtin_reset_default=" --quiet --no-refresh --mixed --soft --hard --merge --keep --recurse-submodules --patch --intent-to-add --pathspec-from-file= --pathspec-file-nul --refresh -- --no-quiet --no-mixed --no-soft --no-hard --no-merge --no-keep --no-recurse-submodules --no-patch --no-intent-to-add --no-pathspec-from-file --no-pathspec-file-nul"
399 __gitcomp_builtin_restore_default=" --source= --staged --worktree --ignore-unmerged --overlay --quiet --recurse-submodules --progress --merge --conflict= --ours --theirs --patch --ignore-skip-worktree-bits --pathspec-from-file= --pathspec-file-nul --no-source -- --no-staged --no-worktree --no-ignore-unmerged --no-overlay --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-patch --no-ignore-skip-worktree-bits --no-pathspec-from-file --no-pathspec-file-nul"
400 __gitcomp_builtin_revert_default=" --quit --continue --abort --skip --cleanup= --no-commit --edit --signoff --mainline= --rerere-autoupdate --strategy= --strategy-option= --gpg-sign --commit -- --no-cleanup --no-edit --no-signoff --no-mainline --no-rerere-autoupdate --no-strategy --no-strategy-option --no-gpg-sign"
401 __gitcomp_builtin_rm_default=" --dry-run --quiet --cached --ignore-unmatch --sparse --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-quiet --no-cached --no-ignore-unmatch --no-sparse --no-pathspec-from-file --no-pathspec-file-nul"
402 __gitcomp_builtin_send_pack_default=" --verbose --quiet --receive-pack= --exec= --remote= --all --dry-run --mirror --force --signed --push-option= --progress --thin --atomic --stateless-rpc --stdin --helper-status --force-with-lease --force-if-includes --no-verbose -- --no-quiet --no-receive-pack --no-exec --no-remote --no-all --no-dry-run --no-mirror --no-force --no-signed --no-push-option --no-progress --no-thin --no-atomic --no-stateless-rpc --no-stdin --no-helper-status --no-force-with-lease --no-force-if-includes"
403 __gitcomp_builtin_shortlog_default=" --committer --numbered --summary --email --group= --no-committer -- --no-numbered --no-summary --no-email --no-group"
404 __gitcomp_builtin_show_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate"
405 __gitcomp_builtin_show_branch_default=" --all --remotes --color --more --list --no-name --current --sha1-name --merge-base --independent --topo-order --topics --sparse --date-order --reflog --name -- --no-all --no-remotes --no-color --no-more --no-list --no-current --no-sha1-name --no-merge-base --no-independent --no-topo-order --no-topics --no-sparse --no-date-order"
406 __gitcomp_builtin_show_index_default=" --object-format= --no-object-format"
407 __gitcomp_builtin_show_ref_default=" --tags --heads --verify --head --dereference --hash --abbrev --quiet --exclude-existing --no-tags -- --no-heads --no-verify --no-head --no-dereference --no-hash --no-abbrev --no-quiet"
408 __gitcomp_builtin_sparse_checkout_default=""
409 __gitcomp_builtin_stage_default=" --dry-run --verbose --interactive --patch --edit --force --update --renormalize --intent-to-add --all --ignore-removal --refresh --ignore-errors --ignore-missing --sparse --chmod= --pathspec-from-file= --pathspec-file-nul --no-dry-run -- --no-verbose --no-interactive --no-patch --no-edit --no-force --no-update --no-renormalize --no-intent-to-add --no-all --no-ignore-removal --no-refresh --no-ignore-errors --no-ignore-missing --no-sparse --no-chmod --no-pathspec-from-file --no-pathspec-file-nul"
410 __gitcomp_builtin_stash_default=""
411 __gitcomp_builtin_status_default=" --verbose --short --branch --show-stash --ahead-behind --porcelain --long --null --untracked-files --ignored --ignore-submodules --column --no-renames --find-renames --renames -- --no-verbose --no-short --no-branch --no-show-stash --no-ahead-behind --no-porcelain --no-long --no-null --no-untracked-files --no-ignored --no-ignore-submodules --no-column"
412 __gitcomp_builtin_stripspace_default=" --strip-comments --comment-lines"
413 __gitcomp_builtin_switch_default=" --create= --force-create= --guess --discard-changes --quiet --recurse-submodules --progress --merge --conflict= --detach --track --orphan= --ignore-other-worktrees --no-create -- --no-force-create --no-guess --no-discard-changes --no-quiet --no-recurse-submodules --no-progress --no-merge --no-conflict --no-detach --no-track --no-orphan --no-ignore-other-worktrees"
414 __gitcomp_builtin_symbolic_ref_default=" --quiet --delete --short --no-quiet -- --no-delete --no-short"
415 __gitcomp_builtin_tag_default=" --list --delete --verify --annotate --message= --file= --edit --sign --cleanup= --local-user= --force --create-reflog --column --contains --no-contains --merged --no-merged --sort= --points-at --format= --color --ignore-case -- --no-annotate --no-file --no-edit --no-sign --no-cleanup --no-local-user --no-force --no-create-reflog --no-column --no-sort --no-points-at --no-format --no-color --no-ignore-case"
416 __gitcomp_builtin_update_index_default=" --ignore-submodules --add --replace --remove --unmerged --refresh --really-refresh --cacheinfo --chmod= --assume-unchanged --no-assume-unchanged --skip-worktree --no-skip-worktree --ignore-skip-worktree-entries --info-only --force-remove --stdin --index-info --unresolve --again --ignore-missing --verbose --clear-resolve-undo --index-version= --split-index --untracked-cache --test-untracked-cache --force-untracked-cache --force-write-index --fsmonitor --fsmonitor-valid --no-fsmonitor-valid -- --no-ignore-submodules --no-add --no-replace --no-remove --no-unmerged --no-ignore-skip-worktree-entries --no-info-only --no-force-remove --no-ignore-missing --no-verbose --no-index-version --no-split-index --no-untracked-cache --no-test-untracked-cache --no-force-untracked-cache --no-force-write-index --no-fsmonitor"
417 __gitcomp_builtin_update_ref_default=" --no-deref --stdin --create-reflog --deref -- --no-stdin --no-create-reflog"
418 __gitcomp_builtin_update_server_info_default=" --force --no-force"
419 __gitcomp_builtin_upload_pack_default=" --stateless-rpc --strict --timeout= --no-stateless-rpc -- --no-strict --no-timeout"
420 __gitcomp_builtin_verify_commit_default=" --verbose --raw --no-verbose -- --no-raw"
421 __gitcomp_builtin_verify_pack_default=" --verbose --stat-only --object-format= --no-verbose -- --no-stat-only --no-object-format"
422 __gitcomp_builtin_verify_tag_default=" --verbose --raw --format= --no-verbose -- --no-raw --no-format"
423 __gitcomp_builtin_version_default=" --build-options --no-build-options"
424 __gitcomp_builtin_whatchanged_default=" --quiet --source --use-mailmap --decorate-refs= --decorate-refs-exclude= --decorate --no-quiet -- --no-source --no-use-mailmap --no-mailmap --no-decorate-refs --no-decorate-refs-exclude --no-decorate"
425 __gitcomp_builtin_write_tree_default=" --missing-ok --prefix= --no-missing-ok -- --no-prefix"
426 __gitcomp_builtin_send_email_default="--sender= --from= --smtp-auth= --8bit-encoding= --no-format-patch --no-bcc --no-suppress-from --no-annotate --relogin-delay= --no-cc --no-signed-off-cc --no-signed-off-by-cc --no-chain-reply-to --smtp-debug= --smtp-domain= --chain-reply-to --dry-run --compose --bcc= --smtp-user= --thread --cc-cover --identity= --to= --reply-to= --no-cc-cover --suppress-cc= --to-cmd= --smtp-server= --smtp-ssl-cert-path= --no-thread --smtp-server-option= --quiet --batch-size= --envelope-sender= --smtp-ssl --no-to --validate --format-patch --suppress-from --cc= --compose-encoding= --to-cover --in-reply-to= --annotate --smtp-encryption= --cc-cmd= --smtp-server-port= --smtp-pass= --signed-off-cc --signed-off-by-cc --no-xmailer --subject= --no-to-cover --confirm= --transfer-encoding= --no-smtp-auth --sendmail-cmd= --no-validate --no-identity --dump-aliases --xmailer --force --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --from --attach --inline --signature= --base= --signature-file= --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-from --no-in-reply-to --no-attach --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor"
428 __gitcomp_builtin_get_default ()
430 eval "test -n \"\$${1}_default\" && echo \"\$${1}_default\""
433 # This function is equivalent to
435 # __gitcomp_opts "$(git xxx --git-completion-helper) ..."
437 # except that the output is cached. Accept 1-3 arguments:
438 # 1: the git command to execute, this is also the cache key
439 # 2: extra options to be added on top (e.g. negative forms)
440 # 3: options to be excluded
443 # spaces must be replaced with underscore for multi-word
444 # commands, e.g. "git remote add" becomes remote_add.
449 local var=__gitcomp_builtin_"${cmd//-/_}"
451 eval "options=\${$var-}"
453 if [ -z "$options" ]; then
454 local completion_helper
455 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
456 completion_helper="--git-completion-helper-all"
458 completion_helper="--git-completion-helper"
460 completion="$(__git ${cmd/_/ } $completion_helper ||
461 __gitcomp_builtin_get_default $var)" || return
462 # leading and trailing spaces are significant to make
463 # option removal work correctly.
464 options=" $incl $completion "
467 options="${options/ $i / }"
469 eval "$var=\"$options\""
472 __gitcomp_opts "$options"
475 # Execute 'git ls-files', unless the --committable option is specified, in
476 # which case it runs 'git diff-index' to find out the files that can be
477 # committed. It return paths relative to the directory specified in the first
478 # argument, and using the options specified in the second argument.
479 __git_ls_files_helper ()
481 if [ "$2" = "--committable" ]; then
482 __git -C "$1" -c core.quotePath=false diff-index \
483 --name-only --relative HEAD -- "${3//\\/\\\\}*"
485 # NOTE: $2 is not quoted in order to support multiple options
486 __git -C "$1" -c core.quotePath=false ls-files \
487 --exclude-standard $2 -- "${3//\\/\\\\}*"
492 # __git_index_files accepts 1 or 2 arguments:
493 # 1: Options to pass to ls-files (required).
494 # 2: A directory path (optional).
495 # If provided, only files within the specified directory are listed.
496 # Sub directories are never recursed. Path must have a trailing
498 # 3: List only paths matching this path component (optional).
501 local root="$2" match="$3"
503 __git_ls_files_helper "$root" "$1" "${match:-?}" |
504 awk -F / -v pfx="${2//\\/\\\\}" '{
509 if (substr(p, 1, 1) != "\"") {
510 # No special characters, easy!
515 # The path is quoted.
520 # Even when a directory name itself does not contain
521 # any special characters, it will still be quoted if
522 # any of its (stripped) trailing path components do.
523 # Because of this we may have seen the same directory
524 # both quoted and unquoted.
526 # We have seen the same directory unquoted,
533 function dequote(p, bs_idx, out, esc, esc_idx, dec) {
534 # Skip opening double quote.
537 # Interpret backslash escape sequences.
538 while ((bs_idx = index(p, "\\")) != 0) {
539 out = out substr(p, 1, bs_idx - 1)
540 esc = substr(p, bs_idx + 1, 1)
541 p = substr(p, bs_idx + 2)
543 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) {
544 # C-style one-character escape sequence.
545 out = out substr("\a\b\t\v\f\r\"\\",
547 } else if (esc == "n") {
548 # Uh-oh, a newline character.
549 # We cannot reliably put a pathname
550 # containing a newline into COMPREPLY,
551 # and the newline would create a mess.
555 # Must be a \nnn octal value, then.
557 substr(p, 1, 1) * 8 + \
559 out = out sprintf("%c", dec)
563 # Drop closing double quote, if there is one.
564 # (There is not any if this is a directory, as it was
565 # already stripped with the trailing path components.)
566 if (substr(p, length(p), 1) == "\"")
567 out = out substr(p, 1, length(p) - 1)
575 # __git_complete_index_file requires 1 argument:
576 # 1: the options to pass to ls-file
578 # The exception is --committable, which finds the files appropriate commit.
579 __git_complete_index_file ()
581 local dequoted_word pfx="" cur_
585 case "$dequoted_word" in
587 pfx="${dequoted_word%/*}/"
588 cur_="${dequoted_word##*/}"
591 cur_="$dequoted_word"
594 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
597 # Lists branches from the local repository.
598 # 1: A prefix to be added to each listed branch (optional).
599 # 2: List only branches matching this word (optional; list all branches if
601 # 3: A suffix to be appended to each listed branch (optional).
604 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
606 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
607 "refs/heads/$cur_*" "refs/heads/$cur_*/**"
610 # Lists branches from remote repositories.
611 # 1: A prefix to be added to each listed branch (optional).
612 # 2: List only branches matching this word (optional; list all branches if
614 # 3: A suffix to be appended to each listed branch (optional).
615 __git_remote_heads ()
617 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
619 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
620 "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
623 # Lists tags from the local repository.
624 # Accepts the same positional parameters as __git_heads() above.
627 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
629 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
630 "refs/tags/$cur_*" "refs/tags/$cur_*/**"
633 # List unique branches from refs/remotes used for 'git checkout' and 'git
634 # switch' tracking DWIMery.
635 # 1: A prefix to be added to each listed branch (optional)
636 # 2: List only branches matching this word (optional; list all branches if
638 # 3: A suffix to be appended to each listed branch (optional).
639 __git_dwim_remote_heads ()
641 local pfx="${1-}" cur_="${2-}" sfx="${3-}"
642 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
644 # employ the heuristic used by git checkout and git switch
645 # Try to find a remote branch that cur_es the completion word
646 # but only output if the branch name is unique
647 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
648 --sort="refname:strip=3" \
649 "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
653 # Lists refs from the local (by default) or from a remote repository.
654 # It accepts 0, 1 or 2 arguments:
655 # 1: The remote to list refs from (optional; ignored, if set but empty).
656 # Can be the name of a configured remote, a path, or a URL.
657 # 2: In addition to local refs, list unique branches from refs/remotes/ for
658 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty).
659 # 3: A prefix to be added to each listed ref (optional).
660 # 4: List only refs matching this word (optional; list all refs if unset or
662 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
665 # Use __git_complete_refs() instead.
668 local i hash dir track="${2-}"
669 local list_refs_from=path remote="${1-}"
671 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
673 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
676 dir="$__git_repo_path"
678 if [ -z "$remote" ]; then
679 if [ -z "$dir" ]; then
683 if __git_is_configured_remote "$remote"; then
684 # configured remote takes precedence over a
685 # local directory with the same name
686 list_refs_from=remote
687 elif [ -d "$remote/.git" ]; then
689 elif [ -d "$remote" ]; then
696 if [ "$list_refs_from" = path ]; then
697 if [[ "$cur_" == ^* ]]; then
706 refs=("$match*" "$match*/**")
710 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
713 if [ -e "$dir/$i" ]; then
719 format="refname:strip=2"
720 refs=("refs/tags/$match*" "refs/tags/$match*/**"
721 "refs/heads/$match*" "refs/heads/$match*/**"
722 "refs/remotes/$match*" "refs/remotes/$match*/**")
725 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
727 if [ -n "$track" ]; then
728 __git_dwim_remote_heads "$pfx" "$match" "$sfx"
734 __git ls-remote "$remote" "$match*" | \
735 while read -r hash i; do
738 *) echo "$pfx$i$sfx" ;;
743 if [ "$list_refs_from" = remote ]; then
745 $match*) echo "${pfx}HEAD$sfx" ;;
747 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
748 "refs/remotes/$remote/$match*" \
749 "refs/remotes/$remote/$match*/**"
753 $match*) query_symref="HEAD" ;;
755 __git ls-remote "$remote" $query_symref \
756 "refs/tags/$match*" "refs/heads/$match*" \
757 "refs/remotes/$match*" |
758 while read -r hash i; do
761 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
762 *) echo "$pfx$i$sfx" ;; # symbolic refs
770 # Completes refs, short and long, local and remote, symbolic and pseudo.
772 # Usage: __git_complete_refs [<option>]...
773 # --remote=<remote>: The remote to list refs from, can be the name of a
774 # configured remote, a path, or a URL.
775 # --dwim: List unique remote branches for 'git switch's tracking DWIMery.
776 # --pfx=<prefix>: A prefix to be added to each ref.
777 # --cur=<word>: The current ref to be completed. Defaults to the current
778 # word to be completed.
779 # --sfx=<suffix>: A suffix to be appended to each ref instead of the default
781 # --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
782 # complete all refs, 'heads' to complete only branches, or
783 # 'remote-heads' to complete only remote branches. Note that
784 # --remote is only compatible with --mode=refs.
785 __git_complete_refs ()
787 local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
789 while test $# != 0; do
791 --remote=*) remote="${1##--remote=}" ;;
792 --dwim) dwim="yes" ;;
793 # --track is an old spelling of --dwim
794 --track) dwim="yes" ;;
795 --pfx=*) pfx="${1##--pfx=}" ;;
796 --cur=*) cur_="${1##--cur=}" ;;
797 --sfx=*) sfx="${1##--sfx=}" ;;
798 --mode=*) mode="${1##--mode=}" ;;
804 # complete references based on the specified mode
807 __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
809 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
811 __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
816 # Append DWIM remote branch names if requested
817 if [ "$dwim" = "yes" ]; then
818 __gitcomp_direct "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
822 # __git_refs2 requires 1 argument (to pass to __git_refs)
823 # Deprecated: use __git_complete_fetch_refspecs() instead.
827 for i in $(__git_refs "$1"); do
832 # Completes refspecs for fetching from a remote repository.
833 # 1: The remote repository.
834 # 2: A prefix to be added to each listed refspec (optional).
835 # 3: The ref to be completed as a refspec instead of the current word to be
836 # completed (optional)
837 # 4: A suffix to be appended to each listed refspec instead of the default
839 __git_complete_fetch_refspecs ()
841 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
844 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
850 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
851 __git_refs_remotes ()
854 __git ls-remote "$1" 'refs/heads/*' | \
855 while read -r hash i; do
856 echo "$i:refs/remotes/$1/${i#refs/heads/}"
863 test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
867 # Returns true if $1 matches the name of a configured remote, false otherwise.
868 __git_is_configured_remote ()
871 for remote in $(__git_remotes); do
872 if [ "$remote" = "$1" ]; then
879 __git_list_merge_strategies ()
881 LANG=C LC_ALL=C git merge -s help 2>&1 |
882 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
891 __git_merge_strategies_default='octopus ours recursive resolve subtree'
892 __git_merge_strategies=
893 # 'git merge -s help' (and thus detection of the merge strategy
894 # list) fails, unfortunately, if run outside of any git working
895 # tree. __git_merge_strategies is set to the empty string in
896 # that case, and the detection will be repeated the next time it
898 __git_compute_merge_strategies ()
900 test -n "$__git_merge_strategies" ||
901 { __git_merge_strategies=$(__git_list_merge_strategies);
902 __git_merge_strategies="${__git_merge_strategies:-__git_merge_strategies_default}"; }
905 __git_merge_strategy_options="ours theirs subtree subtree= patience
906 histogram diff-algorithm= ignore-space-change ignore-all-space
907 ignore-space-at-eol renormalize no-renormalize no-renames
908 find-renames find-renames= rename-threshold="
910 __git_complete_revlist_file ()
912 local dequoted_word pfx ls ref cur_="$cur"
921 __git_dequote "$cur_"
923 case "$dequoted_word" in
925 pfx="${dequoted_word%/*}"
926 cur_="${dequoted_word##*/}"
931 cur_="$dequoted_word"
936 case "$COMP_WORDBREAKS" in
938 *) pfx="$ref:$pfx" ;;
941 __gitcomp_file "$(__git ls-tree "$ls" \
947 pfx="${cur_%...*}..."
949 __git_complete_refs --pfx="$pfx" --cur="$cur_"
954 __git_complete_refs --pfx="$pfx" --cur="$cur_"
962 __git_complete_file ()
964 __git_complete_revlist_file
967 __git_complete_revlist ()
969 __git_complete_revlist_file
972 __git_complete_remote_or_refspec ()
974 local cur_="$cur" cmd="${words[__git_cmd_idx]}"
975 local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
976 if [ "$cmd" = "remote" ]; then
979 while [ $c -lt $cword ]; do
982 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
983 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
986 push) no_complete_refspec=1 ;;
993 --multiple) no_complete_refspec=1; break ;;
995 *) remote="$i"; break ;;
999 if [ -z "$remote" ]; then
1000 __gitcomp_nl "$(__git_remotes)"
1003 if [ $no_complete_refspec = 1 ]; then
1006 [ "$remote" = "." ] && remote=
1009 case "$COMP_WORDBREAKS" in
1011 *) pfx="${cur_%%:*}:" ;;
1023 if [ $lhs = 1 ]; then
1024 __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1026 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1030 if [ $lhs = 1 ]; then
1031 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1033 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1037 if [ $lhs = 1 ]; then
1038 __git_complete_refs --pfx="$pfx" --cur="$cur_"
1040 __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1046 __git_complete_strategy ()
1048 __git_compute_merge_strategies
1051 __gitcomp "$__git_merge_strategies"
1055 __gitcomp_opts "$__git_merge_strategy_options"
1061 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1064 --strategy-option=*)
1065 __gitcomp_opts "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1073 __git_compute_all_commands ()
1075 test -n "$__git_all_commands" ||
1076 __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1079 # Lists all set config variables starting with the given section prefix,
1080 # with the prefix removed.
1081 __git_get_config_variables ()
1083 local section="$1" i IFS=$'\n'
1084 for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1085 echo "${i#$section.}"
1089 __git_pretty_aliases ()
1091 __git_get_config_variables "pretty"
1094 # __git_aliased_command requires 1 argument
1095 __git_aliased_command ()
1097 local cur=$1 last list= word cmdline
1099 while [[ -n "$cur" ]]; do
1100 if [[ "$list" == *" $cur "* ]]; then
1105 cmdline=$(__git config --get "alias.$cur")
1110 for word in $cmdline; do
1116 \!*) : shell command alias ;;
1118 *=*) : setting env ;;
1119 git) : git itself ;;
1120 \(\)) : skip parens of shell function definition ;;
1121 {) : skip start of shell helper function ;;
1122 :) : skip null command ;;
1123 \'*) : skip opening quote after sh -c ;;
1132 if [[ "$cur" != "$1" ]]; then
1137 # Check whether one of the given words is present on the command line,
1138 # and print the first word found.
1140 # Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
1141 # --show-idx: Optionally show the index of the found word in the $words array.
1142 __git_find_on_cmdline ()
1144 local word c="$__git_cmd_idx" show_idx
1146 while test $# -gt 1; do
1148 --show-idx) show_idx=y ;;
1155 while [ $c -lt $cword ]; do
1156 for word in $wordlist; do
1157 if [ "$word" = "${words[c]}" ]; then
1158 if [ -n "${show_idx-}" ]; then
1170 # Similar to __git_find_on_cmdline, except that it loops backwards and thus
1171 # prints the *last* word found. Useful for finding which of two options that
1172 # supersede each other came last, such as "--guess" and "--no-guess".
1174 # Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
1175 # --show-idx: Optionally show the index of the found word in the $words array.
1176 __git_find_last_on_cmdline ()
1178 local word c=$cword show_idx
1180 while test $# -gt 1; do
1182 --show-idx) show_idx=y ;;
1189 while [ $c -gt "$__git_cmd_idx" ]; do
1191 for word in $wordlist; do
1192 if [ "$word" = "${words[c]}" ]; then
1193 if [ -n "$show_idx" ]; then
1204 # Echo the value of an option set on the command line or config
1206 # $1: short option name
1207 # $2: long option name including =
1208 # $3: list of possible values
1209 # $4: config string (optional)
1212 # result="$(__git_get_option_value "-d" "--do-something=" \
1213 # "yes no" "core.doSomething")"
1215 # result is then either empty (no option set) or "yes" or "no"
1217 # __git_get_option_value requires 3 arguments
1218 __git_get_option_value ()
1220 local c short_opt long_opt val
1221 local result= values config_key word
1229 while [ $c -ge 0 ]; do
1231 for val in $values; do
1232 if [ "$short_opt$val" = "$word" ] ||
1233 [ "$long_opt$val" = "$word" ]; then
1241 if [ -n "$config_key" ] && [ -z "$result" ]; then
1242 result="$(__git config "$config_key")"
1248 __git_has_doubledash ()
1251 while [ $c -lt $cword ]; do
1252 if [ "--" = "${words[c]}" ]; then
1260 # Try to count non option arguments passed on the command line for the
1261 # specified git command.
1262 # When options are used, it is necessary to use the special -- option to
1263 # tell the implementation were non option arguments begin.
1264 # XXX this can not be improved, since options can appear everywhere, as
1268 # __git_count_arguments requires 1 argument: the git command executed.
1269 __git_count_arguments ()
1273 # Skip "git" (first argument)
1274 for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1279 # Good; we can assume that the following are only non
1284 # Skip the specified git command and discard git
1297 __git_whitespacelist="nowarn warn error error-all fix"
1298 __git_patchformat="mbox stgit stgit-series hg mboxrd"
1299 __git_showcurrentpatch="diff raw"
1300 __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1301 __git_quoted_cr="nowarn warn strip"
1305 __git_find_repo_path
1306 if [ -d "$__git_repo_path"/rebase-apply ]; then
1307 __gitcomp_opts "$__git_am_inprogress_options"
1312 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1316 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1319 --show-current-patch=*)
1320 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1324 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1328 __gitcomp_builtin am "" \
1329 "$__git_am_inprogress_options"
1338 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1342 __gitcomp_builtin apply
1351 __gitcomp "+x -x" "" "${cur##--chmod=}"
1355 __gitcomp_builtin add
1359 local complete_opt="--others --modified --directory --no-empty-directory"
1360 if test -n "$(__git_find_on_cmdline "-u --update")"
1362 complete_opt="--modified"
1364 __git_complete_index_file "$complete_opt"
1371 __gitcomp_nl "$(git archive --list)" "" "${cur##--format=}"
1375 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1379 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1388 __git_has_doubledash && return
1390 local subcommands="start bad good skip reset visualize replay log run"
1391 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1392 if [ -z "$subcommand" ]; then
1393 __git_find_repo_path
1394 if [ -f "$__git_repo_path"/BISECT_START ]; then
1395 __gitcomp "$subcommands"
1397 __gitcomp "replay start"
1402 case "$subcommand" in
1403 bad|good|reset|skip|start)
1411 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1415 local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1417 while [ $c -lt $cword ]; do
1420 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1421 only_local_ref="y" ;;
1429 --set-upstream-to=*)
1430 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1433 __gitcomp_builtin branch
1436 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1437 __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1447 local cmd="${words[__git_cmd_idx+1]}"
1449 $((__git_cmd_idx+1)))
1450 __gitcomp "create list-heads verify unbundle"
1452 $((__git_cmd_idx+2)))
1453 # looking for a file
1458 __git_complete_revlist
1465 # Helper function to decide whether or not we should enable DWIM logic for
1466 # git-switch and git-checkout.
1468 # To decide between the following rules in decreasing priority order:
1469 # - the last provided of "--guess" or "--no-guess" explicitly enable or
1470 # disable completion of DWIM logic respectively.
1471 # - If checkout.guess is false, disable completion of DWIM logic.
1472 # - If the --no-track option is provided, take this as a hint to disable the
1473 # DWIM completion logic
1474 # - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
1475 # logic, as requested by the user.
1476 # - Enable DWIM logic otherwise.
1478 __git_checkout_default_dwim_mode ()
1480 local last_option dwim_opt="--dwim"
1482 if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1486 # --no-track disables DWIM, but with lower priority than
1487 # --guess/--no-guess/checkout.guess
1488 if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
1492 # checkout.guess = false disables DWIM, but with lower priority than
1493 # --guess/--no-guess
1494 if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
1498 # Find the last provided --guess or --no-guess
1499 last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
1500 case "$last_option" in
1514 __git_has_doubledash && return
1516 local dwim_opt="$(__git_checkout_default_dwim_mode)"
1520 # Complete local branches (and DWIM branch
1521 # remote branch names) for an option argument
1522 # specifying a new branch name. This is for
1523 # convenience, assuming new branches are
1524 # possibly based on pre-existing branch names.
1525 __git_complete_refs $dwim_opt --mode="heads"
1534 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1537 __gitcomp_builtin checkout
1540 # At this point, we've already handled special completion for
1541 # the arguments to -b/-B, and --orphan. There are 3 main
1542 # things left we can possibly complete:
1543 # 1) a start-point for -b/-B, -d/--detach, or --orphan
1544 # 2) a remote head, for --track
1545 # 3) an arbitrary reference, possibly including DWIM names
1548 if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
1549 __git_complete_refs --mode="refs"
1550 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
1551 __git_complete_refs --mode="remote-heads"
1553 __git_complete_refs $dwim_opt --mode="refs"
1559 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1561 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1565 __git_find_repo_path
1566 if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1567 __gitcomp_opts "$__git_cherry_pick_inprogress_options"
1571 __git_complete_strategy && return
1575 __gitcomp_builtin cherry-pick "" \
1576 "$__git_cherry_pick_inprogress_options"
1588 __gitcomp_builtin clean
1593 # XXX should we check for -x option ?
1594 __git_complete_index_file "--others --directory"
1601 __git_complete_config_variable_name_and_value
1607 __git_complete_config_variable_name_and_value \
1608 --cur="${cur##--config=}"
1612 __gitcomp_builtin clone
1618 __git_untracked_file_modes="all no normal"
1631 __gitcomp "default scissors strip verbatim whitespace
1632 " "" "${cur##--cleanup=}"
1635 --reuse-message=*|--reedit-message=*|\
1636 --fixup=*|--squash=*)
1637 __git_complete_refs --cur="${cur#*=}"
1640 --untracked-files=*)
1641 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1645 __gitcomp_builtin commit
1649 if __git rev-parse --verify --quiet HEAD >/dev/null; then
1650 __git_complete_index_file "--committable"
1652 # This is the first commit
1653 __git_complete_index_file "--cached"
1661 __gitcomp_builtin describe
1667 __git_diff_algorithms="myers minimal patience histogram"
1669 __git_diff_submodule_formats="diff log short"
1671 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1673 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1674 ignore-all-space allow-indentation-change"
1676 __git_diff_common_options="--stat --numstat --shortstat --summary
1677 --patch-with-stat --name-only --name-status --color
1678 --no-color --color-words --no-renames --check
1679 --color-moved --color-moved= --no-color-moved
1680 --color-moved-ws= --no-color-moved-ws
1681 --full-index --binary --abbrev --diff-filter=
1682 --find-copies-harder --ignore-cr-at-eol
1683 --text --ignore-space-at-eol --ignore-space-change
1684 --ignore-all-space --ignore-blank-lines --exit-code
1685 --quiet --ext-diff --no-ext-diff
1686 --no-prefix --src-prefix= --dst-prefix=
1687 --inter-hunk-context=
1688 --patience --histogram --minimal
1689 --raw --word-diff --word-diff-regex=
1690 --dirstat --dirstat= --dirstat-by-file
1691 --dirstat-by-file= --cumulative
1693 --submodule --submodule= --ignore-submodules
1694 --indent-heuristic --no-indent-heuristic
1695 --textconv --no-textconv
1700 __git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex
1701 --base --ours --theirs --no-index --relative --merge-base
1702 $__git_diff_common_options"
1706 __git_has_doubledash && return
1710 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1714 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1718 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1722 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1726 __gitcomp_opts "$__git_diff_difftool_options"
1730 __git_complete_revlist_file
1733 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1734 tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1735 bc codecompare smerge
1740 __git_has_doubledash && return
1744 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1748 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1752 __git_complete_revlist_file
1755 __git_fetch_recurse_submodules="yes on-demand no"
1760 --recurse-submodules=*)
1761 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1765 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1769 __gitcomp_builtin fetch
1773 __git_complete_remote_or_refspec
1776 __git_format_patch_extra_options="
1777 --full-index --not --all --no-prefix --src-prefix=
1778 --dst-prefix= --notes
1781 _git_format_patch ()
1785 __gitcomp "deep shallow" "" "${cur##--thread=}"
1788 --base=*|--interdiff=*|--range-diff=*)
1789 __git_complete_refs --cur="${cur#--*=}"
1793 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1797 __git_complete_revlist
1804 __gitcomp_builtin fsck
1815 # Lists matching symbol names from a tag (as in ctags) file.
1816 # 1: List symbol names matching this word.
1817 # 2: The tag file to list symbol names from.
1818 # 3: A prefix to be added to each listed symbol name (optional).
1819 # 4: A suffix to be appended to each listed symbol name (optional).
1820 __git_match_ctag () {
1821 awk -v pfx="${3-}" -v sfx="${4-}" "
1822 /^${1//\//\\/}/ { print pfx \$1 sfx }
1826 # Complete symbol names from a tag file.
1827 # Usage: __git_complete_symbol [<option>]...
1828 # --tags=<file>: The tag file to list symbol names from instead of the
1830 # --pfx=<prefix>: A prefix to be added to each symbol name.
1831 # --cur=<word>: The current symbol name to be completed. Defaults to
1832 # the current word to be completed.
1833 # --sfx=<suffix>: A suffix to be appended to each symbol name instead
1834 # of the default space.
1835 __git_complete_symbol () {
1836 local tags=tags pfx="" cur_="${cur-}" sfx=" "
1838 while test $# != 0; do
1840 --tags=*) tags="${1##--tags=}" ;;
1841 --pfx=*) pfx="${1##--pfx=}" ;;
1842 --cur=*) cur_="${1##--cur=}" ;;
1843 --sfx=*) sfx="${1##--sfx=}" ;;
1849 if test -r "$tags"; then
1850 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1856 __git_has_doubledash && return
1860 __gitcomp_builtin grep
1865 case "$cword,$prev" in
1866 $((__git_cmd_idx+1)),*|*,-*)
1867 __git_complete_symbol && return
1878 __gitcomp_builtin help
1882 if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1884 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1886 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1895 false true umask group all world everybody
1896 " "" "${cur##--shared=}"
1900 __gitcomp_builtin init
1910 __gitcomp_builtin ls-files
1915 # XXX ignore options like --modified and always suggest all cached
1917 __git_complete_index_file "--cached"
1924 __gitcomp_builtin ls-remote
1928 __gitcomp_nl "$(__git_remotes)"
1935 __gitcomp_builtin ls-tree
1943 # Options that go well for log, shortlog and gitk
1944 __git_log_common_options="
1946 --branches --tags --remotes
1947 --first-parent --merges --no-merges
1949 --max-age= --since= --after=
1950 --min-age= --until= --before=
1951 --min-parents= --max-parents=
1952 --no-min-parents --no-max-parents
1954 # Options that go well for log and gitk (not shortlog)
1955 __git_log_gitk_options="
1956 --dense --sparse --full-history
1957 --simplify-merges --simplify-by-decoration
1958 --left-right --notes --no-notes
1960 # Options that go well for log and shortlog (not gitk)
1961 __git_log_shortlog_options="
1962 --author= --committer= --grep=
1963 --all-match --invert-grep
1966 __git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
1967 __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
1971 __git_has_doubledash && return
1972 __git_find_repo_path
1975 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1978 case "$prev,$cur" in
1980 return # fall back to Bash filename completion
1983 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1987 __git_complete_symbol
1992 --pretty=*|--format=*)
1993 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1998 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
2002 __gitcomp "full short no" "" "${cur##--decorate=}"
2006 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2010 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2014 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2019 $__git_log_common_options
2020 $__git_log_shortlog_options
2021 $__git_log_gitk_options
2022 --root --topo-order --date-order --reverse
2023 --follow --full-diff
2024 --abbrev-commit --no-abbrev-commit --abbrev=
2025 --relative-date --date=
2026 --pretty= --format= --oneline
2031 --decorate --decorate= --no-decorate
2033 --no-walk --no-walk= --do-walk
2034 --parents --children
2035 --expand-tabs --expand-tabs= --no-expand-tabs
2037 $__git_diff_common_options
2038 --pickaxe-all --pickaxe-regex
2043 return # fall back to Bash filename completion
2046 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2050 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2054 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2058 __git_complete_revlist
2063 __git_complete_strategy && return
2067 __gitcomp_builtin merge
2077 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2081 __gitcomp_opts "--tool= --prompt --no-prompt --gui --no-gui"
2091 __gitcomp_builtin merge-base
2102 __gitcomp_builtin mv
2107 if [ $(__git_count_arguments "mv") -gt 0 ]; then
2108 # We need to show both cached and untracked files (including
2109 # empty directories) since this may not be the last argument.
2110 __git_complete_index_file "--cached --others --directory"
2112 __git_complete_index_file "--cached"
2118 local subcommands='add append copy edit get-ref list merge prune remove show'
2119 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2121 case "$subcommand,$cur" in
2123 __gitcomp_builtin notes
2131 __gitcomp "$subcommands --ref"
2135 *,--reuse-message=*|*,--reedit-message=*)
2136 __git_complete_refs --cur="${cur#*=}"
2139 __gitcomp_builtin notes_$subcommand
2142 # this command does not take a ref, do not complete it
2158 __git_complete_strategy && return
2161 --recurse-submodules=*)
2162 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2166 __gitcomp_builtin pull
2171 __git_complete_remote_or_refspec
2174 __git_push_recurse_submodules="check on-demand only"
2176 __git_complete_force_with_lease ()
2184 __git_complete_refs --cur="${cur_#*:}"
2187 __git_complete_refs --cur="$cur_"
2196 __gitcomp_nl "$(__git_remotes)"
2199 --recurse-submodules)
2200 __gitcomp "$__git_push_recurse_submodules"
2206 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2209 --recurse-submodules=*)
2210 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2213 --force-with-lease=*)
2214 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2218 __gitcomp_builtin push
2222 __git_complete_remote_or_refspec
2230 --creation-factor= --no-dual-color
2231 $__git_diff_common_options
2236 __git_complete_revlist
2239 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2240 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2244 __git_find_repo_path
2245 if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2246 __gitcomp_opts "$__git_rebase_interactive_inprogress_options"
2248 elif [ -d "$__git_repo_path"/rebase-apply ] || \
2249 [ -d "$__git_repo_path"/rebase-merge ]; then
2250 __gitcomp_opts "$__git_rebase_inprogress_options"
2253 __git_complete_strategy && return
2256 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2260 __git_complete_refs --cur="${cur##--onto=}"
2264 __gitcomp_builtin rebase "" \
2265 "$__git_rebase_interactive_inprogress_options"
2274 local subcommands="show delete expire"
2275 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2277 if [ -z "$subcommand" ]; then
2278 __gitcomp "$subcommands"
2284 __git_send_email_options="--no-cc-cover --cc= --no-bcc --force --relogin-delay= --to= --suppress-cc= --no-annotate --no-chain-reply-to --sendmail-cmd= --no-identity --transfer-encoding= --validate --no-smtp-auth --confirm= --no-format-patch --reply-to= --smtp-pass= --smtp-server= --annotate --envelope-sender= --no-validate --dry-run --no-thread --smtp-debug= --no-to --thread --no-xmailer --identity= --no-signed-off-cc --no-signed-off-by-cc --smtp-domain= --to-cover --8bit-encoding= --bcc= --smtp-ssl-cert-path= --smtp-user= --cc-cmd= --to-cmd= --no-cc --smtp-server-option= --in-reply-to= --subject= --batch-size= --smtp-auth= --compose --smtp-server-port= --xmailer --no-to-cover --chain-reply-to --smtp-encryption= --dump-aliases --quiet --smtp-ssl --signed-off-cc --signed-off-by-cc --suppress-from --compose-encoding= --no-suppress-from --sender= --from= --format-patch --cc-cover --numbered --no-numbered --signoff --stdout --cover-letter --numbered-files --suffix= --start-number= --reroll-count= --filename-max-length= --rfc --cover-from-description= --subject-prefix= --output-directory= --keep-subject --no-binary --zero-commit --ignore-if-in-upstream --no-stat --add-header= --from --attach --inline --signature= --base= --signature-file= --progress --interdiff= --range-diff= --creation-factor= --binary -- --no-signoff --no-stdout --no-cover-letter --no-numbered-files --no-suffix --no-start-number --no-reroll-count --no-filename-max-length --no-cover-from-description --no-zero-commit --no-ignore-if-in-upstream --no-add-header --no-from --no-in-reply-to --no-attach --no-signature --no-base --no-signature-file --no-quiet --no-progress --no-interdiff --no-range-diff --no-creation-factor"
2285 __git_send_email_confirm_options="always never auto cc compose"
2286 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
2291 --to|--cc|--bcc|--from)
2292 __gitcomp_nl "$(__git send-email --dump-aliases)"
2300 $__git_send_email_confirm_options
2301 " "" "${cur##--confirm=}"
2306 $__git_send_email_suppresscc_options
2307 " "" "${cur##--suppress-cc=}"
2311 --smtp-encryption=*)
2312 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2316 __gitcomp "deep shallow" "" "${cur##--thread=}"
2319 --to=*|--cc=*|--bcc=*|--from=*)
2320 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2324 __gitcomp_builtin send-email "$__git_send_email_options $__git_format_patch_extra_options"
2328 __git_complete_revlist
2339 local untracked_state
2342 --ignore-submodules=*)
2343 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2346 --untracked-files=*)
2347 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2352 always never auto column row plain dense nodense
2353 " "" "${cur##--column=}"
2357 __gitcomp_builtin status
2362 untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2363 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2365 case "$untracked_state" in
2367 # --ignored option does not matter
2371 complete_opt="--cached --directory --no-empty-directory --others"
2373 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2374 complete_opt="$complete_opt --ignored --exclude=*"
2379 __git_complete_index_file "$complete_opt"
2384 local dwim_opt="$(__git_checkout_default_dwim_mode)"
2388 # Complete local branches (and DWIM branch
2389 # remote branch names) for an option argument
2390 # specifying a new branch name. This is for
2391 # convenience, assuming new branches are
2392 # possibly based on pre-existing branch names.
2393 __git_complete_refs $dwim_opt --mode="heads"
2402 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2405 __gitcomp_builtin switch
2408 # Unlike in git checkout, git switch --orphan does not take
2409 # a start point. Thus we really have nothing to complete after
2411 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2415 # At this point, we've already handled special completion for
2416 # -c/-C, and --orphan. There are 3 main things left to
2418 # 1) a start-point for -c/-C or -d/--detach
2419 # 2) a remote head, for --track
2420 # 3) a branch name, possibly including DWIM remote branches
2422 if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
2423 __git_complete_refs --mode="refs"
2424 elif [ -n "$(__git_find_on_cmdline "--track")" ]; then
2425 __git_complete_refs --mode="remote-heads"
2427 __git_complete_refs $dwim_opt --mode="heads"
2433 __git_config_get_set_variables ()
2435 local prevword word config_file= c=$cword
2436 while [ $c -gt "$__git_cmd_idx" ]; do
2439 --system|--global|--local|--file=*)
2444 config_file="$word $prevword"
2452 __git config $config_file --name-only --list
2456 __git_compute_config_vars ()
2458 test -n "$__git_config_vars" ||
2459 __git_config_vars="$(git help --config-for-completion | sort -u)"
2462 # Completes possible values of various configuration variables.
2464 # Usage: __git_complete_config_variable_value [<option>]...
2465 # --varname=<word>: The name of the configuration variable whose value is
2466 # to be completed. Defaults to the previous word on the
2468 # --cur=<word>: The current value to be completed. Defaults to the current
2469 # word to be completed.
2470 __git_complete_config_variable_value ()
2472 local varname="$prev" cur_="$cur"
2474 while test $# != 0; do
2476 --varname=*) varname="${1##--varname=}" ;;
2477 --cur=*) cur_="${1##--cur=}" ;;
2483 if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2484 varname="${varname,,}"
2486 varname="$(echo "$varname" |tr A-Z a-z)"
2490 branch.*.remote|branch.*.pushremote)
2491 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2495 __git_complete_refs --cur="$cur_"
2499 __gitcomp "false true merges interactive" "" "$cur_"
2503 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2507 local remote="${varname#remote.}"
2508 remote="${remote%.fetch}"
2509 if [ -z "$cur_" ]; then
2510 __gitcomp_nl "refs/heads/" "" "" ""
2513 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2517 local remote="${varname#remote.}"
2518 remote="${remote%.push}"
2519 __gitcomp_nl "$(__git for-each-ref \
2520 --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2523 pull.twohead|pull.octopus)
2524 __git_compute_merge_strategies
2525 __gitcomp "$__git_merge_strategies" "" "$cur_"
2529 __gitcomp "false true" "" "$cur_"
2534 normal black red green yellow blue magenta cyan white
2535 bold dim ul blink reverse
2540 __gitcomp "false true always never auto" "" "$cur_"
2544 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2548 __gitcomp "man info web html" "" "$cur_"
2552 __gitcomp "$__git_log_date_formats" "" "$cur_"
2555 sendemail.aliasfiletype)
2556 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2560 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2563 sendemail.suppresscc)
2564 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2567 sendemail.transferencoding)
2568 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2577 # Completes configuration sections, subsections, variable names.
2579 # Usage: __git_complete_config_variable_name [<option>]...
2580 # --cur=<word>: The current configuration section/variable name to be
2581 # completed. Defaults to the current word to be completed.
2582 # --sfx=<suffix>: A suffix to be appended to each fully completed
2583 # configuration variable name (but not to sections or
2584 # subsections) instead of the default space.
2585 __git_complete_config_variable_name ()
2587 local cur_="$cur" sfx=" "
2589 while test $# != 0; do
2591 --cur=*) cur_="${1##--cur=}" ;;
2592 --sfx=*) sfx="${1##--sfx=}" ;;
2600 local pfx="${cur_%.*}."
2602 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2606 local pfx="${cur_%.*}."
2608 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2609 __gitcomp "autoSetupMerge autoSetupRebase" "$pfx" "$cur_" "$sfx"
2613 local pfx="${cur_%.*}."
2616 argPrompt cmd confirm needsFile noConsole noRescan
2617 prompt revPrompt revUnmerged title
2618 " "$pfx" "$cur_" "$sfx"
2622 local pfx="${cur_%.*}."
2624 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2628 local pfx="${cur_%.*}."
2630 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2634 local pfx="${cur_%.*}."
2636 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2640 local pfx="${cur_%.*}."
2642 __git_compute_all_commands
2643 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
2647 local pfx="${cur_%.*}."
2650 url proxy fetch push mirror skipDefaultUpdate
2651 receivepack uploadpack tagOpt pushurl
2652 " "$pfx" "$cur_" "$sfx"
2656 local pfx="${cur_%.*}."
2658 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2659 __gitcomp "pushDefault" "$pfx" "$cur_" "$sfx"
2663 local pfx="${cur_%.*}."
2665 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2669 __git_compute_config_vars
2670 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2673 __git_compute_config_vars
2674 __gitcomp_nl "$(echo "$__git_config_vars" |
2687 # Completes '='-separated configuration sections/variable names and values
2688 # for 'git -c section.name=value'.
2690 # Usage: __git_complete_config_variable_name_and_value [<option>]...
2691 # --cur=<word>: The current configuration section/variable name/value to be
2692 # completed. Defaults to the current word to be completed.
2693 __git_complete_config_variable_name_and_value ()
2697 while test $# != 0; do
2699 --cur=*) cur_="${1##--cur=}" ;;
2707 __git_complete_config_variable_value \
2708 --varname="${cur_%%=*}" --cur="${cur_#*=}"
2711 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2719 --get|--get-all|--unset|--unset-all)
2720 __gitcomp_nl "$(__git_config_get_set_variables)"
2724 __git_complete_config_variable_value
2730 __gitcomp_builtin config
2733 __git_complete_config_variable_name
2741 add rename remove set-head set-branches
2742 get-url set-url show prune update
2744 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2745 if [ -z "$subcommand" ]; then
2748 __gitcomp_builtin remote
2751 __gitcomp "$subcommands"
2757 case "$subcommand,$cur" in
2759 __gitcomp_builtin remote_add
2764 __gitcomp_builtin remote_set-head
2767 __gitcomp_builtin remote_set-branches
2769 set-head,*|set-branches,*)
2770 __git_complete_remote_or_refspec
2773 __gitcomp_builtin remote_update
2776 __gitcomp_nl "$(__git_remotes) $(__git_get_config_variables "remotes")"
2779 __gitcomp_builtin remote_set-url
2782 __gitcomp_builtin remote_get-url
2785 __gitcomp_builtin remote_prune
2788 __gitcomp_nl "$(__git_remotes)"
2797 __gitcomp "short medium long" "" "${cur##--format=}"
2801 __gitcomp_builtin replace
2810 local subcommands="clear forget diff remaining status gc"
2811 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2812 if test -z "$subcommand"
2814 __gitcomp "$subcommands"
2821 __git_has_doubledash && return
2825 __gitcomp_builtin reset
2843 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2846 __git_complete_refs --cur="${cur##--source=}"
2849 __gitcomp_builtin restore
2852 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2853 __git_complete_index_file "--modified"
2858 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2862 __git_find_repo_path
2863 if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2864 __gitcomp_opts "$__git_revert_inprogress_options"
2867 __git_complete_strategy && return
2870 __gitcomp_builtin revert "" \
2871 "$__git_revert_inprogress_options"
2882 __gitcomp_builtin rm
2887 __git_complete_index_file "--cached"
2892 __git_has_doubledash && return
2897 $__git_log_common_options
2898 $__git_log_shortlog_options
2899 --numbered --summary --email
2904 __git_complete_revlist
2909 __git_has_doubledash && return
2912 --pretty=*|--format=*)
2913 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2918 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2922 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2926 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2930 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2934 __gitcomp_opts "--pretty= --format= --abbrev-commit --no-abbrev-commit
2935 --oneline --show-signature
2936 --expand-tabs --expand-tabs= --no-expand-tabs
2937 $__git_diff_common_options
2942 __git_complete_revlist_file
2949 __gitcomp_builtin show-branch
2953 __git_complete_revlist
2956 __gitcomp_directories ()
2958 local _tmp_dir _tmp_completions _found=0
2960 # Get the directory of the current token; this differs from dirname
2961 # in that it keeps up to the final trailing slash. If no slash found
2964 _tmp_dir=$BASH_REMATCH
2966 # Find possible directory completions, adding trailing '/' characters,
2967 # de-quoting, and handling unusual characters.
2968 while IFS= read -r -d $'\0' c ; do
2969 # If there are directory completions, find ones that start
2970 # with "$cur", the current token, and put those in COMPREPLY
2971 if [[ $c == "$cur"* ]]; then
2975 done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
2977 if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
2978 # No possible further completions any deeper, so assume we're at
2979 # a leaf directory and just consider it complete
2980 __gitcomp_direct_append "$cur "
2984 _git_sparse_checkout ()
2986 local subcommands="list init set disable add reapply"
2987 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2988 if [ -z "$subcommand" ]; then
2989 __gitcomp "$subcommands"
2993 case "$subcommand,$cur" in
2995 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
2998 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
2999 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3000 __gitcomp_directories
3007 local subcommands='push list show apply clear drop pop create branch'
3008 local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3010 if [ -z "$subcommand" ]; then
3011 case "$((cword - __git_cmd_idx)),$cur" in
3013 __gitcomp_builtin stash_push
3019 __gitcomp "$subcommands"
3025 case "$subcommand,$cur" in
3027 # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3028 __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3031 __gitcomp_builtin stash_show "$__git_diff_common_options"
3034 __gitcomp_builtin "stash_$subcommand"
3037 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3040 __gitcomp_nl "$(__git stash list \
3041 | sed -n -e 's/:.*//p')"
3044 show,*|apply,*|drop,*|pop,*)
3045 __gitcomp_nl "$(__git stash list \
3046 | sed -n -e 's/:.*//p')"
3053 __git_has_doubledash && return
3055 local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
3056 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3057 if [ -z "$subcommand" ]; then
3060 __gitcomp_opts "--quiet"
3063 __gitcomp "$subcommands"
3069 case "$subcommand,$cur" in
3071 __gitcomp_opts "--branch --force --name --reference --depth"
3074 __gitcomp_opts "--cached --recursive"
3077 __gitcomp_opts "--force --all"
3081 --init --remote --no-fetch
3082 --recommend-shallow --no-recommend-shallow
3083 --force --rebase --merge --reference --depth --recursive --jobs
3087 __gitcomp_opts "--default --branch"
3090 __gitcomp_opts "--cached --files --summary-limit"
3092 foreach,--*|sync,--*)
3093 __gitcomp_opts "--recursive"
3103 init fetch clone rebase dcommit log find-rev
3104 set-tree commit-diff info create-ignore propget
3105 proplist show-ignore show-externals branch tag blame
3106 migrate mkdirs reset gc
3108 local subcommand="$(__git_find_on_cmdline "$subcommands")"
3109 if [ -z "$subcommand" ]; then
3110 __gitcomp "$subcommands"
3112 local remote_opts="--username= --config-dir= --no-auth-cache"
3114 --follow-parent --authors-file= --repack=
3115 --no-metadata --use-svm-props --use-svnsync-props
3116 --log-window-size= --no-checkout --quiet
3117 --repack-flags --use-log-author --localtime
3120 --ignore-paths= --include-paths= $remote_opts
3123 --template= --shared= --trunk= --tags=
3124 --branches= --stdlayout --minimize-url
3125 --no-metadata --use-svm-props --use-svnsync-props
3126 --rewrite-root= --prefix= $remote_opts
3129 --edit --rmdir --find-copies-harder --copy-similarity=
3132 case "$subcommand,$cur" in
3134 __gitcomp_opts "--revision= --fetch-all $fc_opts"
3137 __gitcomp_opts "--revision= $fc_opts $init_opts"
3140 __gitcomp_opts "$init_opts"
3144 --merge --strategy= --verbose --dry-run
3145 --fetch-all --no-rebase --commit-url
3146 --revision --interactive $cmt_opts $fc_opts
3150 __gitcomp_opts "--stdin $cmt_opts $fc_opts"
3152 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3153 show-externals,--*|mkdirs,--*)
3154 __gitcomp_opts "--revision="
3158 --limit= --revision= --verbose --incremental
3159 --oneline --show-commit --non-recursive
3160 --authors-file= --color
3165 --merge --verbose --strategy= --local
3166 --fetch-all --dry-run $fc_opts
3170 __gitcomp_opts "--message= --file= --revision= $cmt_opts"
3173 __gitcomp_opts "--url"
3176 __gitcomp_opts "--dry-run --message --tag"
3179 __gitcomp_opts "--dry-run --message"
3182 __gitcomp_opts "--git-format"
3186 --config-dir= --ignore-paths= --minimize
3187 --no-auth-cache --username=
3191 __gitcomp_opts "--revision= --parent"
3201 local i c="$__git_cmd_idx" f=0
3202 while [ $c -lt $cword ]; do
3205 -d|--delete|-v|--verify)
3206 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3221 __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3231 __gitcomp_builtin tag
3241 __git_complete_worktree_paths ()
3244 # Generate completion reply from worktree list skipping the first
3245 # entry: it's the path of the main worktree, which can't be moved,
3246 # removed, locked, etc.
3247 __gitcomp_nl "$(git worktree list --porcelain |
3248 sed -n -e '2,$ s/^worktree //p')"
3253 local subcommands="add list lock move prune remove unlock"
3254 local subcommand subcommand_idx
3256 subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3257 subcommand_idx="${subcommand% *}"
3258 subcommand="${subcommand#* }"
3260 case "$subcommand,$cur" in
3262 __gitcomp "$subcommands"
3265 __gitcomp_builtin worktree_$subcommand
3267 add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
3268 # Here we are not completing an --option, it's either the
3271 -b|-B) # Complete refs for branch to be created/reset.
3274 -*) # The previous word is an -o|--option without an
3275 # unstuck argument: have to complete the path for
3276 # the new worktree, so don't list anything, but let
3277 # Bash fall back to filename completion.
3279 *) # The previous word is not an --option, so it must
3280 # be either the 'add' subcommand, the unstuck
3281 # argument of an option (e.g. branch for -b|-B), or
3282 # the path for the new worktree.
3283 if [ $cword -eq $((subcommand_idx+1)) ]; then
3284 # Right after the 'add' subcommand: have to
3285 # complete the path, so fall back to Bash
3286 # filename completion.
3289 case "${words[cword-2]}" in
3290 -b|-B) # After '-b <branch>': have to
3291 # complete the path, so fall back
3292 # to Bash filename completion.
3294 *) # After the path: have to complete
3295 # the ref to be checked out.
3303 lock,*|remove,*|unlock,*)
3304 __git_complete_worktree_paths
3307 if [ $cword -eq $((subcommand_idx+1)) ]; then
3308 # The first parameter must be an existing working
3310 __git_complete_worktree_paths
3312 # The second parameter is the destination: it could
3313 # be any path, so don't list anything, but let Bash
3314 # fall back to filename completion.
3321 __git_complete_common () {
3326 __gitcomp_builtin "$command"
3331 __git_cmds_with_parseopt_helper=
3332 __git_support_parseopt_helper () {
3333 test -n "$__git_cmds_with_parseopt_helper" ||
3334 __git_cmds_with_parseopt_helper="$(__git --list-cmds=parseopt)"
3336 case " $__git_cmds_with_parseopt_helper " in
3346 __git_have_func () {
3347 declare -f -- "$1" >/dev/null 2>&1
3350 __git_complete_command () {
3352 local completion_func="_git_${command//-/_}"
3353 if ! __git_have_func $completion_func &&
3354 __git_have_func _completion_loader
3356 _completion_loader "git-$command"
3358 if __git_have_func $completion_func
3362 elif __git_support_parseopt_helper "$command"
3364 __git_complete_common "$command"
3373 local i c=1 command __git_dir __git_repo_path
3374 local __git_C_args C_args_count=0
3377 while [ $c -lt $cword ]; do
3381 __git_dir="${i#--git-dir=}"
3385 __git_dir="${words[c]}"
3394 -c|--work-tree|--namespace)
3398 __git_C_args[C_args_count++]=-C
3400 __git_C_args[C_args_count++]="${words[c]}"
3413 if [ -z "${command-}" ]; then
3415 --git-dir|-C|--work-tree)
3416 # these need a path argument, let's fall back to
3417 # Bash filename completion
3421 __git_complete_config_variable_name_and_value
3425 # we don't support completing these options' arguments
3444 --no-replace-objects
3449 if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3451 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3453 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3455 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3457 list_cmds=builtins,$list_cmds
3459 __gitcomp_nl "$(__git --list-cmds=$list_cmds)"
3466 __git_complete_command "$command" && return
3468 local expansion=$(__git_aliased_command "$command")
3469 if [ -n "$expansion" ]; then
3471 __git_complete_command "$expansion"
3477 __git_has_doubledash && return
3479 local __git_repo_path
3480 __git_find_repo_path
3483 if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3489 $__git_log_common_options
3490 $__git_log_gitk_options
3496 __git_complete_revlist
3499 if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
3500 echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
3504 # The following function is based on code from:
3506 # bash_completion - programmable completion functions for bash 3.2+
3508 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
3509 # © 2009-2010, Bash Completion Maintainers
3510 # <bash-completion-devel@lists.alioth.debian.org>
3512 # This program is free software; you can redistribute it and/or modify
3513 # it under the terms of the GNU General Public License as published by
3514 # the Free Software Foundation; either version 2, or (at your option)
3515 # any later version.
3517 # This program is distributed in the hope that it will be useful,
3518 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3519 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3520 # GNU General Public License for more details.
3522 # You should have received a copy of the GNU General Public License
3523 # along with this program; if not, see <http://www.gnu.org/licenses/>.
3525 # The latest version of this software can be obtained here:
3527 # http://bash-completion.alioth.debian.org/
3531 # This function reorganizes the words on the command line to be processed by
3532 # the rest of the script.
3534 # This is roughly equivalent to going back in time and setting
3535 # COMP_WORDBREAKS to exclude '=' and ':'. The intent is to
3536 # make option types like --date=<type> and <rev>:<path> easy to
3537 # recognize by treating each shell word as a single token.
3539 # It is best not to set COMP_WORDBREAKS directly because the value is
3540 # shared with other completion scripts. By the time the completion
3541 # function gets called, COMP_WORDS has already been populated so local
3542 # changes to COMP_WORDBREAKS have no effect.
3544 if ! type __git_get_comp_words_by_ref >/dev/null 2>&1; then
3545 __git_get_comp_words_by_ref ()
3547 local exclude i j first
3549 # Which word separators to exclude?
3550 exclude="${COMP_WORDBREAKS//[^=:]}"
3552 if [ -n "$exclude" ]; then
3553 # List of word completion separators has shrunk;
3554 # re-assemble words to complete.
3555 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
3556 # Append each nonempty word consisting of just
3557 # word separator characters to the current word.
3561 [ -n "${COMP_WORDS[$i]}" ] &&
3562 # word consists of excluded word separators
3563 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
3565 # Attach to the previous token,
3566 # unless the previous token is the command name.
3567 if [ $j -ge 2 ] && [ -n "$first" ]; then
3571 words[$j]=${words[j]}${COMP_WORDS[i]}
3572 if [ $i = $COMP_CWORD ]; then
3575 if (($i < ${#COMP_WORDS[@]} - 1)); then
3582 words[$j]=${words[j]}${COMP_WORDS[i]}
3583 if [ $i = $COMP_CWORD ]; then
3588 words=("${COMP_WORDS[@]}")
3592 prev=${words[cword-1]}
3598 local cur words cword prev __git_cmd_idx=0
3599 __git_get_comp_words_by_ref
3605 local wrapper="__git_wrap${2}"
3606 eval "$wrapper () { __git_func_wrap $2 ; }"
3607 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
3608 || complete -o default -o nospace -F $wrapper $1
3611 # Setup the completion for git commands
3612 # 1: command or alias
3613 # 2: function to call (e.g. `git`, `gitk`, `git_fetch`)
3618 if __git_have_func $2; then
3620 elif __git_have_func __$2_main; then
3622 elif __git_have_func _$2; then
3625 echo "ERROR: could not find function '$2'" 1>&2
3628 ___git_complete $1 $func
3631 if ! git --list-cmds=main >/dev/null 2>&1; then
3633 declare -A __git_cmds
3634 __git_cmds[list-complete]="apply blame cherry config difftool fsck help instaweb mergetool prune reflog remote repack replace request-pull send-email show-branch stage whatchanged"
3635 __git_cmds[list-guide]="attributes cli core-tutorial credentials cvs-migration diffcore everyday faq glossary hooks ignore mailmap modules namespaces remote-helpers repository-layout revisions submodules tutorial tutorial-2 workflows"
3636 __git_cmds[list-mainporcelain]="add am archive bisect branch bundle checkout cherry-pick citool clean clone commit describe diff fetch format-patch gc grep gui init log maintenance merge mv notes pull push range-diff rebase reset restore revert rm shortlog show sparse-checkout stash status submodule switch tag worktree gitk"
3637 __git_cmds[main]="add add--interactive am annotate apply archimport archive bisect bisect--helper blame branch bugreport bundle cat-file check-attr check-ignore check-mailmap check-ref-format checkout checkout--worker checkout-index cherry cherry-pick citool clean clone column commit commit-graph commit-tree config count-objects credential credential-cache credential-cache--daemon credential-store cvsexportcommit cvsimport cvsserver daemon describe diff diff-files diff-index diff-tree difftool difftool--helper env--helper fast-export fast-import fetch fetch-pack filter-branch fmt-merge-msg for-each-ref for-each-repo format-patch fsck fsck-objects fsmonitor--daemon gc get-tar-commit-id grep gui gui--askpass hash-object help hook http-backend http-fetch http-push imap-send index-pack init init-db instaweb interpret-trailers legacy-rebase legacy-stash log ls-files ls-remote ls-tree mailinfo mailsplit maintenance merge merge-base merge-file merge-index merge-octopus merge-one-file merge-ours merge-recursive merge-recursive-ours merge-recursive-theirs merge-resolve merge-subtree merge-tree mergetool mktag mktree multi-pack-index mv name-rev notes p4 pack-objects pack-redundant pack-refs patch-id pickaxe prune prune-packed pull push quiltimport range-diff read-tree rebase rebase--helper receive-pack reflog relink remote remote-ext remote-fd remote-ftp remote-ftps remote-http remote-https remote-testsvn repack replace request-pull rerere reset restore rev-list rev-parse revert rm send-email send-pack serve sh-i18n--envsubst shell shortlog show show-branch show-index show-ref sparse-checkout stage stash status stripspace submodule submodule--helper svn switch symbolic-ref tag unpack-file unpack-objects update-index update-ref update-server-info upload-archive upload-archive--writer upload-pack var verify-commit verify-pack verify-tag version web--browse whatchanged worktree write-tree"
3638 __git_cmds[others]=""
3639 __git_cmds[parseopt]="add am apply archive bisect--helper blame branch bugreport cat-file check-attr check-ignore check-mailmap checkout checkout--worker checkout-index cherry cherry-pick clean clone column commit commit-graph config count-objects credential-cache credential-cache--daemon credential-store describe difftool env--helper fast-export fetch fmt-merge-msg for-each-ref for-each-repo format-patch fsck fsck-objects fsmonitor--daemon gc grep hash-object help hook init init-db interpret-trailers log ls-files ls-remote ls-tree merge merge-base merge-file mktree multi-pack-index mv name-rev notes pack-objects pack-refs pickaxe prune prune-packed pull push range-diff read-tree rebase receive-pack reflog remote repack replace rerere reset restore revert rm send-pack shortlog show show-branch show-index show-ref sparse-checkout stage stash status stripspace switch symbolic-ref tag update-index update-ref update-server-info upload-pack verify-commit verify-pack verify-tag version whatchanged write-tree "
3646 while read -r -d ',' x; do
3655 echo ${__git_cmds[$x]}
3658 done <<< "${1##--list-cmds=},"
3662 git ${__git_C_args:+"${__git_C_args[@]}"} \
3663 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
3668 ___git_complete git __git_main
3669 ___git_complete gitk __gitk_main
3671 # The following are necessary only for Cygwin, and only are needed
3672 # when the user has tab-completed the executable name and consequently
3673 # included the '.exe' suffix.
3675 if [ "$OSTYPE" = cygwin ]; then
3676 ___git_complete git.exe __git_main