summaryrefslogtreecommitdiff
path: root/contrib/completion/git-completion.bash
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/completion/git-completion.bash')
-rw-r--r--contrib/completion/git-completion.bash162
1 files changed, 135 insertions, 27 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e4d9ff4a95..b1d6e5ebed 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -504,7 +504,7 @@ __git_index_files ()
{
local root="$2" match="$3"
- __git_ls_files_helper "$root" "$1" "$match" |
+ __git_ls_files_helper "$root" "$1" "${match:-?}" |
awk -F / -v pfx="${2//\\/\\\\}" '{
paths[$1] = 1
}
@@ -1069,15 +1069,32 @@ __git_aliased_command ()
done
}
-# __git_find_on_cmdline requires 1 argument
+# Check whether one of the given words is present on the command line,
+# and print the first word found.
+#
+# Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
+# --show-idx: Optionally show the index of the found word in the $words array.
__git_find_on_cmdline ()
{
- local word subcommand c=1
+ local word c=1 show_idx
+
+ while test $# -gt 1; do
+ case "$1" in
+ --show-idx) show_idx=y ;;
+ *) return 1 ;;
+ esac
+ shift
+ done
+ local wordlist="$1"
+
while [ $c -lt $cword ]; do
- word="${words[c]}"
- for subcommand in $1; do
- if [ "$subcommand" = "$word" ]; then
- echo "$subcommand"
+ for word in $wordlist; do
+ if [ "$word" = "${words[c]}" ]; then
+ if [ -n "$show_idx" ]; then
+ echo "$c $word"
+ else
+ echo "$word"
+ fi
return
fi
done
@@ -1180,6 +1197,7 @@ __git_count_arguments ()
__git_whitespacelist="nowarn warn error error-all fix"
__git_patchformat="mbox stgit stgit-series hg mboxrd"
+__git_showcurrentpatch="diff raw"
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
_git_am ()
@@ -1198,6 +1216,10 @@ _git_am ()
__gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
return
;;
+ --show-current-patch=*)
+ __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
+ return
+ ;;
--*)
__gitcomp_builtin am "" \
"$__git_am_inprogress_options"
@@ -1470,9 +1492,16 @@ __git_diff_algorithms="myers minimal patience histogram"
__git_diff_submodule_formats="diff log short"
+__git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
+
+__git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
+ ignore-all-space allow-indentation-change"
+
__git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
+ --color-moved --color-moved= --no-color-moved
+ --color-moved-ws= --no-color-moved-ws
--full-index --binary --abbrev --diff-filter=
--find-copies-harder --ignore-cr-at-eol
--text --ignore-space-at-eol --ignore-space-change
@@ -1503,6 +1532,14 @@ _git_diff ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --color-moved=*)
+ __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
+ return
+ ;;
+ --color-moved-ws=*)
+ __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
+ return
+ ;;
--*)
__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
--base --ours --theirs --no-index
@@ -2718,6 +2755,27 @@ _git_show_branch ()
__git_complete_revlist
}
+_git_sparse_checkout ()
+{
+ local subcommands="list init set disable"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand,$cur" in
+ init,--*)
+ __gitcomp "--cone"
+ ;;
+ set,--*)
+ __gitcomp "--stdin"
+ ;;
+ *)
+ ;;
+ esac
+}
+
_git_stash ()
{
local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
@@ -2969,33 +3027,83 @@ _git_whatchanged ()
_git_log
}
+__git_complete_worktree_paths ()
+{
+ local IFS=$'\n'
+ __gitcomp_nl "$(git worktree list --porcelain |
+ # Skip the first entry: it's the path of the main worktree,
+ # which can't be moved, removed, locked, etc.
+ sed -n -e '2,$ s/^worktree //p')"
+}
+
_git_worktree ()
{
local subcommands="add list lock move prune remove unlock"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
- if [ -z "$subcommand" ]; then
+ local subcommand subcommand_idx
+
+ subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
+ subcommand_idx="${subcommand% *}"
+ subcommand="${subcommand#* }"
+
+ case "$subcommand,$cur" in
+ ,*)
__gitcomp "$subcommands"
- else
- case "$subcommand,$cur" in
- add,--*)
- __gitcomp_builtin worktree_add
- ;;
- list,--*)
- __gitcomp_builtin worktree_list
- ;;
- lock,--*)
- __gitcomp_builtin worktree_lock
- ;;
- prune,--*)
- __gitcomp_builtin worktree_prune
- ;;
- remove,--*)
- __gitcomp "--force"
+ ;;
+ *,--*)
+ __gitcomp_builtin worktree_$subcommand
+ ;;
+ add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
+ # Here we are not completing an --option, it's either the
+ # path or a ref.
+ case "$prev" in
+ -b|-B) # Complete refs for branch to be created/reseted.
+ __git_complete_refs
;;
- *)
+ -*) # The previous word is an -o|--option without an
+ # unstuck argument: have to complete the path for
+ # the new worktree, so don't list anything, but let
+ # Bash fall back to filename completion.
+ ;;
+ *) # The previous word is not an --option, so it must
+ # be either the 'add' subcommand, the unstuck
+ # argument of an option (e.g. branch for -b|-B), or
+ # the path for the new worktree.
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
+ # Right after the 'add' subcommand: have to
+ # complete the path, so fall back to Bash
+ # filename completion.
+ :
+ else
+ case "${words[cword-2]}" in
+ -b|-B) # After '-b <branch>': have to
+ # complete the path, so fall back
+ # to Bash filename completion.
+ ;;
+ *) # After the path: have to complete
+ # the ref to be checked out.
+ __git_complete_refs
+ ;;
+ esac
+ fi
;;
esac
- fi
+ ;;
+ lock,*|remove,*|unlock,*)
+ __git_complete_worktree_paths
+ ;;
+ move,*)
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
+ # The first parameter must be an existing working
+ # tree to be moved.
+ __git_complete_worktree_paths
+ else
+ # The second parameter is the destination: it could
+ # be any path, so don't list anything, but let Bash
+ # fall back to filename completion.
+ :
+ fi
+ ;;
+ esac
}
__git_complete_common () {