3 # Copyright (c) 2012 Felipe Contreras
6 test_description='test bash completion'
16 . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash"
18 # We don't need this function to actually join words or do anything special.
19 # Also, it's cleaner to avoid touching bash's internal completion variables.
20 # So let's override it with a minimal version for testing purposes.
21 _get_comp_words_by_ref ()
23 while [ $# -gt 0 ]; do
29 prev=${_words[_cword-1]}
32 words=("${_words[@]}")
45 echo "${COMPREPLY[*]}" > out
50 local -a COMPREPLY _words
53 (( _cword = ${#_words[@]} - 1 ))
54 __git_wrap__git_main && print_comp
59 test $# -gt 1 && echo "$2" > expected
60 run_completion "$@" &&
66 test_expect_success '__gitcomp - trailing space - options' '
67 sed -e "s/Z$//" >expected <<-\EOF &&
75 __gitcomp "--dry-run --reuse-message= --reedit-message=
78 echo "${COMPREPLY[*]}" > out
83 test_expect_success '__gitcomp - trailing space - config keys' '
84 sed -e "s/Z$//" >expected <<-\EOF &&
86 branch.autosetupmerge Z
87 branch.autosetuprebase Z
93 __gitcomp "branch. branch.autosetupmerge
94 branch.autosetuprebase browser." &&
96 echo "${COMPREPLY[*]}" > out
101 test_expect_success '__gitcomp - option parameter' '
102 sed -e "s/Z$//" >expected <<-\EOF &&
107 local -a COMPREPLY &&
108 cur="--strategy=re" &&
109 __gitcomp "octopus ours recursive resolve subtree
112 echo "${COMPREPLY[*]}" > out
114 test_cmp expected out
117 test_expect_success '__gitcomp - prefix' '
118 sed -e "s/Z$//" >expected <<-\EOF &&
120 branch.maint.mergeoptions Z
123 local -a COMPREPLY &&
125 __gitcomp "remote merge mergeoptions rebase
126 " "branch.maint." "me" &&
128 echo "${COMPREPLY[*]}" > out
130 test_cmp expected out
133 test_expect_success '__gitcomp - suffix' '
134 sed -e "s/Z$//" >expected <<-\EOF &&
139 local -a COMPREPLY &&
141 __gitcomp "master maint next pu
142 " "branch." "ma" "." &&
144 echo "${COMPREPLY[*]}" > out
146 test_cmp expected out
149 test_expect_success 'basic' '
150 run_completion "git \"\"" &&
152 grep -q "^add \$" out &&
154 grep -q "^filter-branch \$" out &&
156 ! grep -q "^ls-files \$" out &&
158 run_completion "git f" &&
159 ! grep -q -v "^f" out
162 test_expect_success 'double dash "git" itself' '
163 sed -e "s/Z$//" >expected <<-\EOF &&
175 --no-replace-objects Z
178 test_completion "git --"
181 test_expect_success 'double dash "git checkout"' '
182 sed -e "s/Z$//" >expected <<-\EOF &&
193 test_completion "git checkout --"
196 test_expect_success 'general options' '
197 test_completion "git --ver" "--version " &&
198 test_completion "git --hel" "--help " &&
199 sed -e "s/Z$//" >expected <<-\EOF &&
203 test_completion "git --exe" &&
204 test_completion "git --htm" "--html-path " &&
205 test_completion "git --pag" "--paginate " &&
206 test_completion "git --no-p" "--no-pager " &&
207 test_completion "git --git" "--git-dir=" &&
208 test_completion "git --wor" "--work-tree=" &&
209 test_completion "git --nam" "--namespace=" &&
210 test_completion "git --bar" "--bare " &&
211 test_completion "git --inf" "--info-path " &&
212 test_completion "git --no-r" "--no-replace-objects "
215 test_expect_success 'general options plus command' '
216 test_completion "git --version check" "checkout " &&
217 test_completion "git --paginate check" "checkout " &&
218 test_completion "git --git-dir=foo check" "checkout " &&
219 test_completion "git --bare check" "checkout " &&
220 test_completion "git --help des" "describe " &&
221 test_completion "git --exec-path=foo check" "checkout " &&
222 test_completion "git --html-path check" "checkout " &&
223 test_completion "git --no-pager check" "checkout " &&
224 test_completion "git --work-tree=foo check" "checkout " &&
225 test_completion "git --namespace=foo check" "checkout " &&
226 test_completion "git --paginate check" "checkout " &&
227 test_completion "git --info-path check" "checkout " &&
228 test_completion "git --no-replace-objects check" "checkout "