]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/gitfast/git-completion.bash
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / gitfast / git-completion.bash
1 # bash/zsh completion support for core Git.
2 #
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.
6 #
7 # The contained completion routines provide support for completing:
8 #
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
17 #
18 # To use these routines:
19 #
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.
25 #
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 ; ... '".
31 #
32 # If you have a command that is not part of git, but you would still
33 # like completion, you can use __git_complete:
34 #
35 #   __git_complete gl git_log
36 #
37 # Or if it's a main command (i.e. git or gitk):
38 #
39 #   __git_complete gk gitk
40 #
41 # Compatible with bash 3.2.57.
42 #
43 # You can set the following environment variables to influence the behavior of
44 # the completion routines:
45 #
46 #   GIT_COMPLETION_CHECKOUT_NO_GUESS
47 #
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"
50 #     exists).
51 #
52 #   GIT_COMPLETION_SHOW_ALL_COMMANDS
53 #
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>").
56 #
57 #   GIT_COMPLETION_SHOW_ALL
58 #
59 #     When set to "1" suggest all options, including options which are
60 #     typically hidden (e.g. '--allow-empty' for 'git commit').
61
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.
66
67 __gitcompadd ()
68 {
69         local x i=${#COMPREPLY[@]}
70         for x in $1; do
71                 if [[ "$x" == "$3"* ]]; then
72                         COMPREPLY[i++]="$2$x$4"
73                 fi
74         done
75 }
76
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).
83 __gitcomp ()
84 {
85         local IFS=$' \t\n'
86         __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
87 }
88
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
97 #    appended.
98 __gitcomp_nl ()
99 {
100         local IFS=$'\n'
101         __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
102 }
103
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
107 # necessary.
108 # 1: List of newline-separated matching completion words, complete with
109 #    prefix and suffix.
110 __gitcomp_direct ()
111 {
112         local IFS=$'\n'
113
114         COMPREPLY+=($1)
115 }
116
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
122 #    (optional).
123 # 3: Generate possible completion matches for this word (optional).
124 __gitcomp_file ()
125 {
126         local IFS=$'\n'
127
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}" ""
133
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 ||
137         true
138 }
139
140 # Fills the COMPREPLY array with prefiltered paths without any additional
141 # processing.
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
145 #    path components.
146 __gitcomp_file_direct ()
147 {
148         local IFS=$'\n'
149
150         COMPREPLY+=($1)
151
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 ||
155         true
156 }
157
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).
164 __gitcomp_opts ()
165 {
166         local cur_="${3-$cur}"
167
168         if [[ "$cur_" == *= ]]; then
169                 return
170         fi
171
172         local c i=0 IFS=$' \t\n' sfx
173         for c in $1; do
174                 if [[ $c == "--" ]]; then
175                         if [[ "$cur_" == --no-* ]]; then
176                                 continue
177                         fi
178
179                         if [[ --no == "$cur_"* ]]; then
180                                 COMPREPLY[i++]="--no-... "
181                         fi
182                         break
183                 fi
184                 if [[ $c == "$cur_"* ]]; then
185                         if [[ -z "${4+set}" ]]; then
186                                 case $c in
187                                 *=|*.) sfx="" ;;
188                                 *) sfx=" " ;;
189                                 esac
190                         else
191                                 sfx="$4"
192                         fi
193                         COMPREPLY[i++]="${2-}$c$sfx"
194                 fi
195         done
196 }
197
198 # __gitcomp functions end here
199 # ==============================================================================
200
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
203 # variable.
204 __git_find_repo_path ()
205 {
206         if [ -n "${__git_repo_path-}" ]; then
207                 # we already know where it is
208                 return
209         fi
210
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
222                 __git_repo_path=.git
223         else
224                 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)"
225         fi
226 }
227
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
231 __gitdir ()
232 {
233         if [ -z "${1-}" ]; then
234                 __git_find_repo_path || return 1
235                 echo "$__git_repo_path"
236         elif [ -d "$1/.git" ]; then
237                 echo "$1/.git"
238         else
239                 echo "$1"
240         fi
241 }
242
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
245 __git ()
246 {
247         git ${__git_C_args:+"${__git_C_args[@]}"} \
248                 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
249 }
250
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.
254 __git_dequote ()
255 {
256         local rest="$1" len ch
257
258         dequoted_word=""
259
260         while test -n "$rest"; do
261                 len=${#dequoted_word}
262                 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}"
263                 rest="${rest:$((${#dequoted_word}-$len))}"
264
265                 case "${rest:0:1}" in
266                 \\)
267                         ch="${rest:1:1}"
268                         case "$ch" in
269                         $'\n')
270                                 ;;
271                         *)
272                                 dequoted_word="$dequoted_word$ch"
273                                 ;;
274                         esac
275                         rest="${rest:2}"
276                         ;;
277                 \')
278                         rest="${rest:1}"
279                         len=${#dequoted_word}
280                         dequoted_word="$dequoted_word${rest%%\'*}"
281                         rest="${rest:$((${#dequoted_word}-$len+1))}"
282                         ;;
283                 \")
284                         rest="${rest: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
290                                 \\)
291                                         ch="${rest:1:1}"
292                                         case "$ch" in
293                                         \"|\\|\$|\`)
294                                                 dequoted_word="$dequoted_word$ch"
295                                                 ;;
296                                         $'\n')
297                                                 ;;
298                                         *)
299                                                 dequoted_word="$dequoted_word\\$ch"
300                                                 ;;
301                                         esac
302                                         rest="${rest:2}"
303                                         ;;
304                                 \")
305                                         rest="${rest:1}"
306                                         break
307                                         ;;
308                                 esac
309                         done
310                         ;;
311                 esac
312         done
313 }
314
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
319 else
320         unset $(compgen -v __gitcomp_builtin_)
321 fi
322
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"
427
428 __gitcomp_builtin_get_default ()
429 {
430         eval "test -n \"\$${1}_default\" && echo \"\$${1}_default\""
431 }
432
433 # This function is equivalent to
434 #
435 #    __gitcomp_opts "$(git xxx --git-completion-helper) ..."
436 #
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
441 __gitcomp_builtin ()
442 {
443         # spaces must be replaced with underscore for multi-word
444         # commands, e.g. "git remote add" becomes remote_add.
445         local cmd="$1"
446         local incl="${2-}"
447         local excl="${3-}"
448
449         local var=__gitcomp_builtin_"${cmd//-/_}"
450         local options
451         eval "options=\${$var-}"
452
453         if [ -z "$options" ]; then
454                 local completion_helper
455                 if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
456                         completion_helper="--git-completion-helper-all"
457                 else
458                         completion_helper="--git-completion-helper"
459                 fi
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 "
465
466                 for i in $excl; do
467                         options="${options/ $i / }"
468                 done
469                 eval "$var=\"$options\""
470         fi
471
472         __gitcomp_opts "$options"
473 }
474
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 ()
480 {
481         if [ "$2" = "--committable" ]; then
482                 __git -C "$1" -c core.quotePath=false diff-index \
483                         --name-only --relative HEAD -- "${3//\\/\\\\}*"
484         else
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//\\/\\\\}*"
488         fi
489 }
490
491
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
497 #    slash.
498 # 3: List only paths matching this path component (optional).
499 __git_index_files ()
500 {
501         local root="$2" match="$3"
502
503         __git_ls_files_helper "$root" "$1" "${match:-?}" |
504         awk -F / -v pfx="${2//\\/\\\\}" '{
505                 paths[$1] = 1
506         }
507         END {
508                 for (p in paths) {
509                         if (substr(p, 1, 1) != "\"") {
510                                 # No special characters, easy!
511                                 print pfx p
512                                 continue
513                         }
514
515                         # The path is quoted.
516                         p = dequote(p)
517                         if (p == "")
518                                 continue
519
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.
525                         if (p in paths)
526                                 # We have seen the same directory unquoted,
527                                 # skip it.
528                                 continue
529                         else
530                                 print pfx p
531                 }
532         }
533         function dequote(p,    bs_idx, out, esc, esc_idx, dec) {
534                 # Skip opening double quote.
535                 p = substr(p, 2)
536
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)
542
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\"\\",
546                                                  esc_idx, 1)
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.
552                                 # Skip this path.
553                                 return ""
554                         } else {
555                                 # Must be a \nnn octal value, then.
556                                 dec = esc             * 64 + \
557                                       substr(p, 1, 1) * 8  + \
558                                       substr(p, 2, 1)
559                                 out = out sprintf("%c", dec)
560                                 p = substr(p, 3)
561                         }
562                 }
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)
568                 else
569                         out = out p
570
571                 return out
572         }'
573 }
574
575 # __git_complete_index_file requires 1 argument:
576 # 1: the options to pass to ls-file
577 #
578 # The exception is --committable, which finds the files appropriate commit.
579 __git_complete_index_file ()
580 {
581         local dequoted_word pfx="" cur_
582
583         __git_dequote "$cur"
584
585         case "$dequoted_word" in
586         ?*/*)
587                 pfx="${dequoted_word%/*}/"
588                 cur_="${dequoted_word##*/}"
589                 ;;
590         *)
591                 cur_="$dequoted_word"
592         esac
593
594         __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")"
595 }
596
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
600 #    unset or empty).
601 # 3: A suffix to be appended to each listed branch (optional).
602 __git_heads ()
603 {
604         local pfx="${1-}" cur_="${2-}" sfx="${3-}"
605
606         __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
607                         "refs/heads/$cur_*" "refs/heads/$cur_*/**"
608 }
609
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
613 #    unset or empty).
614 # 3: A suffix to be appended to each listed branch (optional).
615 __git_remote_heads ()
616 {
617         local pfx="${1-}" cur_="${2-}" sfx="${3-}"
618
619         __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
620                         "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
621 }
622
623 # Lists tags from the local repository.
624 # Accepts the same positional parameters as __git_heads() above.
625 __git_tags ()
626 {
627         local pfx="${1-}" cur_="${2-}" sfx="${3-}"
628
629         __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
630                         "refs/tags/$cur_*" "refs/tags/$cur_*/**"
631 }
632
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
637 #    unset or empty).
638 # 3: A suffix to be appended to each listed branch (optional).
639 __git_dwim_remote_heads ()
640 {
641         local pfx="${1-}" cur_="${2-}" sfx="${3-}"
642         local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
643
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_*/**" | \
650         uniq -u
651 }
652
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
661 #    empty).
662 # 5: A suffix to be appended to each listed ref (optional; ignored, if set
663 #    but empty).
664 #
665 # Use __git_complete_refs() instead.
666 __git_refs ()
667 {
668         local i hash dir track="${2-}"
669         local list_refs_from=path remote="${1-}"
670         local format refs
671         local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
672         local match="${4-}"
673         local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
674
675         __git_find_repo_path
676         dir="$__git_repo_path"
677
678         if [ -z "$remote" ]; then
679                 if [ -z "$dir" ]; then
680                         return
681                 fi
682         else
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
688                         dir="$remote/.git"
689                 elif [ -d "$remote" ]; then
690                         dir="$remote"
691                 else
692                         list_refs_from=url
693                 fi
694         fi
695
696         if [ "$list_refs_from" = path ]; then
697                 if [[ "$cur_" == ^* ]]; then
698                         pfx="$pfx^"
699                         fer_pfx="$fer_pfx^"
700                         cur_=${cur_#^}
701                         match=${match#^}
702                 fi
703                 case "$cur_" in
704                 refs|refs/*)
705                         format="refname"
706                         refs=("$match*" "$match*/**")
707                         track=""
708                         ;;
709                 *)
710                         for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
711                                 case "$i" in
712                                 $match*)
713                                         if [ -e "$dir/$i" ]; then
714                                                 echo "$pfx$i$sfx"
715                                         fi
716                                         ;;
717                                 esac
718                         done
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*/**")
723                         ;;
724                 esac
725                 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
726                         "${refs[@]}"
727                 if [ -n "$track" ]; then
728                         __git_dwim_remote_heads "$pfx" "$match" "$sfx"
729                 fi
730                 return
731         fi
732         case "$cur_" in
733         refs|refs/*)
734                 __git ls-remote "$remote" "$match*" | \
735                 while read -r hash i; do
736                         case "$i" in
737                         *^{}) ;;
738                         *) echo "$pfx$i$sfx" ;;
739                         esac
740                 done
741                 ;;
742         *)
743                 if [ "$list_refs_from" = remote ]; then
744                         case "HEAD" in
745                         $match*)        echo "${pfx}HEAD$sfx" ;;
746                         esac
747                         __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
748                                 "refs/remotes/$remote/$match*" \
749                                 "refs/remotes/$remote/$match*/**"
750                 else
751                         local query_symref
752                         case "HEAD" in
753                         $match*)        query_symref="HEAD" ;;
754                         esac
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
759                                 case "$i" in
760                                 *^{})   ;;
761                                 refs/*) echo "$pfx${i#refs/*/}$sfx" ;;
762                                 *)      echo "$pfx$i$sfx" ;;  # symbolic refs
763                                 esac
764                         done
765                 fi
766                 ;;
767         esac
768 }
769
770 # Completes refs, short and long, local and remote, symbolic and pseudo.
771 #
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
780 #                 space.
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 ()
786 {
787         local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
788
789         while test $# != 0; do
790                 case "$1" in
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=}" ;;
799                 *)              return 1 ;;
800                 esac
801                 shift
802         done
803
804         # complete references based on the specified mode
805         case "$mode" in
806                 refs)
807                         __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
808                 heads)
809                         __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
810                 remote-heads)
811                         __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
812                 *)
813                         return 1 ;;
814         esac
815
816         # Append DWIM remote branch names if requested
817         if [ "$dwim" = "yes" ]; then
818                 __gitcomp_direct "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
819         fi
820 }
821
822 # __git_refs2 requires 1 argument (to pass to __git_refs)
823 # Deprecated: use __git_complete_fetch_refspecs() instead.
824 __git_refs2 ()
825 {
826         local i
827         for i in $(__git_refs "$1"); do
828                 echo "$i:$i"
829         done
830 }
831
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
838 #    space (optional).
839 __git_complete_fetch_refspecs ()
840 {
841         local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
842
843         __gitcomp_direct "$(
844                 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
845                         echo "$pfx$i:$i$sfx"
846                 done
847                 )"
848 }
849
850 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
851 __git_refs_remotes ()
852 {
853         local i hash
854         __git ls-remote "$1" 'refs/heads/*' | \
855         while read -r hash i; do
856                 echo "$i:refs/remotes/$1/${i#refs/heads/}"
857         done
858 }
859
860 __git_remotes ()
861 {
862         __git_find_repo_path
863         test -d "$__git_repo_path/remotes" && ls -1 "$__git_repo_path/remotes"
864         __git remote
865 }
866
867 # Returns true if $1 matches the name of a configured remote, false otherwise.
868 __git_is_configured_remote ()
869 {
870         local remote
871         for remote in $(__git_remotes); do
872                 if [ "$remote" = "$1" ]; then
873                         return 0
874                 fi
875         done
876         return 1
877 }
878
879 __git_list_merge_strategies ()
880 {
881         LANG=C LC_ALL=C git merge -s help 2>&1 |
882         sed -n -e '/[Aa]vailable strategies are: /,/^$/{
883                 s/\.$//
884                 s/.*://
885                 s/^[    ]*//
886                 s/[     ]*$//
887                 p
888         }'
889 }
890
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
897 # is needed.
898 __git_compute_merge_strategies ()
899 {
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}"; }
903 }
904
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="
909
910 __git_complete_revlist_file ()
911 {
912         local dequoted_word pfx ls ref cur_="$cur"
913         case "$cur_" in
914         *..?*:*)
915                 return
916                 ;;
917         ?*:*)
918                 ref="${cur_%%:*}"
919                 cur_="${cur_#*:}"
920
921                 __git_dequote "$cur_"
922
923                 case "$dequoted_word" in
924                 ?*/*)
925                         pfx="${dequoted_word%/*}"
926                         cur_="${dequoted_word##*/}"
927                         ls="$ref:$pfx"
928                         pfx="$pfx/"
929                         ;;
930                 *)
931                         cur_="$dequoted_word"
932                         ls="$ref"
933                         ;;
934                 esac
935
936                 case "$COMP_WORDBREAKS" in
937                 *:*) : great ;;
938                 *)   pfx="$ref:$pfx" ;;
939                 esac
940
941                 __gitcomp_file "$(__git ls-tree "$ls" \
942                                 | sed 's/^.*    //
943                                        s/$//')" \
944                         "$pfx" "$cur_"
945                 ;;
946         *...*)
947                 pfx="${cur_%...*}..."
948                 cur_="${cur_#*...}"
949                 __git_complete_refs --pfx="$pfx" --cur="$cur_"
950                 ;;
951         *..*)
952                 pfx="${cur_%..*}.."
953                 cur_="${cur_#*..}"
954                 __git_complete_refs --pfx="$pfx" --cur="$cur_"
955                 ;;
956         *)
957                 __git_complete_refs
958                 ;;
959         esac
960 }
961
962 __git_complete_file ()
963 {
964         __git_complete_revlist_file
965 }
966
967 __git_complete_revlist ()
968 {
969         __git_complete_revlist_file
970 }
971
972 __git_complete_remote_or_refspec ()
973 {
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
977                 ((c++))
978         fi
979         while [ $c -lt $cword ]; do
980                 i="${words[c]}"
981                 case "$i" in
982                 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
983                 -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
984                 --all)
985                         case "$cmd" in
986                         push) no_complete_refspec=1 ;;
987                         fetch)
988                                 return
989                                 ;;
990                         *) ;;
991                         esac
992                         ;;
993                 --multiple) no_complete_refspec=1; break ;;
994                 -*) ;;
995                 *) remote="$i"; break ;;
996                 esac
997                 ((c++))
998         done
999         if [ -z "$remote" ]; then
1000                 __gitcomp_nl "$(__git_remotes)"
1001                 return
1002         fi
1003         if [ $no_complete_refspec = 1 ]; then
1004                 return
1005         fi
1006         [ "$remote" = "." ] && remote=
1007         case "$cur_" in
1008         *:*)
1009                 case "$COMP_WORDBREAKS" in
1010                 *:*) : great ;;
1011                 *)   pfx="${cur_%%:*}:" ;;
1012                 esac
1013                 cur_="${cur_#*:}"
1014                 lhs=0
1015                 ;;
1016         +*)
1017                 pfx="+"
1018                 cur_="${cur_#+}"
1019                 ;;
1020         esac
1021         case "$cmd" in
1022         fetch)
1023                 if [ $lhs = 1 ]; then
1024                         __git_complete_fetch_refspecs "$remote" "$pfx" "$cur_"
1025                 else
1026                         __git_complete_refs --pfx="$pfx" --cur="$cur_"
1027                 fi
1028                 ;;
1029         pull|remote)
1030                 if [ $lhs = 1 ]; then
1031                         __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1032                 else
1033                         __git_complete_refs --pfx="$pfx" --cur="$cur_"
1034                 fi
1035                 ;;
1036         push)
1037                 if [ $lhs = 1 ]; then
1038                         __git_complete_refs --pfx="$pfx" --cur="$cur_"
1039                 else
1040                         __git_complete_refs --remote="$remote" --pfx="$pfx" --cur="$cur_"
1041                 fi
1042                 ;;
1043         esac
1044 }
1045
1046 __git_complete_strategy ()
1047 {
1048         __git_compute_merge_strategies
1049         case "$prev" in
1050         -s|--strategy)
1051                 __gitcomp "$__git_merge_strategies"
1052                 return 0
1053                 ;;
1054         -X)
1055                 __gitcomp_opts "$__git_merge_strategy_options"
1056                 return 0
1057                 ;;
1058         esac
1059         case "$cur" in
1060         --strategy=*)
1061                 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1062                 return 0
1063                 ;;
1064         --strategy-option=*)
1065                 __gitcomp_opts "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1066                 return 0
1067                 ;;
1068         esac
1069         return 1
1070 }
1071
1072 __git_all_commands=
1073 __git_compute_all_commands ()
1074 {
1075         test -n "$__git_all_commands" ||
1076         __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
1077 }
1078
1079 # Lists all set config variables starting with the given section prefix,
1080 # with the prefix removed.
1081 __git_get_config_variables ()
1082 {
1083         local section="$1" i IFS=$'\n'
1084         for i in $(__git config --name-only --get-regexp "^$section\..*"); do
1085                 echo "${i#$section.}"
1086         done
1087 }
1088
1089 __git_pretty_aliases ()
1090 {
1091         __git_get_config_variables "pretty"
1092 }
1093
1094 # __git_aliased_command requires 1 argument
1095 __git_aliased_command ()
1096 {
1097         local cur=$1 last list= word cmdline
1098
1099         while [[ -n "$cur" ]]; do
1100                 if [[ "$list" == *" $cur "* ]]; then
1101                         # loop detected
1102                         return
1103                 fi
1104
1105                 cmdline=$(__git config --get "alias.$cur")
1106                 list=" $cur $list"
1107                 last=$cur
1108                 cur=
1109
1110                 for word in $cmdline; do
1111                         case "$word" in
1112                         \!gitk|gitk)
1113                                 cur="gitk"
1114                                 break
1115                                 ;;
1116                         \!*)    : shell command alias ;;
1117                         -*)     : option ;;
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 ;;
1124                         *)
1125                                 cur="$word"
1126                                 break
1127                         esac
1128                 done
1129         done
1130
1131         cur=$last
1132         if [[ "$cur" != "$1" ]]; then
1133                 echo "$cur"
1134         fi
1135 }
1136
1137 # Check whether one of the given words is present on the command line,
1138 # and print the first word found.
1139 #
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 ()
1143 {
1144         local word c="$__git_cmd_idx" show_idx
1145
1146         while test $# -gt 1; do
1147                 case "$1" in
1148                 --show-idx)     show_idx=y ;;
1149                 *)              return 1 ;;
1150                 esac
1151                 shift
1152         done
1153         local wordlist="$1"
1154
1155         while [ $c -lt $cword ]; do
1156                 for word in $wordlist; do
1157                         if [ "$word" = "${words[c]}" ]; then
1158                                 if [ -n "${show_idx-}" ]; then
1159                                         echo "$c $word"
1160                                 else
1161                                         echo "$word"
1162                                 fi
1163                                 return
1164                         fi
1165                 done
1166                 ((c++))
1167         done
1168 }
1169
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".
1173 #
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 ()
1177 {
1178         local word c=$cword show_idx
1179
1180         while test $# -gt 1; do
1181                 case "$1" in
1182                 --show-idx)     show_idx=y ;;
1183                 *)              return 1 ;;
1184                 esac
1185                 shift
1186         done
1187         local wordlist="$1"
1188
1189         while [ $c -gt "$__git_cmd_idx" ]; do
1190                 ((c--))
1191                 for word in $wordlist; do
1192                         if [ "$word" = "${words[c]}" ]; then
1193                                 if [ -n "$show_idx" ]; then
1194                                         echo "$c $word"
1195                                 else
1196                                         echo "$word"
1197                                 fi
1198                                 return
1199                         fi
1200                 done
1201         done
1202 }
1203
1204 # Echo the value of an option set on the command line or config
1205 #
1206 # $1: short option name
1207 # $2: long option name including =
1208 # $3: list of possible values
1209 # $4: config string (optional)
1210 #
1211 # example:
1212 # result="$(__git_get_option_value "-d" "--do-something=" \
1213 #     "yes no" "core.doSomething")"
1214 #
1215 # result is then either empty (no option set) or "yes" or "no"
1216 #
1217 # __git_get_option_value requires 3 arguments
1218 __git_get_option_value ()
1219 {
1220         local c short_opt long_opt val
1221         local result= values config_key word
1222
1223         short_opt="$1"
1224         long_opt="$2"
1225         values="$3"
1226         config_key="$4"
1227
1228         ((c = $cword - 1))
1229         while [ $c -ge 0 ]; do
1230                 word="${words[c]}"
1231                 for val in $values; do
1232                         if [ "$short_opt$val" = "$word" ] ||
1233                            [ "$long_opt$val"  = "$word" ]; then
1234                                 result="$val"
1235                                 break 2
1236                         fi
1237                 done
1238                 ((c--))
1239         done
1240
1241         if [ -n "$config_key" ] && [ -z "$result" ]; then
1242                 result="$(__git config "$config_key")"
1243         fi
1244
1245         echo "$result"
1246 }
1247
1248 __git_has_doubledash ()
1249 {
1250         local c=1
1251         while [ $c -lt $cword ]; do
1252                 if [ "--" = "${words[c]}" ]; then
1253                         return 0
1254                 fi
1255                 ((c++))
1256         done
1257         return 1
1258 }
1259
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
1265 # an example:
1266 #       git mv x -n y
1267 #
1268 # __git_count_arguments requires 1 argument: the git command executed.
1269 __git_count_arguments ()
1270 {
1271         local word i c=0
1272
1273         # Skip "git" (first argument)
1274         for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
1275                 word="${words[i]}"
1276
1277                 case "$word" in
1278                         --)
1279                                 # Good; we can assume that the following are only non
1280                                 # option arguments.
1281                                 ((c = 0))
1282                                 ;;
1283                         "$1")
1284                                 # Skip the specified git command and discard git
1285                                 # main options
1286                                 ((c = 0))
1287                                 ;;
1288                         ?*)
1289                                 ((c++))
1290                                 ;;
1291                 esac
1292         done
1293
1294         printf "%d" $c
1295 }
1296
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"
1302
1303 _git_am ()
1304 {
1305         __git_find_repo_path
1306         if [ -d "$__git_repo_path"/rebase-apply ]; then
1307                 __gitcomp_opts "$__git_am_inprogress_options"
1308                 return
1309         fi
1310         case "$cur" in
1311         --whitespace=*)
1312                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1313                 return
1314                 ;;
1315         --patch-format=*)
1316                 __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1317                 return
1318                 ;;
1319         --show-current-patch=*)
1320                 __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
1321                 return
1322                 ;;
1323         --quoted-cr=*)
1324                 __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
1325                 return
1326                 ;;
1327         --*)
1328                 __gitcomp_builtin am "" \
1329                         "$__git_am_inprogress_options"
1330                 return
1331         esac
1332 }
1333
1334 _git_apply ()
1335 {
1336         case "$cur" in
1337         --whitespace=*)
1338                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1339                 return
1340                 ;;
1341         --*)
1342                 __gitcomp_builtin apply
1343                 return
1344         esac
1345 }
1346
1347 _git_add ()
1348 {
1349         case "$cur" in
1350         --chmod=*)
1351                 __gitcomp "+x -x" "" "${cur##--chmod=}"
1352                 return
1353                 ;;
1354         --*)
1355                 __gitcomp_builtin add
1356                 return
1357         esac
1358
1359         local complete_opt="--others --modified --directory --no-empty-directory"
1360         if test -n "$(__git_find_on_cmdline "-u --update")"
1361         then
1362                 complete_opt="--modified"
1363         fi
1364         __git_complete_index_file "$complete_opt"
1365 }
1366
1367 _git_archive ()
1368 {
1369         case "$cur" in
1370         --format=*)
1371                 __gitcomp_nl "$(git archive --list)" "" "${cur##--format=}"
1372                 return
1373                 ;;
1374         --remote=*)
1375                 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1376                 return
1377                 ;;
1378         --*)
1379                 __gitcomp_builtin archive "--format= --list --verbose --prefix= --worktree-attributes"
1380                 return
1381                 ;;
1382         esac
1383         __git_complete_file
1384 }
1385
1386 _git_bisect ()
1387 {
1388         __git_has_doubledash && return
1389
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"
1396                 else
1397                         __gitcomp "replay start"
1398                 fi
1399                 return
1400         fi
1401
1402         case "$subcommand" in
1403         bad|good|reset|skip|start)
1404                 __git_complete_refs
1405                 ;;
1406         *)
1407                 ;;
1408         esac
1409 }
1410
1411 __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1412
1413 _git_branch ()
1414 {
1415         local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1416
1417         while [ $c -lt $cword ]; do
1418                 i="${words[c]}"
1419                 case "$i" in
1420                 -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
1421                         only_local_ref="y" ;;
1422                 -r|--remotes)
1423                         has_r="y" ;;
1424                 esac
1425                 ((c++))
1426         done
1427
1428         case "$cur" in
1429         --set-upstream-to=*)
1430                 __git_complete_refs --cur="${cur##--set-upstream-to=}"
1431                 ;;
1432         --*)
1433                 __gitcomp_builtin branch
1434                 ;;
1435         *)
1436                 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1437                         __gitcomp_direct "$(__git_heads "" "$cur" " ")"
1438                 else
1439                         __git_complete_refs
1440                 fi
1441                 ;;
1442         esac
1443 }
1444
1445 _git_bundle ()
1446 {
1447         local cmd="${words[__git_cmd_idx+1]}"
1448         case "$cword" in
1449         $((__git_cmd_idx+1)))
1450                 __gitcomp "create list-heads verify unbundle"
1451                 ;;
1452         $((__git_cmd_idx+2)))
1453                 # looking for a file
1454                 ;;
1455         *)
1456                 case "$cmd" in
1457                         create)
1458                                 __git_complete_revlist
1459                         ;;
1460                 esac
1461                 ;;
1462         esac
1463 }
1464
1465 # Helper function to decide whether or not we should enable DWIM logic for
1466 # git-switch and git-checkout.
1467 #
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.
1477 #
1478 __git_checkout_default_dwim_mode ()
1479 {
1480         local last_option dwim_opt="--dwim"
1481
1482         if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
1483                 dwim_opt=""
1484         fi
1485
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
1489                 dwim_opt=""
1490         fi
1491
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
1495                 dwim_opt=""
1496         fi
1497
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
1501                 --guess)
1502                         dwim_opt="--dwim"
1503                         ;;
1504                 --no-guess)
1505                         dwim_opt=""
1506                         ;;
1507         esac
1508
1509         echo "$dwim_opt"
1510 }
1511
1512 _git_checkout ()
1513 {
1514         __git_has_doubledash && return
1515
1516         local dwim_opt="$(__git_checkout_default_dwim_mode)"
1517
1518         case "$prev" in
1519         -b|-B|--orphan)
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"
1526                 return
1527                 ;;
1528         *)
1529                 ;;
1530         esac
1531
1532         case "$cur" in
1533         --conflict=*)
1534                 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
1535                 ;;
1536         --*)
1537                 __gitcomp_builtin checkout
1538                 ;;
1539         *)
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
1546                 #
1547
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"
1552                 else
1553                         __git_complete_refs $dwim_opt --mode="refs"
1554                 fi
1555                 ;;
1556         esac
1557 }
1558
1559 __git_sequencer_inprogress_options="--continue --quit --abort --skip"
1560
1561 __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
1562
1563 _git_cherry_pick ()
1564 {
1565         __git_find_repo_path
1566         if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
1567                 __gitcomp_opts "$__git_cherry_pick_inprogress_options"
1568                 return
1569         fi
1570
1571         __git_complete_strategy && return
1572
1573         case "$cur" in
1574         --*)
1575                 __gitcomp_builtin cherry-pick "" \
1576                         "$__git_cherry_pick_inprogress_options"
1577                 ;;
1578         *)
1579                 __git_complete_refs
1580                 ;;
1581         esac
1582 }
1583
1584 _git_clean ()
1585 {
1586         case "$cur" in
1587         --*)
1588                 __gitcomp_builtin clean
1589                 return
1590                 ;;
1591         esac
1592
1593         # XXX should we check for -x option ?
1594         __git_complete_index_file "--others --directory"
1595 }
1596
1597 _git_clone ()
1598 {
1599         case "$prev" in
1600         -c|--config)
1601                 __git_complete_config_variable_name_and_value
1602                 return
1603                 ;;
1604         esac
1605         case "$cur" in
1606         --config=*)
1607                 __git_complete_config_variable_name_and_value \
1608                         --cur="${cur##--config=}"
1609                 return
1610                 ;;
1611         --*)
1612                 __gitcomp_builtin clone
1613                 return
1614                 ;;
1615         esac
1616 }
1617
1618 __git_untracked_file_modes="all no normal"
1619
1620 _git_commit ()
1621 {
1622         case "$prev" in
1623         -c|-C)
1624                 __git_complete_refs
1625                 return
1626                 ;;
1627         esac
1628
1629         case "$cur" in
1630         --cleanup=*)
1631                 __gitcomp "default scissors strip verbatim whitespace
1632                         " "" "${cur##--cleanup=}"
1633                 return
1634                 ;;
1635         --reuse-message=*|--reedit-message=*|\
1636         --fixup=*|--squash=*)
1637                 __git_complete_refs --cur="${cur#*=}"
1638                 return
1639                 ;;
1640         --untracked-files=*)
1641                 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1642                 return
1643                 ;;
1644         --*)
1645                 __gitcomp_builtin commit
1646                 return
1647         esac
1648
1649         if __git rev-parse --verify --quiet HEAD >/dev/null; then
1650                 __git_complete_index_file "--committable"
1651         else
1652                 # This is the first commit
1653                 __git_complete_index_file "--cached"
1654         fi
1655 }
1656
1657 _git_describe ()
1658 {
1659         case "$cur" in
1660         --*)
1661                 __gitcomp_builtin describe
1662                 return
1663         esac
1664         __git_complete_refs
1665 }
1666
1667 __git_diff_algorithms="myers minimal patience histogram"
1668
1669 __git_diff_submodule_formats="diff log short"
1670
1671 __git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
1672
1673 __git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
1674                         ignore-all-space allow-indentation-change"
1675
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
1692                         --diff-algorithm=
1693                         --submodule --submodule= --ignore-submodules
1694                         --indent-heuristic --no-indent-heuristic
1695                         --textconv --no-textconv
1696                         --patch --no-patch
1697                         --anchored=
1698 "
1699
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"
1703
1704 _git_diff ()
1705 {
1706         __git_has_doubledash && return
1707
1708         case "$cur" in
1709         --diff-algorithm=*)
1710                 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1711                 return
1712                 ;;
1713         --submodule=*)
1714                 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
1715                 return
1716                 ;;
1717         --color-moved=*)
1718                 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
1719                 return
1720                 ;;
1721         --color-moved-ws=*)
1722                 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
1723                 return
1724                 ;;
1725         --*)
1726                 __gitcomp_opts "$__git_diff_difftool_options"
1727                 return
1728                 ;;
1729         esac
1730         __git_complete_revlist_file
1731 }
1732
1733 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
1734                         tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
1735                         bc codecompare smerge
1736 "
1737
1738 _git_difftool ()
1739 {
1740         __git_has_doubledash && return
1741
1742         case "$cur" in
1743         --tool=*)
1744                 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1745                 return
1746                 ;;
1747         --*)
1748                 __gitcomp_builtin difftool "$__git_diff_difftool_options"
1749                 return
1750                 ;;
1751         esac
1752         __git_complete_revlist_file
1753 }
1754
1755 __git_fetch_recurse_submodules="yes on-demand no"
1756
1757 _git_fetch ()
1758 {
1759         case "$cur" in
1760         --recurse-submodules=*)
1761                 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1762                 return
1763                 ;;
1764         --filter=*)
1765                 __gitcomp "blob:none blob:limit= sparse:oid=" "" "${cur##--filter=}"
1766                 return
1767                 ;;
1768         --*)
1769                 __gitcomp_builtin fetch
1770                 return
1771                 ;;
1772         esac
1773         __git_complete_remote_or_refspec
1774 }
1775
1776 __git_format_patch_extra_options="
1777         --full-index --not --all --no-prefix --src-prefix=
1778         --dst-prefix= --notes
1779 "
1780
1781 _git_format_patch ()
1782 {
1783         case "$cur" in
1784         --thread=*)
1785                 __gitcomp "deep shallow" "" "${cur##--thread=}"
1786                 return
1787                 ;;
1788         --base=*|--interdiff=*|--range-diff=*)
1789                 __git_complete_refs --cur="${cur#--*=}"
1790                 return
1791                 ;;
1792         --*)
1793                 __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1794                 return
1795                 ;;
1796         esac
1797         __git_complete_revlist
1798 }
1799
1800 _git_fsck ()
1801 {
1802         case "$cur" in
1803         --*)
1804                 __gitcomp_builtin fsck
1805                 return
1806                 ;;
1807         esac
1808 }
1809
1810 _git_gitk ()
1811 {
1812         __gitk_main
1813 }
1814
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 }
1823                 " "$2"
1824 }
1825
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
1829 #                default "tags".
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=" "
1837
1838         while test $# != 0; do
1839                 case "$1" in
1840                 --tags=*)       tags="${1##--tags=}" ;;
1841                 --pfx=*)        pfx="${1##--pfx=}" ;;
1842                 --cur=*)        cur_="${1##--cur=}" ;;
1843                 --sfx=*)        sfx="${1##--sfx=}" ;;
1844                 *)              return 1 ;;
1845                 esac
1846                 shift
1847         done
1848
1849         if test -r "$tags"; then
1850                 __gitcomp_direct "$(__git_match_ctag "$cur_" "$tags" "$pfx" "$sfx")"
1851         fi
1852 }
1853
1854 _git_grep ()
1855 {
1856         __git_has_doubledash && return
1857
1858         case "$cur" in
1859         --*)
1860                 __gitcomp_builtin grep
1861                 return
1862                 ;;
1863         esac
1864
1865         case "$cword,$prev" in
1866         $((__git_cmd_idx+1)),*|*,-*)
1867                 __git_complete_symbol && return
1868                 ;;
1869         esac
1870
1871         __git_complete_refs
1872 }
1873
1874 _git_help ()
1875 {
1876         case "$cur" in
1877         --*)
1878                 __gitcomp_builtin help
1879                 return
1880                 ;;
1881         esac
1882         if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
1883         then
1884                 __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
1885         else
1886                 __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk"
1887         fi
1888 }
1889
1890 _git_init ()
1891 {
1892         case "$cur" in
1893         --shared=*)
1894                 __gitcomp "
1895                         false true umask group all world everybody
1896                         " "" "${cur##--shared=}"
1897                 return
1898                 ;;
1899         --*)
1900                 __gitcomp_builtin init
1901                 return
1902                 ;;
1903         esac
1904 }
1905
1906 _git_ls_files ()
1907 {
1908         case "$cur" in
1909         --*)
1910                 __gitcomp_builtin ls-files
1911                 return
1912                 ;;
1913         esac
1914
1915         # XXX ignore options like --modified and always suggest all cached
1916         # files.
1917         __git_complete_index_file "--cached"
1918 }
1919
1920 _git_ls_remote ()
1921 {
1922         case "$cur" in
1923         --*)
1924                 __gitcomp_builtin ls-remote
1925                 return
1926                 ;;
1927         esac
1928         __gitcomp_nl "$(__git_remotes)"
1929 }
1930
1931 _git_ls_tree ()
1932 {
1933         case "$cur" in
1934         --*)
1935                 __gitcomp_builtin ls-tree
1936                 return
1937                 ;;
1938         esac
1939
1940         __git_complete_file
1941 }
1942
1943 # Options that go well for log, shortlog and gitk
1944 __git_log_common_options="
1945         --not --all
1946         --branches --tags --remotes
1947         --first-parent --merges --no-merges
1948         --max-count=
1949         --max-age= --since= --after=
1950         --min-age= --until= --before=
1951         --min-parents= --max-parents=
1952         --no-min-parents --no-max-parents
1953 "
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
1959 "
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
1964 "
1965
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:"
1968
1969 _git_log ()
1970 {
1971         __git_has_doubledash && return
1972         __git_find_repo_path
1973
1974         local merge=""
1975         if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
1976                 merge="--merge"
1977         fi
1978         case "$prev,$cur" in
1979         -L,:*:*)
1980                 return  # fall back to Bash filename completion
1981                 ;;
1982         -L,:*)
1983                 __git_complete_symbol --cur="${cur#:}" --sfx=":"
1984                 return
1985                 ;;
1986         -G,*|-S,*)
1987                 __git_complete_symbol
1988                 return
1989                 ;;
1990         esac
1991         case "$cur" in
1992         --pretty=*|--format=*)
1993                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1994                         " "" "${cur#*=}"
1995                 return
1996                 ;;
1997         --date=*)
1998                 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1999                 return
2000                 ;;
2001         --decorate=*)
2002                 __gitcomp "full short no" "" "${cur##--decorate=}"
2003                 return
2004                 ;;
2005         --diff-algorithm=*)
2006                 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2007                 return
2008                 ;;
2009         --submodule=*)
2010                 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2011                 return
2012                 ;;
2013         --no-walk=*)
2014                 __gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
2015                 return
2016                 ;;
2017         --*)
2018                 __gitcomp_opts "
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
2027                         --show-signature
2028                         --cherry-mark
2029                         --cherry-pick
2030                         --graph
2031                         --decorate --decorate= --no-decorate
2032                         --walk-reflogs
2033                         --no-walk --no-walk= --do-walk
2034                         --parents --children
2035                         --expand-tabs --expand-tabs= --no-expand-tabs
2036                         $merge
2037                         $__git_diff_common_options
2038                         --pickaxe-all --pickaxe-regex
2039                         "
2040                 return
2041                 ;;
2042         -L:*:*)
2043                 return  # fall back to Bash filename completion
2044                 ;;
2045         -L:*)
2046                 __git_complete_symbol --cur="${cur#-L:}" --sfx=":"
2047                 return
2048                 ;;
2049         -G*)
2050                 __git_complete_symbol --pfx="-G" --cur="${cur#-G}"
2051                 return
2052                 ;;
2053         -S*)
2054                 __git_complete_symbol --pfx="-S" --cur="${cur#-S}"
2055                 return
2056                 ;;
2057         esac
2058         __git_complete_revlist
2059 }
2060
2061 _git_merge ()
2062 {
2063         __git_complete_strategy && return
2064
2065         case "$cur" in
2066         --*)
2067                 __gitcomp_builtin merge
2068                 return
2069         esac
2070         __git_complete_refs
2071 }
2072
2073 _git_mergetool ()
2074 {
2075         case "$cur" in
2076         --tool=*)
2077                 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
2078                 return
2079                 ;;
2080         --*)
2081                 __gitcomp_opts "--tool= --prompt --no-prompt --gui --no-gui"
2082                 return
2083                 ;;
2084         esac
2085 }
2086
2087 _git_merge_base ()
2088 {
2089         case "$cur" in
2090         --*)
2091                 __gitcomp_builtin merge-base
2092                 return
2093                 ;;
2094         esac
2095         __git_complete_refs
2096 }
2097
2098 _git_mv ()
2099 {
2100         case "$cur" in
2101         --*)
2102                 __gitcomp_builtin mv
2103                 return
2104                 ;;
2105         esac
2106
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"
2111         else
2112                 __git_complete_index_file "--cached"
2113         fi
2114 }
2115
2116 _git_notes ()
2117 {
2118         local subcommands='add append copy edit get-ref list merge prune remove show'
2119         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2120
2121         case "$subcommand,$cur" in
2122         ,--*)
2123                 __gitcomp_builtin notes
2124                 ;;
2125         ,*)
2126                 case "$prev" in
2127                 --ref)
2128                         __git_complete_refs
2129                         ;;
2130                 *)
2131                         __gitcomp "$subcommands --ref"
2132                         ;;
2133                 esac
2134                 ;;
2135         *,--reuse-message=*|*,--reedit-message=*)
2136                 __git_complete_refs --cur="${cur#*=}"
2137                 ;;
2138         *,--*)
2139                 __gitcomp_builtin notes_$subcommand
2140                 ;;
2141         prune,*|get-ref,*)
2142                 # this command does not take a ref, do not complete it
2143                 ;;
2144         *)
2145                 case "$prev" in
2146                 -m|-F)
2147                         ;;
2148                 *)
2149                         __git_complete_refs
2150                         ;;
2151                 esac
2152                 ;;
2153         esac
2154 }
2155
2156 _git_pull ()
2157 {
2158         __git_complete_strategy && return
2159
2160         case "$cur" in
2161         --recurse-submodules=*)
2162                 __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
2163                 return
2164                 ;;
2165         --*)
2166                 __gitcomp_builtin pull
2167
2168                 return
2169                 ;;
2170         esac
2171         __git_complete_remote_or_refspec
2172 }
2173
2174 __git_push_recurse_submodules="check on-demand only"
2175
2176 __git_complete_force_with_lease ()
2177 {
2178         local cur_=$1
2179
2180         case "$cur_" in
2181         --*=)
2182                 ;;
2183         *:*)
2184                 __git_complete_refs --cur="${cur_#*:}"
2185                 ;;
2186         *)
2187                 __git_complete_refs --cur="$cur_"
2188                 ;;
2189         esac
2190 }
2191
2192 _git_push ()
2193 {
2194         case "$prev" in
2195         --repo)
2196                 __gitcomp_nl "$(__git_remotes)"
2197                 return
2198                 ;;
2199         --recurse-submodules)
2200                 __gitcomp "$__git_push_recurse_submodules"
2201                 return
2202                 ;;
2203         esac
2204         case "$cur" in
2205         --repo=*)
2206                 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
2207                 return
2208                 ;;
2209         --recurse-submodules=*)
2210                 __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}"
2211                 return
2212                 ;;
2213         --force-with-lease=*)
2214                 __git_complete_force_with_lease "${cur##--force-with-lease=}"
2215                 return
2216                 ;;
2217         --*)
2218                 __gitcomp_builtin push
2219                 return
2220                 ;;
2221         esac
2222         __git_complete_remote_or_refspec
2223 }
2224
2225 _git_range_diff ()
2226 {
2227         case "$cur" in
2228         --*)
2229                 __gitcomp_opts "
2230                         --creation-factor= --no-dual-color
2231                         $__git_diff_common_options
2232                 "
2233                 return
2234                 ;;
2235         esac
2236         __git_complete_revlist
2237 }
2238
2239 __git_rebase_inprogress_options="--continue --skip --abort --quit --show-current-patch"
2240 __git_rebase_interactive_inprogress_options="$__git_rebase_inprogress_options --edit-todo"
2241
2242 _git_rebase ()
2243 {
2244         __git_find_repo_path
2245         if [ -f "$__git_repo_path"/rebase-merge/interactive ]; then
2246                 __gitcomp_opts "$__git_rebase_interactive_inprogress_options"
2247                 return
2248         elif [ -d "$__git_repo_path"/rebase-apply ] || \
2249              [ -d "$__git_repo_path"/rebase-merge ]; then
2250                 __gitcomp_opts "$__git_rebase_inprogress_options"
2251                 return
2252         fi
2253         __git_complete_strategy && return
2254         case "$cur" in
2255         --whitespace=*)
2256                 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
2257                 return
2258                 ;;
2259         --onto=*)
2260                 __git_complete_refs --cur="${cur##--onto=}"
2261                 return
2262                 ;;
2263         --*)
2264                 __gitcomp_builtin rebase "" \
2265                         "$__git_rebase_interactive_inprogress_options"
2266
2267                 return
2268         esac
2269         __git_complete_refs
2270 }
2271
2272 _git_reflog ()
2273 {
2274         local subcommands="show delete expire"
2275         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2276
2277         if [ -z "$subcommand" ]; then
2278                 __gitcomp "$subcommands"
2279         else
2280                 __git_complete_refs
2281         fi
2282 }
2283
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"
2287
2288 _git_send_email ()
2289 {
2290         case "$prev" in
2291         --to|--cc|--bcc|--from)
2292                 __gitcomp_nl "$(__git send-email --dump-aliases)"
2293                 return
2294                 ;;
2295         esac
2296
2297         case "$cur" in
2298         --confirm=*)
2299                 __gitcomp "
2300                         $__git_send_email_confirm_options
2301                         " "" "${cur##--confirm=}"
2302                 return
2303                 ;;
2304         --suppress-cc=*)
2305                 __gitcomp "
2306                         $__git_send_email_suppresscc_options
2307                         " "" "${cur##--suppress-cc=}"
2308
2309                 return
2310                 ;;
2311         --smtp-encryption=*)
2312                 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
2313                 return
2314                 ;;
2315         --thread=*)
2316                 __gitcomp "deep shallow" "" "${cur##--thread=}"
2317                 return
2318                 ;;
2319         --to=*|--cc=*|--bcc=*|--from=*)
2320                 __gitcomp "$(__git send-email --dump-aliases)" "" "${cur#--*=}"
2321                 return
2322                 ;;
2323         --*)
2324                 __gitcomp_builtin send-email "$__git_send_email_options $__git_format_patch_extra_options"
2325                 return
2326                 ;;
2327         esac
2328         __git_complete_revlist
2329 }
2330
2331 _git_stage ()
2332 {
2333         _git_add
2334 }
2335
2336 _git_status ()
2337 {
2338         local complete_opt
2339         local untracked_state
2340
2341         case "$cur" in
2342         --ignore-submodules=*)
2343                 __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}"
2344                 return
2345                 ;;
2346         --untracked-files=*)
2347                 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
2348                 return
2349                 ;;
2350         --column=*)
2351                 __gitcomp "
2352                         always never auto column row plain dense nodense
2353                         " "" "${cur##--column=}"
2354                 return
2355                 ;;
2356         --*)
2357                 __gitcomp_builtin status
2358                 return
2359                 ;;
2360         esac
2361
2362         untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \
2363                 "$__git_untracked_file_modes" "status.showUntrackedFiles")"
2364
2365         case "$untracked_state" in
2366         no)
2367                 # --ignored option does not matter
2368                 complete_opt=
2369                 ;;
2370         all|normal|*)
2371                 complete_opt="--cached --directory --no-empty-directory --others"
2372
2373                 if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then
2374                         complete_opt="$complete_opt --ignored --exclude=*"
2375                 fi
2376                 ;;
2377         esac
2378
2379         __git_complete_index_file "$complete_opt"
2380 }
2381
2382 _git_switch ()
2383 {
2384         local dwim_opt="$(__git_checkout_default_dwim_mode)"
2385
2386         case "$prev" in
2387         -c|-C|--orphan)
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"
2394                 return
2395                 ;;
2396         *)
2397                 ;;
2398         esac
2399
2400         case "$cur" in
2401         --conflict=*)
2402                 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2403                 ;;
2404         --*)
2405                 __gitcomp_builtin switch
2406                 ;;
2407         *)
2408                 # Unlike in git checkout, git switch --orphan does not take
2409                 # a start point. Thus we really have nothing to complete after
2410                 # the branch name.
2411                 if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
2412                         return
2413                 fi
2414
2415                 # At this point, we've already handled special completion for
2416                 # -c/-C, and --orphan. There are 3 main things left to
2417                 # complete:
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
2421
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"
2426                 else
2427                         __git_complete_refs $dwim_opt --mode="heads"
2428                 fi
2429                 ;;
2430         esac
2431 }
2432
2433 __git_config_get_set_variables ()
2434 {
2435         local prevword word config_file= c=$cword
2436         while [ $c -gt "$__git_cmd_idx" ]; do
2437                 word="${words[c]}"
2438                 case "$word" in
2439                 --system|--global|--local|--file=*)
2440                         config_file="$word"
2441                         break
2442                         ;;
2443                 -f|--file)
2444                         config_file="$word $prevword"
2445                         break
2446                         ;;
2447                 esac
2448                 prevword=$word
2449                 c=$((--c))
2450         done
2451
2452         __git config $config_file --name-only --list
2453 }
2454
2455 __git_config_vars=
2456 __git_compute_config_vars ()
2457 {
2458         test -n "$__git_config_vars" ||
2459         __git_config_vars="$(git help --config-for-completion | sort -u)"
2460 }
2461
2462 # Completes possible values of various configuration variables.
2463 #
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
2467 #                   command line.
2468 # --cur=<word>: The current value to be completed.  Defaults to the current
2469 #               word to be completed.
2470 __git_complete_config_variable_value ()
2471 {
2472         local varname="$prev" cur_="$cur"
2473
2474         while test $# != 0; do
2475                 case "$1" in
2476                 --varname=*)    varname="${1##--varname=}" ;;
2477                 --cur=*)        cur_="${1##--cur=}" ;;
2478                 *)              return 1 ;;
2479                 esac
2480                 shift
2481         done
2482
2483         if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
2484                 varname="${varname,,}"
2485         else
2486                 varname="$(echo "$varname" |tr A-Z a-z)"
2487         fi
2488
2489         case "$varname" in
2490         branch.*.remote|branch.*.pushremote)
2491                 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2492                 return
2493                 ;;
2494         branch.*.merge)
2495                 __git_complete_refs --cur="$cur_"
2496                 return
2497                 ;;
2498         branch.*.rebase)
2499                 __gitcomp "false true merges interactive" "" "$cur_"
2500                 return
2501                 ;;
2502         remote.pushdefault)
2503                 __gitcomp_nl "$(__git_remotes)" "" "$cur_"
2504                 return
2505                 ;;
2506         remote.*.fetch)
2507                 local remote="${varname#remote.}"
2508                 remote="${remote%.fetch}"
2509                 if [ -z "$cur_" ]; then
2510                         __gitcomp_nl "refs/heads/" "" "" ""
2511                         return
2512                 fi
2513                 __gitcomp_nl "$(__git_refs_remotes "$remote")" "" "$cur_"
2514                 return
2515                 ;;
2516         remote.*.push)
2517                 local remote="${varname#remote.}"
2518                 remote="${remote%.push}"
2519                 __gitcomp_nl "$(__git for-each-ref \
2520                         --format='%(refname):%(refname)' refs/heads)" "" "$cur_"
2521                 return
2522                 ;;
2523         pull.twohead|pull.octopus)
2524                 __git_compute_merge_strategies
2525                 __gitcomp "$__git_merge_strategies" "" "$cur_"
2526                 return
2527                 ;;
2528         color.pager)
2529                 __gitcomp "false true" "" "$cur_"
2530                 return
2531                 ;;
2532         color.*.*)
2533                 __gitcomp "
2534                         normal black red green yellow blue magenta cyan white
2535                         bold dim ul blink reverse
2536                         " "" "$cur_"
2537                 return
2538                 ;;
2539         color.*)
2540                 __gitcomp "false true always never auto" "" "$cur_"
2541                 return
2542                 ;;
2543         diff.submodule)
2544                 __gitcomp "$__git_diff_submodule_formats" "" "$cur_"
2545                 return
2546                 ;;
2547         help.format)
2548                 __gitcomp "man info web html" "" "$cur_"
2549                 return
2550                 ;;
2551         log.date)
2552                 __gitcomp "$__git_log_date_formats" "" "$cur_"
2553                 return
2554                 ;;
2555         sendemail.aliasfiletype)
2556                 __gitcomp "mutt mailrc pine elm gnus" "" "$cur_"
2557                 return
2558                 ;;
2559         sendemail.confirm)
2560                 __gitcomp "$__git_send_email_confirm_options" "" "$cur_"
2561                 return
2562                 ;;
2563         sendemail.suppresscc)
2564                 __gitcomp "$__git_send_email_suppresscc_options" "" "$cur_"
2565                 return
2566                 ;;
2567         sendemail.transferencoding)
2568                 __gitcomp "7bit 8bit quoted-printable base64" "" "$cur_"
2569                 return
2570                 ;;
2571         *.*)
2572                 return
2573                 ;;
2574         esac
2575 }
2576
2577 # Completes configuration sections, subsections, variable names.
2578 #
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 ()
2586 {
2587         local cur_="$cur" sfx=" "
2588
2589         while test $# != 0; do
2590                 case "$1" in
2591                 --cur=*)        cur_="${1##--cur=}" ;;
2592                 --sfx=*)        sfx="${1##--sfx=}" ;;
2593                 *)              return 1 ;;
2594                 esac
2595                 shift
2596         done
2597
2598         case "$cur_" in
2599         branch.*.*)
2600                 local pfx="${cur_%.*}."
2601                 cur_="${cur_##*.}"
2602                 __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
2603                 return
2604                 ;;
2605         branch.*)
2606                 local pfx="${cur_%.*}."
2607                 cur_="${cur_#*.}"
2608                 __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
2609                 __gitcomp "autoSetupMerge autoSetupRebase" "$pfx" "$cur_" "$sfx"
2610                 return
2611                 ;;
2612         guitool.*.*)
2613                 local pfx="${cur_%.*}."
2614                 cur_="${cur_##*.}"
2615                 __gitcomp "
2616                         argPrompt cmd confirm needsFile noConsole noRescan
2617                         prompt revPrompt revUnmerged title
2618                         " "$pfx" "$cur_" "$sfx"
2619                 return
2620                 ;;
2621         difftool.*.*)
2622                 local pfx="${cur_%.*}."
2623                 cur_="${cur_##*.}"
2624                 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2625                 return
2626                 ;;
2627         man.*.*)
2628                 local pfx="${cur_%.*}."
2629                 cur_="${cur_##*.}"
2630                 __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
2631                 return
2632                 ;;
2633         mergetool.*.*)
2634                 local pfx="${cur_%.*}."
2635                 cur_="${cur_##*.}"
2636                 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
2637                 return
2638                 ;;
2639         pager.*)
2640                 local pfx="${cur_%.*}."
2641                 cur_="${cur_#*.}"
2642                 __git_compute_all_commands
2643                 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
2644                 return
2645                 ;;
2646         remote.*.*)
2647                 local pfx="${cur_%.*}."
2648                 cur_="${cur_##*.}"
2649                 __gitcomp "
2650                         url proxy fetch push mirror skipDefaultUpdate
2651                         receivepack uploadpack tagOpt pushurl
2652                         " "$pfx" "$cur_" "$sfx"
2653                 return
2654                 ;;
2655         remote.*)
2656                 local pfx="${cur_%.*}."
2657                 cur_="${cur_#*.}"
2658                 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
2659                 __gitcomp "pushDefault" "$pfx" "$cur_" "$sfx"
2660                 return
2661                 ;;
2662         url.*.*)
2663                 local pfx="${cur_%.*}."
2664                 cur_="${cur_##*.}"
2665                 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
2666                 return
2667                 ;;
2668         *.*)
2669                 __git_compute_config_vars
2670                 __gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
2671                 ;;
2672         *)
2673                 __git_compute_config_vars
2674                 __gitcomp_nl "$(echo "$__git_config_vars" |
2675                                 awk -F . '{
2676                                         sections[$1] = 1
2677                                 }
2678                                 END {
2679                                         for (s in sections)
2680                                                 print s "."
2681                                 }
2682                                 ')" "" "$cur_" ""
2683                 ;;
2684         esac
2685 }
2686
2687 # Completes '='-separated configuration sections/variable names and values
2688 # for 'git -c section.name=value'.
2689 #
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 ()
2694 {
2695         local cur_="$cur"
2696
2697         while test $# != 0; do
2698                 case "$1" in
2699                 --cur=*)        cur_="${1##--cur=}" ;;
2700                 *)              return 1 ;;
2701                 esac
2702                 shift
2703         done
2704
2705         case "$cur_" in
2706         *=*)
2707                 __git_complete_config_variable_value \
2708                         --varname="${cur_%%=*}" --cur="${cur_#*=}"
2709                 ;;
2710         *)
2711                 __git_complete_config_variable_name --cur="$cur_" --sfx='='
2712                 ;;
2713         esac
2714 }
2715
2716 _git_config ()
2717 {
2718         case "$prev" in
2719         --get|--get-all|--unset|--unset-all)
2720                 __gitcomp_nl "$(__git_config_get_set_variables)"
2721                 return
2722                 ;;
2723         *.*)
2724                 __git_complete_config_variable_value
2725                 return
2726                 ;;
2727         esac
2728         case "$cur" in
2729         --*)
2730                 __gitcomp_builtin config
2731                 ;;
2732         *)
2733                 __git_complete_config_variable_name
2734                 ;;
2735         esac
2736 }
2737
2738 _git_remote ()
2739 {
2740         local subcommands="
2741                 add rename remove set-head set-branches
2742                 get-url set-url show prune update
2743                 "
2744         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2745         if [ -z "$subcommand" ]; then
2746                 case "$cur" in
2747                 --*)
2748                         __gitcomp_builtin remote
2749                         ;;
2750                 *)
2751                         __gitcomp "$subcommands"
2752                         ;;
2753                 esac
2754                 return
2755         fi
2756
2757         case "$subcommand,$cur" in
2758         add,--*)
2759                 __gitcomp_builtin remote_add
2760                 ;;
2761         add,*)
2762                 ;;
2763         set-head,--*)
2764                 __gitcomp_builtin remote_set-head
2765                 ;;
2766         set-branches,--*)
2767                 __gitcomp_builtin remote_set-branches
2768                 ;;
2769         set-head,*|set-branches,*)
2770                 __git_complete_remote_or_refspec
2771                 ;;
2772         update,--*)
2773                 __gitcomp_builtin remote_update
2774                 ;;
2775         update,*)
2776                 __gitcomp_nl "$(__git_remotes) $(__git_get_config_variables "remotes")"
2777                 ;;
2778         set-url,--*)
2779                 __gitcomp_builtin remote_set-url
2780                 ;;
2781         get-url,--*)
2782                 __gitcomp_builtin remote_get-url
2783                 ;;
2784         prune,--*)
2785                 __gitcomp_builtin remote_prune
2786                 ;;
2787         *)
2788                 __gitcomp_nl "$(__git_remotes)"
2789                 ;;
2790         esac
2791 }
2792
2793 _git_replace ()
2794 {
2795         case "$cur" in
2796         --format=*)
2797                 __gitcomp "short medium long" "" "${cur##--format=}"
2798                 return
2799                 ;;
2800         --*)
2801                 __gitcomp_builtin replace
2802                 return
2803                 ;;
2804         esac
2805         __git_complete_refs
2806 }
2807
2808 _git_rerere ()
2809 {
2810         local subcommands="clear forget diff remaining status gc"
2811         local subcommand="$(__git_find_on_cmdline "$subcommands")"
2812         if test -z "$subcommand"
2813         then
2814                 __gitcomp "$subcommands"
2815                 return
2816         fi
2817 }
2818
2819 _git_reset ()
2820 {
2821         __git_has_doubledash && return
2822
2823         case "$cur" in
2824         --*)
2825                 __gitcomp_builtin reset
2826                 return
2827                 ;;
2828         esac
2829         __git_complete_refs
2830 }
2831
2832 _git_restore ()
2833 {
2834         case "$prev" in
2835         -s)
2836                 __git_complete_refs
2837                 return
2838                 ;;
2839         esac
2840
2841         case "$cur" in
2842         --conflict=*)
2843                 __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
2844                 ;;
2845         --source=*)
2846                 __git_complete_refs --cur="${cur##--source=}"
2847                 ;;
2848         --*)
2849                 __gitcomp_builtin restore
2850                 ;;
2851         *)
2852                 if __git rev-parse --verify --quiet HEAD >/dev/null; then
2853                         __git_complete_index_file "--modified"
2854                 fi
2855         esac
2856 }
2857
2858 __git_revert_inprogress_options=$__git_sequencer_inprogress_options
2859
2860 _git_revert ()
2861 {
2862         __git_find_repo_path
2863         if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
2864                 __gitcomp_opts "$__git_revert_inprogress_options"
2865                 return
2866         fi
2867         __git_complete_strategy && return
2868         case "$cur" in
2869         --*)
2870                 __gitcomp_builtin revert "" \
2871                         "$__git_revert_inprogress_options"
2872                 return
2873                 ;;
2874         esac
2875         __git_complete_refs
2876 }
2877
2878 _git_rm ()
2879 {
2880         case "$cur" in
2881         --*)
2882                 __gitcomp_builtin rm
2883                 return
2884                 ;;
2885         esac
2886
2887         __git_complete_index_file "--cached"
2888 }
2889
2890 _git_shortlog ()
2891 {
2892         __git_has_doubledash && return
2893
2894         case "$cur" in
2895         --*)
2896                 __gitcomp_opts "
2897                         $__git_log_common_options
2898                         $__git_log_shortlog_options
2899                         --numbered --summary --email
2900                         "
2901                 return
2902                 ;;
2903         esac
2904         __git_complete_revlist
2905 }
2906
2907 _git_show ()
2908 {
2909         __git_has_doubledash && return
2910
2911         case "$cur" in
2912         --pretty=*|--format=*)
2913                 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2914                         " "" "${cur#*=}"
2915                 return
2916                 ;;
2917         --diff-algorithm=*)
2918                 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2919                 return
2920                 ;;
2921         --submodule=*)
2922                 __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
2923                 return
2924                 ;;
2925         --color-moved=*)
2926                 __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
2927                 return
2928                 ;;
2929         --color-moved-ws=*)
2930                 __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
2931                 return
2932                 ;;
2933         --*)
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
2938                         "
2939                 return
2940                 ;;
2941         esac
2942         __git_complete_revlist_file
2943 }
2944
2945 _git_show_branch ()
2946 {
2947         case "$cur" in
2948         --*)
2949                 __gitcomp_builtin show-branch
2950                 return
2951                 ;;
2952         esac
2953         __git_complete_revlist
2954 }
2955
2956 __gitcomp_directories ()
2957 {
2958         local _tmp_dir _tmp_completions _found=0
2959
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
2962         # that's fine too.
2963         [[ "$cur" =~ .*/ ]]
2964         _tmp_dir=$BASH_REMATCH
2965
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
2972                         COMPREPLY+=("$c/")
2973                         _found=1
2974                 fi
2975         done < <(git ls-tree -z -d --name-only HEAD $_tmp_dir)
2976
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 "
2981         fi
2982 }
2983
2984 _git_sparse_checkout ()
2985 {
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"
2990                 return
2991         fi
2992
2993         case "$subcommand,$cur" in
2994         *,--*)
2995                 __gitcomp_builtin sparse-checkout_$subcommand "" "--"
2996                 ;;
2997         set,*|add,*)
2998                 if [ "$(__git config core.sparseCheckoutCone)" == "true" ] ||
2999                 [ -n "$(__git_find_on_cmdline --cone)" ]; then
3000                         __gitcomp_directories
3001                 fi
3002         esac
3003 }
3004
3005 _git_stash ()
3006 {
3007         local subcommands='push list show apply clear drop pop create branch'
3008         local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3009
3010         if [ -z "$subcommand" ]; then
3011                 case "$((cword - __git_cmd_idx)),$cur" in
3012                 *,--*)
3013                         __gitcomp_builtin stash_push
3014                         ;;
3015                 1,sa*)
3016                         __gitcomp "save"
3017                         ;;
3018                 1,*)
3019                         __gitcomp "$subcommands"
3020                         ;;
3021                 esac
3022                 return
3023         fi
3024
3025         case "$subcommand,$cur" in
3026         list,--*)
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"
3029                 ;;
3030         show,--*)
3031                 __gitcomp_builtin stash_show "$__git_diff_common_options"
3032                 ;;
3033         *,--*)
3034                 __gitcomp_builtin "stash_$subcommand"
3035                 ;;
3036         branch,*)
3037                 if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3038                         __git_complete_refs
3039                 else
3040                         __gitcomp_nl "$(__git stash list \
3041                                         | sed -n -e 's/:.*//p')"
3042                 fi
3043                 ;;
3044         show,*|apply,*|drop,*|pop,*)
3045                 __gitcomp_nl "$(__git stash list \
3046                                 | sed -n -e 's/:.*//p')"
3047                 ;;
3048         esac
3049 }
3050
3051 _git_submodule ()
3052 {
3053         __git_has_doubledash && return
3054
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
3058                 case "$cur" in
3059                 --*)
3060                         __gitcomp_opts "--quiet"
3061                         ;;
3062                 *)
3063                         __gitcomp "$subcommands"
3064                         ;;
3065                 esac
3066                 return
3067         fi
3068
3069         case "$subcommand,$cur" in
3070         add,--*)
3071                 __gitcomp_opts "--branch --force --name --reference --depth"
3072                 ;;
3073         status,--*)
3074                 __gitcomp_opts "--cached --recursive"
3075                 ;;
3076         deinit,--*)
3077                 __gitcomp_opts "--force --all"
3078                 ;;
3079         update,--*)
3080                 __gitcomp_opts "
3081                         --init --remote --no-fetch
3082                         --recommend-shallow --no-recommend-shallow
3083                         --force --rebase --merge --reference --depth --recursive --jobs
3084                 "
3085                 ;;
3086         set-branch,--*)
3087                 __gitcomp_opts "--default --branch"
3088                 ;;
3089         summary,--*)
3090                 __gitcomp_opts "--cached --files --summary-limit"
3091                 ;;
3092         foreach,--*|sync,--*)
3093                 __gitcomp_opts "--recursive"
3094                 ;;
3095         *)
3096                 ;;
3097         esac
3098 }
3099
3100 _git_svn ()
3101 {
3102         local subcommands="
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
3107                 "
3108         local subcommand="$(__git_find_on_cmdline "$subcommands")"
3109         if [ -z "$subcommand" ]; then
3110                 __gitcomp "$subcommands"
3111         else
3112                 local remote_opts="--username= --config-dir= --no-auth-cache"
3113                 local fc_opts="
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
3118                         --add-author-from
3119                         --recursive
3120                         --ignore-paths= --include-paths= $remote_opts
3121                         "
3122                 local init_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
3127                         "
3128                 local cmt_opts="
3129                         --edit --rmdir --find-copies-harder --copy-similarity=
3130                         "
3131
3132                 case "$subcommand,$cur" in
3133                 fetch,--*)
3134                         __gitcomp_opts "--revision= --fetch-all $fc_opts"
3135                         ;;
3136                 clone,--*)
3137                         __gitcomp_opts "--revision= $fc_opts $init_opts"
3138                         ;;
3139                 init,--*)
3140                         __gitcomp_opts "$init_opts"
3141                         ;;
3142                 dcommit,--*)
3143                         __gitcomp_opts "
3144                                 --merge --strategy= --verbose --dry-run
3145                                 --fetch-all --no-rebase --commit-url
3146                                 --revision --interactive $cmt_opts $fc_opts
3147                                 "
3148                         ;;
3149                 set-tree,--*)
3150                         __gitcomp_opts "--stdin $cmt_opts $fc_opts"
3151                         ;;
3152                 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
3153                 show-externals,--*|mkdirs,--*)
3154                         __gitcomp_opts "--revision="
3155                         ;;
3156                 log,--*)
3157                         __gitcomp_opts "
3158                                 --limit= --revision= --verbose --incremental
3159                                 --oneline --show-commit --non-recursive
3160                                 --authors-file= --color
3161                                 "
3162                         ;;
3163                 rebase,--*)
3164                         __gitcomp_opts "
3165                                 --merge --verbose --strategy= --local
3166                                 --fetch-all --dry-run $fc_opts
3167                                 "
3168                         ;;
3169                 commit-diff,--*)
3170                         __gitcomp_opts "--message= --file= --revision= $cmt_opts"
3171                         ;;
3172                 info,--*)
3173                         __gitcomp_opts "--url"
3174                         ;;
3175                 branch,--*)
3176                         __gitcomp_opts "--dry-run --message --tag"
3177                         ;;
3178                 tag,--*)
3179                         __gitcomp_opts "--dry-run --message"
3180                         ;;
3181                 blame,--*)
3182                         __gitcomp_opts "--git-format"
3183                         ;;
3184                 migrate,--*)
3185                         __gitcomp_opts "
3186                                 --config-dir= --ignore-paths= --minimize
3187                                 --no-auth-cache --username=
3188                                 "
3189                         ;;
3190                 reset,--*)
3191                         __gitcomp_opts "--revision= --parent"
3192                         ;;
3193                 *)
3194                         ;;
3195                 esac
3196         fi
3197 }
3198
3199 _git_tag ()
3200 {
3201         local i c="$__git_cmd_idx" f=0
3202         while [ $c -lt $cword ]; do
3203                 i="${words[c]}"
3204                 case "$i" in
3205                 -d|--delete|-v|--verify)
3206                         __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3207                         return
3208                         ;;
3209                 -f)
3210                         f=1
3211                         ;;
3212                 esac
3213                 ((c++))
3214         done
3215
3216         case "$prev" in
3217         -m|-F)
3218                 ;;
3219         -*|tag)
3220                 if [ $f = 1 ]; then
3221                         __gitcomp_direct "$(__git_tags "" "$cur" " ")"
3222                 fi
3223                 ;;
3224         *)
3225                 __git_complete_refs
3226                 ;;
3227         esac
3228
3229         case "$cur" in
3230         --*)
3231                 __gitcomp_builtin tag
3232                 ;;
3233         esac
3234 }
3235
3236 _git_whatchanged ()
3237 {
3238         _git_log
3239 }
3240
3241 __git_complete_worktree_paths ()
3242 {
3243         local IFS=$'\n'
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')"
3249 }
3250
3251 _git_worktree ()
3252 {
3253         local subcommands="add list lock move prune remove unlock"
3254         local subcommand subcommand_idx
3255
3256         subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3257         subcommand_idx="${subcommand% *}"
3258         subcommand="${subcommand#* }"
3259
3260         case "$subcommand,$cur" in
3261         ,*)
3262                 __gitcomp "$subcommands"
3263                 ;;
3264         *,--*)
3265                 __gitcomp_builtin worktree_$subcommand
3266                 ;;
3267         add,*)  # usage: git worktree add [<options>] <path> [<commit-ish>]
3268                 # Here we are not completing an --option, it's either the
3269                 # path or a ref.
3270                 case "$prev" in
3271                 -b|-B)  # Complete refs for branch to be created/reset.
3272                         __git_complete_refs
3273                         ;;
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.
3278                         ;;
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.
3287                                 :
3288                         else
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.
3293                                         ;;
3294                                 *)      # After the path: have to complete
3295                                         # the ref to be checked out.
3296                                         __git_complete_refs
3297                                         ;;
3298                                 esac
3299                         fi
3300                         ;;
3301                 esac
3302                 ;;
3303         lock,*|remove,*|unlock,*)
3304                 __git_complete_worktree_paths
3305                 ;;
3306         move,*)
3307                 if [ $cword -eq $((subcommand_idx+1)) ]; then
3308                         # The first parameter must be an existing working
3309                         # tree to be moved.
3310                         __git_complete_worktree_paths
3311                 else
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.
3315                         :
3316                 fi
3317                 ;;
3318         esac
3319 }
3320
3321 __git_complete_common () {
3322         local command="$1"
3323
3324         case "$cur" in
3325         --*)
3326                 __gitcomp_builtin "$command"
3327                 ;;
3328         esac
3329 }
3330
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)"
3335
3336         case " $__git_cmds_with_parseopt_helper " in
3337         *" $1 "*)
3338                 return 0
3339                 ;;
3340         *)
3341                 return 1
3342                 ;;
3343         esac
3344 }
3345
3346 __git_have_func () {
3347         declare -f -- "$1" >/dev/null 2>&1
3348 }
3349
3350 __git_complete_command () {
3351         local command="$1"
3352         local completion_func="_git_${command//-/_}"
3353         if ! __git_have_func $completion_func &&
3354                 __git_have_func _completion_loader
3355         then
3356                 _completion_loader "git-$command"
3357         fi
3358         if __git_have_func $completion_func
3359         then
3360                 $completion_func
3361                 return 0
3362         elif __git_support_parseopt_helper "$command"
3363         then
3364                 __git_complete_common "$command"
3365                 return 0
3366         else
3367                 return 1
3368         fi
3369 }
3370
3371 __git_main ()
3372 {
3373         local i c=1 command __git_dir __git_repo_path
3374         local __git_C_args C_args_count=0
3375         local __git_cmd_idx
3376
3377         while [ $c -lt $cword ]; do
3378                 i="${words[c]}"
3379                 case "$i" in
3380                 --git-dir=*)
3381                         __git_dir="${i#--git-dir=}"
3382                         ;;
3383                 --git-dir)
3384                         ((c++))
3385                         __git_dir="${words[c]}"
3386                         ;;
3387                 --bare)
3388                         __git_dir="."
3389                         ;;
3390                 --help)
3391                         command="help"
3392                         break
3393                         ;;
3394                 -c|--work-tree|--namespace)
3395                         ((c++))
3396                         ;;
3397                 -C)
3398                         __git_C_args[C_args_count++]=-C
3399                         ((c++))
3400                         __git_C_args[C_args_count++]="${words[c]}"
3401                         ;;
3402                 -*)
3403                         ;;
3404                 *)
3405                         command="$i"
3406                         __git_cmd_idx="$c"
3407                         break
3408                         ;;
3409                 esac
3410                 ((c++))
3411         done
3412
3413         if [ -z "${command-}" ]; then
3414                 case "$prev" in
3415                 --git-dir|-C|--work-tree)
3416                         # these need a path argument, let's fall back to
3417                         # Bash filename completion
3418                         return
3419                         ;;
3420                 -c)
3421                         __git_complete_config_variable_name_and_value
3422                         return
3423                         ;;
3424                 --namespace)
3425                         # we don't support completing these options' arguments
3426                         return
3427                         ;;
3428                 esac
3429                 case "$cur" in
3430                 --*)
3431                         __gitcomp_opts "
3432                         --paginate
3433                         --no-pager
3434                         --git-dir=
3435                         --bare
3436                         --version
3437                         --exec-path
3438                         --exec-path=
3439                         --html-path
3440                         --man-path
3441                         --info-path
3442                         --work-tree=
3443                         --namespace=
3444                         --no-replace-objects
3445                         --help
3446                         "
3447                         ;;
3448                 *)
3449                         if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
3450                         then
3451                                 __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
3452                         else
3453                                 local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
3454
3455                                 if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
3456                                 then
3457                                         list_cmds=builtins,$list_cmds
3458                                 fi
3459                                 __gitcomp_nl "$(__git --list-cmds=$list_cmds)"
3460                         fi
3461                         ;;
3462                 esac
3463                 return
3464         fi
3465
3466         __git_complete_command "$command" && return
3467
3468         local expansion=$(__git_aliased_command "$command")
3469         if [ -n "$expansion" ]; then
3470                 words[1]=$expansion
3471                 __git_complete_command "$expansion"
3472         fi
3473 }
3474
3475 __gitk_main ()
3476 {
3477         __git_has_doubledash && return
3478
3479         local __git_repo_path
3480         __git_find_repo_path
3481
3482         local merge=""
3483         if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
3484                 merge="--merge"
3485         fi
3486         case "$cur" in
3487         --*)
3488                 __gitcomp_opts "
3489                         $__git_log_common_options
3490                         $__git_log_gitk_options
3491                         $merge
3492                         "
3493                 return
3494                 ;;
3495         esac
3496         __git_complete_revlist
3497 }
3498
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
3501         return
3502 fi
3503
3504 # The following function is based on code from:
3505 #
3506 #   bash_completion - programmable completion functions for bash 3.2+
3507 #
3508 #   Copyright Â© 2006-2008, Ian Macdonald <ian@caliban.org>
3509 #             Â© 2009-2010, Bash Completion Maintainers
3510 #                     <bash-completion-devel@lists.alioth.debian.org>
3511 #
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.
3516 #
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.
3521 #
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/>.
3524 #
3525 #   The latest version of this software can be obtained here:
3526 #
3527 #   http://bash-completion.alioth.debian.org/
3528 #
3529 #   RELEASE: 2.x
3530
3531 # This function reorganizes the words on the command line to be processed by
3532 # the rest of the script.
3533 #
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.
3538 #
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.
3543
3544 if ! type __git_get_comp_words_by_ref >/dev/null 2>&1; then
3545 __git_get_comp_words_by_ref ()
3546 {
3547         local exclude i j first
3548
3549         # Which word separators to exclude?
3550         exclude="${COMP_WORDBREAKS//[^=:]}"
3551         cword=$COMP_CWORD
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.
3558                         first=t
3559                         while
3560                                 [ $i -gt 0 ] &&
3561                                 [ -n "${COMP_WORDS[$i]}" ] &&
3562                                 # word consists of excluded word separators
3563                                 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
3564                         do
3565                                 # Attach to the previous token,
3566                                 # unless the previous token is the command name.
3567                                 if [ $j -ge 2 ] && [ -n "$first" ]; then
3568                                         ((j--))
3569                                 fi
3570                                 first=
3571                                 words[$j]=${words[j]}${COMP_WORDS[i]}
3572                                 if [ $i = $COMP_CWORD ]; then
3573                                         cword=$j
3574                                 fi
3575                                 if (($i < ${#COMP_WORDS[@]} - 1)); then
3576                                         ((i++))
3577                                 else
3578                                         # Done.
3579                                         break 2
3580                                 fi
3581                         done
3582                         words[$j]=${words[j]}${COMP_WORDS[i]}
3583                         if [ $i = $COMP_CWORD ]; then
3584                                 cword=$j
3585                         fi
3586                 done
3587         else
3588                 words=("${COMP_WORDS[@]}")
3589         fi
3590
3591         cur=${words[cword]}
3592         prev=${words[cword-1]}
3593 }
3594 fi
3595
3596 __git_func_wrap ()
3597 {
3598         local cur words cword prev __git_cmd_idx=0
3599         __git_get_comp_words_by_ref
3600         $1
3601 }
3602
3603 ___git_complete ()
3604 {
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
3609 }
3610
3611 # Setup the completion for git commands
3612 # 1: command or alias
3613 # 2: function to call (e.g. `git`, `gitk`, `git_fetch`)
3614 __git_complete ()
3615 {
3616         local func
3617
3618         if __git_have_func $2; then
3619                 func=$2
3620         elif __git_have_func __$2_main; then
3621                 func=__$2_main
3622         elif __git_have_func _$2; then
3623                 func=_$2
3624         else
3625                 echo "ERROR: could not find function '$2'" 1>&2
3626                 return 1
3627         fi
3628         ___git_complete $1 $func
3629 }
3630
3631 if ! git --list-cmds=main >/dev/null 2>&1; then
3632
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 "
3640
3641         # Override __git
3642         __git ()
3643         {
3644                 case "$1" in
3645                 --list-cmds=*)
3646                         while read -r -d ',' x; do
3647                                 case "$x" in
3648                                 nohelpers)
3649                                         ;;
3650                                 alias)
3651                                         ;;
3652                                 config)
3653                                         ;;
3654                                 *)
3655                                         echo ${__git_cmds[$x]}
3656                                         ;;
3657                                 esac
3658                         done <<< "${1##--list-cmds=},"
3659                         return
3660                         ;;
3661                 esac
3662                 git ${__git_C_args:+"${__git_C_args[@]}"} \
3663                         ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
3664         }
3665
3666 fi
3667
3668 ___git_complete git __git_main
3669 ___git_complete gitk __gitk_main
3670
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.
3674 #
3675 if [ "$OSTYPE" = cygwin ]; then
3676         ___git_complete git.exe __git_main
3677 fi