]>
Commit | Line | Data |
---|---|---|
5c293a6b FC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 Felipe Contreras | |
4 | # | |
5 | ||
5c293a6b FC |
6 | test_description='test bash completion' |
7 | ||
f8891cfa | 8 | . ./lib-bash.sh |
5c293a6b FC |
9 | |
10 | complete () | |
11 | { | |
12 | # do nothing | |
13 | return 0 | |
14 | } | |
15 | ||
50478223 JH |
16 | # Be careful when updating this list: |
17 | # | |
18 | # (1) The build tree may have build artifact from different branch, or | |
19 | # the user's $PATH may have a random executable that may begin | |
20 | # with "git-check" that are not part of the subcommands this build | |
21 | # will ship, e.g. "check-ignore". The tests for completion for | |
22 | # subcommand names tests how "check" is expanded; we limit the | |
23 | # possible candidates to "checkout" and "check-attr" to make sure | |
24 | # "check-attr", which is known by the filter function as a | |
25 | # subcommand to be thrown out, while excluding other random files | |
26 | # that happen to begin with "check" to avoid letting them get in | |
27 | # the way. | |
28 | # | |
29 | # (2) A test makes sure that common subcommands are included in the | |
30 | # completion for "git <TAB>", and a plumbing is excluded. "add", | |
31 | # "filter-branch" and "ls-files" are listed for this. | |
32 | ||
33 | GIT_TESTING_COMMAND_COMPLETION='add checkout check-attr filter-branch ls-files' | |
34 | ||
5c293a6b FC |
35 | . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" |
36 | ||
37 | # We don't need this function to actually join words or do anything special. | |
38 | # Also, it's cleaner to avoid touching bash's internal completion variables. | |
39 | # So let's override it with a minimal version for testing purposes. | |
40 | _get_comp_words_by_ref () | |
41 | { | |
42 | while [ $# -gt 0 ]; do | |
43 | case "$1" in | |
44 | cur) | |
45 | cur=${_words[_cword]} | |
46 | ;; | |
47 | prev) | |
48 | prev=${_words[_cword-1]} | |
49 | ;; | |
50 | words) | |
51 | words=("${_words[@]}") | |
52 | ;; | |
53 | cword) | |
54 | cword=$_cword | |
55 | ;; | |
56 | esac | |
57 | shift | |
58 | done | |
59 | } | |
60 | ||
61 | print_comp () | |
62 | { | |
63 | local IFS=$'\n' | |
64 | echo "${COMPREPLY[*]}" > out | |
65 | } | |
66 | ||
67 | run_completion () | |
68 | { | |
69 | local -a COMPREPLY _words | |
70 | local _cword | |
71 | _words=( $1 ) | |
0ef09702 | 72 | test "${1: -1}" = ' ' && _words[${#_words[@]}+1]='' |
5c293a6b | 73 | (( _cword = ${#_words[@]} - 1 )) |
93b291e0 | 74 | __git_wrap__git_main && print_comp |
5c293a6b FC |
75 | } |
76 | ||
701ecdf1 FC |
77 | # Test high-level completion |
78 | # Arguments are: | |
79 | # 1: typed text so far (cur) | |
80 | # 2: expected completion | |
5c293a6b FC |
81 | test_completion () |
82 | { | |
2fbaf813 FC |
83 | if test $# -gt 1 |
84 | then | |
85 | printf '%s\n' "$2" >expected | |
86 | else | |
87 | sed -e 's/Z$//' >expected | |
88 | fi && | |
701ecdf1 | 89 | run_completion "$1" && |
5c293a6b FC |
90 | test_cmp expected out |
91 | } | |
92 | ||
e4615238 FC |
93 | # Test __gitcomp. |
94 | # The first argument is the typed text so far (cur); the rest are | |
95 | # passed to __gitcomp. Expected output comes is read from the | |
96 | # standard input, like test_completion(). | |
97 | test_gitcomp () | |
49ba92b4 | 98 | { |
17393033 | 99 | local -a COMPREPLY && |
e4615238 | 100 | sed -e 's/Z$//' >expected && |
eac90623 | 101 | local cur="$1" && |
17393033 FC |
102 | shift && |
103 | __gitcomp "$@" && | |
104 | print_comp && | |
74a8c849 | 105 | test_cmp expected out |
49ba92b4 JK |
106 | } |
107 | ||
43369a22 FC |
108 | # Test __gitcomp_nl |
109 | # Arguments are: | |
110 | # 1: current word (cur) | |
111 | # -: the rest are passed to __gitcomp_nl | |
112 | test_gitcomp_nl () | |
113 | { | |
114 | local -a COMPREPLY && | |
115 | sed -e 's/Z$//' >expected && | |
eac90623 | 116 | local cur="$1" && |
43369a22 FC |
117 | shift && |
118 | __gitcomp_nl "$@" && | |
119 | print_comp && | |
120 | test_cmp expected out | |
121 | } | |
122 | ||
123 | invalid_variable_name='${foo.bar}' | |
124 | ||
c9a102e8 SG |
125 | actual="$TRASH_DIRECTORY/actual" |
126 | ||
f6114408 SG |
127 | if test_have_prereq MINGW |
128 | then | |
129 | ROOT="$(pwd -W)" | |
130 | else | |
131 | ROOT="$(pwd)" | |
132 | fi | |
133 | ||
fad9484f | 134 | test_expect_success 'setup for __git_find_repo_path/__gitdir tests' ' |
c9a102e8 | 135 | mkdir -p subdir/subsubdir && |
fad9484f | 136 | mkdir -p non-repo && |
c9a102e8 SG |
137 | git init otherrepo |
138 | ' | |
139 | ||
fad9484f | 140 | test_expect_success '__git_find_repo_path - from command line (through $__git_dir)' ' |
f6114408 | 141 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 142 | ( |
f6114408 | 143 | __git_dir="$ROOT/otherrepo/.git" && |
fad9484f SG |
144 | __git_find_repo_path && |
145 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 146 | ) && |
c9a102e8 SG |
147 | test_cmp expected "$actual" |
148 | ' | |
149 | ||
fad9484f | 150 | test_expect_success '__git_find_repo_path - .git directory in cwd' ' |
c9a102e8 | 151 | echo ".git" >expected && |
beb6ee71 | 152 | ( |
fad9484f SG |
153 | __git_find_repo_path && |
154 | echo "$__git_repo_path" >"$actual" | |
beb6ee71 | 155 | ) && |
c9a102e8 SG |
156 | test_cmp expected "$actual" |
157 | ' | |
158 | ||
fad9484f | 159 | test_expect_success '__git_find_repo_path - .git directory in parent' ' |
f6114408 | 160 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
161 | ( |
162 | cd subdir/subsubdir && | |
fad9484f SG |
163 | __git_find_repo_path && |
164 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
165 | ) && |
166 | test_cmp expected "$actual" | |
167 | ' | |
168 | ||
fad9484f | 169 | test_expect_success '__git_find_repo_path - cwd is a .git directory' ' |
c9a102e8 SG |
170 | echo "." >expected && |
171 | ( | |
172 | cd .git && | |
fad9484f SG |
173 | __git_find_repo_path && |
174 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
175 | ) && |
176 | test_cmp expected "$actual" | |
177 | ' | |
178 | ||
fad9484f | 179 | test_expect_success '__git_find_repo_path - parent is a .git directory' ' |
f6114408 | 180 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
181 | ( |
182 | cd .git/refs/heads && | |
fad9484f SG |
183 | __git_find_repo_path && |
184 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
185 | ) && |
186 | test_cmp expected "$actual" | |
187 | ' | |
188 | ||
fad9484f | 189 | test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in cwd' ' |
f6114408 | 190 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 191 | ( |
f6114408 | 192 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 | 193 | export GIT_DIR && |
fad9484f SG |
194 | __git_find_repo_path && |
195 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
196 | ) && |
197 | test_cmp expected "$actual" | |
198 | ' | |
199 | ||
fad9484f | 200 | test_expect_success '__git_find_repo_path - $GIT_DIR set while .git directory in parent' ' |
f6114408 | 201 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 202 | ( |
f6114408 | 203 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
204 | export GIT_DIR && |
205 | cd subdir && | |
fad9484f SG |
206 | __git_find_repo_path && |
207 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
208 | ) && |
209 | test_cmp expected "$actual" | |
210 | ' | |
211 | ||
fad9484f | 212 | test_expect_success '__git_find_repo_path - from command line while "git -C"' ' |
80ac0744 SG |
213 | echo "$ROOT/.git" >expected && |
214 | ( | |
215 | __git_dir="$ROOT/.git" && | |
216 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
217 | __git_find_repo_path && |
218 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
219 | ) && |
220 | test_cmp expected "$actual" | |
221 | ' | |
222 | ||
fad9484f | 223 | test_expect_success '__git_find_repo_path - relative dir from command line and "git -C"' ' |
80ac0744 SG |
224 | echo "$ROOT/otherrepo/.git" >expected && |
225 | ( | |
226 | cd subdir && | |
227 | __git_dir="otherrepo/.git" && | |
228 | __git_C_args=(-C ..) && | |
fad9484f SG |
229 | __git_find_repo_path && |
230 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
231 | ) && |
232 | test_cmp expected "$actual" | |
233 | ' | |
234 | ||
fad9484f | 235 | test_expect_success '__git_find_repo_path - $GIT_DIR set while "git -C"' ' |
80ac0744 SG |
236 | echo "$ROOT/.git" >expected && |
237 | ( | |
238 | GIT_DIR="$ROOT/.git" && | |
239 | export GIT_DIR && | |
240 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
241 | __git_find_repo_path && |
242 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
243 | ) && |
244 | test_cmp expected "$actual" | |
245 | ' | |
246 | ||
fad9484f | 247 | test_expect_success '__git_find_repo_path - relative dir in $GIT_DIR and "git -C"' ' |
80ac0744 SG |
248 | echo "$ROOT/otherrepo/.git" >expected && |
249 | ( | |
250 | cd subdir && | |
251 | GIT_DIR="otherrepo/.git" && | |
252 | export GIT_DIR && | |
253 | __git_C_args=(-C ..) && | |
fad9484f SG |
254 | __git_find_repo_path && |
255 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
256 | ) && |
257 | test_cmp expected "$actual" | |
258 | ' | |
259 | ||
fad9484f | 260 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in cwd' ' |
80ac0744 SG |
261 | echo "$ROOT/otherrepo/.git" >expected && |
262 | ( | |
263 | __git_C_args=(-C otherrepo) && | |
fad9484f SG |
264 | __git_find_repo_path && |
265 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
266 | ) && |
267 | test_cmp expected "$actual" | |
268 | ' | |
269 | ||
fad9484f | 270 | test_expect_success '__git_find_repo_path - "git -C" while cwd is a .git directory' ' |
80ac0744 SG |
271 | echo "$ROOT/otherrepo/.git" >expected && |
272 | ( | |
273 | cd .git && | |
274 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
275 | __git_find_repo_path && |
276 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
277 | ) && |
278 | test_cmp expected "$actual" | |
279 | ' | |
280 | ||
fad9484f | 281 | test_expect_success '__git_find_repo_path - "git -C" while .git directory in parent' ' |
80ac0744 SG |
282 | echo "$ROOT/otherrepo/.git" >expected && |
283 | ( | |
284 | cd subdir && | |
285 | __git_C_args=(-C .. -C otherrepo) && | |
fad9484f SG |
286 | __git_find_repo_path && |
287 | echo "$__git_repo_path" >"$actual" | |
80ac0744 SG |
288 | ) && |
289 | test_cmp expected "$actual" | |
290 | ' | |
291 | ||
fad9484f | 292 | test_expect_success '__git_find_repo_path - non-existing path in "git -C"' ' |
80ac0744 SG |
293 | ( |
294 | __git_C_args=(-C non-existing) && | |
fad9484f SG |
295 | test_must_fail __git_find_repo_path && |
296 | printf "$__git_repo_path" >"$actual" | |
80ac0744 SG |
297 | ) && |
298 | test_must_be_empty "$actual" | |
299 | ' | |
300 | ||
fad9484f | 301 | test_expect_success '__git_find_repo_path - non-existing path in $__git_dir' ' |
a2f03b0e SG |
302 | ( |
303 | __git_dir="non-existing" && | |
fad9484f SG |
304 | test_must_fail __git_find_repo_path && |
305 | printf "$__git_repo_path" >"$actual" | |
a2f03b0e SG |
306 | ) && |
307 | test_must_be_empty "$actual" | |
308 | ' | |
309 | ||
fad9484f | 310 | test_expect_success '__git_find_repo_path - non-existing $GIT_DIR' ' |
c9a102e8 | 311 | ( |
f6114408 | 312 | GIT_DIR="$ROOT/non-existing" && |
c9a102e8 | 313 | export GIT_DIR && |
fad9484f SG |
314 | test_must_fail __git_find_repo_path && |
315 | printf "$__git_repo_path" >"$actual" | |
8f0fa85d SG |
316 | ) && |
317 | test_must_be_empty "$actual" | |
c9a102e8 SG |
318 | ' |
319 | ||
fad9484f | 320 | test_expect_success '__git_find_repo_path - gitfile in cwd' ' |
f6114408 SG |
321 | echo "$ROOT/otherrepo/.git" >expected && |
322 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
323 | test_when_finished "rm -f subdir/.git" && |
324 | ( | |
325 | cd subdir && | |
fad9484f SG |
326 | __git_find_repo_path && |
327 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
328 | ) && |
329 | test_cmp expected "$actual" | |
330 | ' | |
331 | ||
fad9484f | 332 | test_expect_success '__git_find_repo_path - gitfile in parent' ' |
f6114408 SG |
333 | echo "$ROOT/otherrepo/.git" >expected && |
334 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
335 | test_when_finished "rm -f subdir/.git" && |
336 | ( | |
337 | cd subdir/subsubdir && | |
fad9484f SG |
338 | __git_find_repo_path && |
339 | echo "$__git_repo_path" >"$actual" | |
c9a102e8 SG |
340 | ) && |
341 | test_cmp expected "$actual" | |
342 | ' | |
343 | ||
fad9484f | 344 | test_expect_success SYMLINKS '__git_find_repo_path - resulting path avoids symlinks' ' |
f6114408 | 345 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 SG |
346 | mkdir otherrepo/dir && |
347 | test_when_finished "rm -rf otherrepo/dir" && | |
348 | ln -s otherrepo/dir link && | |
349 | test_when_finished "rm -f link" && | |
350 | ( | |
351 | cd link && | |
fad9484f SG |
352 | __git_find_repo_path && |
353 | echo "$__git_repo_path" >"$actual" | |
354 | ) && | |
355 | test_cmp expected "$actual" | |
356 | ' | |
357 | ||
358 | test_expect_success '__git_find_repo_path - not a git repository' ' | |
359 | ( | |
360 | cd non-repo && | |
361 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
362 | export GIT_CEILING_DIRECTORIES && | |
363 | test_must_fail __git_find_repo_path && | |
364 | printf "$__git_repo_path" >"$actual" | |
365 | ) && | |
366 | test_must_be_empty "$actual" | |
367 | ' | |
368 | ||
369 | test_expect_success '__gitdir - finds repo' ' | |
370 | echo "$ROOT/.git" >expected && | |
371 | ( | |
372 | cd subdir/subsubdir && | |
c9a102e8 SG |
373 | __gitdir >"$actual" |
374 | ) && | |
375 | test_cmp expected "$actual" | |
376 | ' | |
377 | ||
fad9484f SG |
378 | |
379 | test_expect_success '__gitdir - returns error when cant find repo' ' | |
380 | ( | |
381 | __git_dir="non-existing" && | |
382 | test_must_fail __gitdir >"$actual" | |
383 | ) && | |
8f0fa85d | 384 | test_must_be_empty "$actual" |
c9a102e8 SG |
385 | ' |
386 | ||
fad9484f SG |
387 | test_expect_success '__gitdir - repo as argument' ' |
388 | echo "otherrepo/.git" >expected && | |
389 | ( | |
390 | __gitdir "otherrepo" >"$actual" | |
391 | ) && | |
392 | test_cmp expected "$actual" | |
393 | ' | |
394 | ||
395 | test_expect_success '__gitdir - remote as argument' ' | |
396 | echo "remote" >expected && | |
397 | ( | |
398 | __gitdir "remote" >"$actual" | |
399 | ) && | |
400 | test_cmp expected "$actual" | |
401 | ' | |
402 | ||
74a8c849 | 403 | test_expect_success '__gitcomp - trailing space - options' ' |
e4615238 FC |
404 | test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= |
405 | --reset-author" <<-EOF | |
74a8c849 SG |
406 | --reuse-message=Z |
407 | --reedit-message=Z | |
408 | --reset-author Z | |
409 | EOF | |
74a8c849 SG |
410 | ' |
411 | ||
412 | test_expect_success '__gitcomp - trailing space - config keys' ' | |
e4615238 FC |
413 | test_gitcomp "br" "branch. branch.autosetupmerge |
414 | branch.autosetuprebase browser." <<-\EOF | |
74a8c849 SG |
415 | branch.Z |
416 | branch.autosetupmerge Z | |
417 | branch.autosetuprebase Z | |
418 | browser.Z | |
419 | EOF | |
74a8c849 SG |
420 | ' |
421 | ||
422 | test_expect_success '__gitcomp - option parameter' ' | |
e4615238 FC |
423 | test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ |
424 | "" "re" <<-\EOF | |
74a8c849 SG |
425 | recursive Z |
426 | resolve Z | |
427 | EOF | |
74a8c849 SG |
428 | ' |
429 | ||
430 | test_expect_success '__gitcomp - prefix' ' | |
e4615238 FC |
431 | test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ |
432 | "branch.maint." "me" <<-\EOF | |
74a8c849 SG |
433 | branch.maint.merge Z |
434 | branch.maint.mergeoptions Z | |
435 | EOF | |
74a8c849 SG |
436 | ' |
437 | ||
438 | test_expect_success '__gitcomp - suffix' ' | |
e4615238 FC |
439 | test_gitcomp "branch.me" "master maint next pu" "branch." \ |
440 | "ma" "." <<-\EOF | |
74a8c849 SG |
441 | branch.master.Z |
442 | branch.maint.Z | |
443 | EOF | |
74a8c849 SG |
444 | ' |
445 | ||
7d13e0a3 | 446 | test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' |
43369a22 FC |
447 | __gitcomp "$invalid_variable_name" |
448 | ' | |
449 | ||
450 | read -r -d "" refs <<-\EOF | |
451 | maint | |
452 | master | |
453 | next | |
454 | pu | |
455 | EOF | |
456 | ||
457 | test_expect_success '__gitcomp_nl - trailing space' ' | |
458 | test_gitcomp_nl "m" "$refs" <<-EOF | |
459 | maint Z | |
460 | master Z | |
461 | EOF | |
462 | ' | |
463 | ||
464 | test_expect_success '__gitcomp_nl - prefix' ' | |
465 | test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF | |
466 | --fixup=maint Z | |
467 | --fixup=master Z | |
468 | EOF | |
469 | ' | |
470 | ||
471 | test_expect_success '__gitcomp_nl - suffix' ' | |
472 | test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF | |
473 | branch.maint.Z | |
474 | branch.master.Z | |
475 | EOF | |
476 | ' | |
477 | ||
478 | test_expect_success '__gitcomp_nl - no suffix' ' | |
479 | test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF | |
480 | maintZ | |
481 | masterZ | |
482 | EOF | |
483 | ' | |
484 | ||
7d13e0a3 | 485 | test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' |
43369a22 FC |
486 | __gitcomp_nl "$invalid_variable_name" |
487 | ' | |
488 | ||
2acc1940 SG |
489 | test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' |
490 | cat >expect <<-EOF && | |
491 | remote_from_file_1 | |
492 | remote_from_file_2 | |
493 | remote_in_config_1 | |
494 | remote_in_config_2 | |
495 | EOF | |
496 | test_when_finished "rm -rf .git/remotes" && | |
497 | mkdir -p .git/remotes && | |
498 | >.git/remotes/remote_from_file_1 && | |
499 | >.git/remotes/remote_from_file_2 && | |
500 | test_when_finished "git remote remove remote_in_config_1" && | |
501 | git remote add remote_in_config_1 git://remote_1 && | |
502 | test_when_finished "git remote remove remote_in_config_2" && | |
503 | git remote add remote_in_config_2 git://remote_2 && | |
beb6ee71 SG |
504 | ( |
505 | __git_remotes >actual | |
506 | ) && | |
2acc1940 SG |
507 | test_cmp expect actual |
508 | ' | |
509 | ||
69a77596 SG |
510 | test_expect_success '__git_is_configured_remote' ' |
511 | test_when_finished "git remote remove remote_1" && | |
512 | git remote add remote_1 git://remote_1 && | |
513 | test_when_finished "git remote remove remote_2" && | |
514 | git remote add remote_2 git://remote_2 && | |
beb6ee71 SG |
515 | ( |
516 | verbose __git_is_configured_remote remote_2 && | |
517 | test_must_fail __git_is_configured_remote non-existent | |
518 | ) | |
69a77596 SG |
519 | ' |
520 | ||
fb9cd420 SG |
521 | test_expect_success 'setup for ref completion' ' |
522 | git commit --allow-empty -m initial && | |
523 | git branch matching-branch && | |
524 | git tag matching-tag && | |
525 | ( | |
526 | cd otherrepo && | |
527 | git commit --allow-empty -m initial && | |
528 | git branch -m master master-in-other && | |
529 | git branch branch-in-other && | |
530 | git tag tag-in-other | |
531 | ) && | |
532 | git remote add other "$ROOT/otherrepo/.git" && | |
533 | git fetch --no-tags other && | |
534 | rm -f .git/FETCH_HEAD && | |
535 | git init thirdrepo | |
536 | ' | |
537 | ||
538 | test_expect_success '__git_refs - simple' ' | |
539 | cat >expected <<-EOF && | |
540 | HEAD | |
541 | master | |
542 | matching-branch | |
543 | other/branch-in-other | |
544 | other/master-in-other | |
545 | matching-tag | |
546 | EOF | |
547 | ( | |
548 | cur= && | |
549 | __git_refs >"$actual" | |
550 | ) && | |
551 | test_cmp expected "$actual" | |
552 | ' | |
553 | ||
554 | test_expect_success '__git_refs - full refs' ' | |
555 | cat >expected <<-EOF && | |
556 | refs/heads/master | |
557 | refs/heads/matching-branch | |
558 | EOF | |
559 | ( | |
560 | cur=refs/heads/ && | |
561 | __git_refs >"$actual" | |
562 | ) && | |
563 | test_cmp expected "$actual" | |
564 | ' | |
565 | ||
566 | test_expect_success '__git_refs - repo given on the command line' ' | |
567 | cat >expected <<-EOF && | |
568 | HEAD | |
569 | branch-in-other | |
570 | master-in-other | |
571 | tag-in-other | |
572 | EOF | |
573 | ( | |
574 | __git_dir="$ROOT/otherrepo/.git" && | |
575 | cur= && | |
576 | __git_refs >"$actual" | |
577 | ) && | |
578 | test_cmp expected "$actual" | |
579 | ' | |
580 | ||
581 | test_expect_success '__git_refs - remote on local file system' ' | |
582 | cat >expected <<-EOF && | |
583 | HEAD | |
584 | branch-in-other | |
585 | master-in-other | |
586 | tag-in-other | |
587 | EOF | |
588 | ( | |
589 | cur= && | |
590 | __git_refs otherrepo >"$actual" | |
591 | ) && | |
592 | test_cmp expected "$actual" | |
593 | ' | |
594 | ||
595 | test_expect_success '__git_refs - remote on local file system - full refs' ' | |
596 | cat >expected <<-EOF && | |
597 | refs/heads/branch-in-other | |
598 | refs/heads/master-in-other | |
599 | refs/tags/tag-in-other | |
600 | EOF | |
601 | ( | |
602 | cur=refs/ && | |
603 | __git_refs otherrepo >"$actual" | |
604 | ) && | |
605 | test_cmp expected "$actual" | |
606 | ' | |
607 | ||
608 | test_expect_success '__git_refs - configured remote' ' | |
609 | cat >expected <<-EOF && | |
610 | HEAD | |
611 | branch-in-other | |
612 | master-in-other | |
613 | EOF | |
614 | ( | |
615 | cur= && | |
616 | __git_refs other >"$actual" | |
617 | ) && | |
618 | test_cmp expected "$actual" | |
619 | ' | |
620 | ||
621 | test_expect_success '__git_refs - configured remote - full refs' ' | |
622 | cat >expected <<-EOF && | |
623 | refs/heads/branch-in-other | |
624 | refs/heads/master-in-other | |
625 | refs/tags/tag-in-other | |
626 | EOF | |
627 | ( | |
628 | cur=refs/ && | |
629 | __git_refs other >"$actual" | |
630 | ) && | |
631 | test_cmp expected "$actual" | |
632 | ' | |
633 | ||
5c12f642 | 634 | test_expect_success '__git_refs - configured remote - repo given on the command line' ' |
fb9cd420 SG |
635 | cat >expected <<-EOF && |
636 | HEAD | |
637 | branch-in-other | |
638 | master-in-other | |
639 | EOF | |
640 | ( | |
641 | cd thirdrepo && | |
642 | __git_dir="$ROOT/.git" && | |
643 | cur= && | |
644 | __git_refs other >"$actual" | |
645 | ) && | |
646 | test_cmp expected "$actual" | |
647 | ' | |
648 | ||
5c12f642 | 649 | test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' |
fb9cd420 SG |
650 | cat >expected <<-EOF && |
651 | refs/heads/branch-in-other | |
652 | refs/heads/master-in-other | |
653 | refs/tags/tag-in-other | |
654 | EOF | |
655 | ( | |
656 | cd thirdrepo && | |
657 | __git_dir="$ROOT/.git" && | |
658 | cur=refs/ && | |
659 | __git_refs other >"$actual" | |
660 | ) && | |
661 | test_cmp expected "$actual" | |
662 | ' | |
663 | ||
69a77596 | 664 | test_expect_success '__git_refs - configured remote - remote name matches a directory' ' |
fb9cd420 SG |
665 | cat >expected <<-EOF && |
666 | HEAD | |
667 | branch-in-other | |
668 | master-in-other | |
669 | EOF | |
670 | mkdir other && | |
671 | test_when_finished "rm -rf other" && | |
672 | ( | |
673 | cur= && | |
674 | __git_refs other >"$actual" | |
675 | ) && | |
676 | test_cmp expected "$actual" | |
677 | ' | |
678 | ||
91b7ea81 | 679 | test_expect_success '__git_refs - URL remote' ' |
fb9cd420 SG |
680 | cat >expected <<-EOF && |
681 | HEAD | |
682 | branch-in-other | |
683 | master-in-other | |
684 | tag-in-other | |
685 | EOF | |
686 | ( | |
687 | cur= && | |
688 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
689 | ) && | |
690 | test_cmp expected "$actual" | |
691 | ' | |
692 | ||
693 | test_expect_success '__git_refs - URL remote - full refs' ' | |
694 | cat >expected <<-EOF && | |
695 | refs/heads/branch-in-other | |
696 | refs/heads/master-in-other | |
697 | refs/tags/tag-in-other | |
698 | EOF | |
699 | ( | |
700 | cur=refs/ && | |
701 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
702 | ) && | |
703 | test_cmp expected "$actual" | |
704 | ' | |
705 | ||
91b7ea81 | 706 | test_expect_success '__git_refs - non-existing remote' ' |
fb9cd420 SG |
707 | ( |
708 | cur= && | |
709 | __git_refs non-existing >"$actual" | |
710 | ) && | |
711 | test_must_be_empty "$actual" | |
712 | ' | |
713 | ||
714 | test_expect_success '__git_refs - non-existing remote - full refs' ' | |
715 | ( | |
716 | cur=refs/ && | |
717 | __git_refs non-existing >"$actual" | |
718 | ) && | |
719 | test_must_be_empty "$actual" | |
720 | ' | |
721 | ||
91b7ea81 | 722 | test_expect_success '__git_refs - non-existing URL remote' ' |
fb9cd420 SG |
723 | ( |
724 | cur= && | |
725 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
726 | ) && | |
727 | test_must_be_empty "$actual" | |
728 | ' | |
729 | ||
730 | test_expect_success '__git_refs - non-existing URL remote - full refs' ' | |
731 | ( | |
732 | cur=refs/ && | |
733 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
734 | ) && | |
735 | test_must_be_empty "$actual" | |
736 | ' | |
737 | ||
62a1b732 | 738 | test_expect_success '__git_refs - not in a git repository' ' |
fb9cd420 SG |
739 | ( |
740 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
741 | export GIT_CEILING_DIRECTORIES && | |
742 | cd subdir && | |
743 | cur= && | |
744 | __git_refs >"$actual" | |
745 | ) && | |
746 | test_must_be_empty "$actual" | |
747 | ' | |
748 | ||
749 | test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' | |
750 | cat >expected <<-EOF && | |
751 | HEAD | |
752 | master | |
753 | matching-branch | |
754 | other/ambiguous | |
755 | other/branch-in-other | |
756 | other/master-in-other | |
757 | remote/ambiguous | |
758 | remote/branch-in-remote | |
759 | matching-tag | |
760 | branch-in-other | |
761 | branch-in-remote | |
762 | master-in-other | |
763 | EOF | |
764 | for remote_ref in refs/remotes/other/ambiguous \ | |
765 | refs/remotes/remote/ambiguous \ | |
766 | refs/remotes/remote/branch-in-remote | |
767 | do | |
768 | git update-ref $remote_ref master && | |
769 | test_when_finished "git update-ref -d $remote_ref" | |
770 | done && | |
771 | ( | |
772 | cur= && | |
773 | __git_refs "" 1 >"$actual" | |
774 | ) && | |
775 | test_cmp expected "$actual" | |
776 | ' | |
777 | ||
15b4a163 SG |
778 | test_expect_success '__git_complete_refs - simple' ' |
779 | sed -e "s/Z$//" >expected <<-EOF && | |
780 | HEAD Z | |
781 | master Z | |
782 | matching-branch Z | |
783 | other/branch-in-other Z | |
784 | other/master-in-other Z | |
785 | matching-tag Z | |
786 | EOF | |
787 | ( | |
788 | cur= && | |
789 | __git_complete_refs && | |
790 | print_comp | |
791 | ) && | |
792 | test_cmp expected out | |
793 | ' | |
794 | ||
795 | test_expect_success '__git_complete_refs - matching' ' | |
796 | sed -e "s/Z$//" >expected <<-EOF && | |
797 | matching-branch Z | |
798 | matching-tag Z | |
799 | EOF | |
800 | ( | |
801 | cur=mat && | |
802 | __git_complete_refs && | |
803 | print_comp | |
804 | ) && | |
805 | test_cmp expected out | |
806 | ' | |
807 | ||
808 | test_expect_success '__git_complete_refs - remote' ' | |
809 | sed -e "s/Z$//" >expected <<-EOF && | |
810 | HEAD Z | |
811 | branch-in-other Z | |
812 | master-in-other Z | |
813 | EOF | |
814 | ( | |
815 | cur= | |
816 | __git_complete_refs --remote=other && | |
817 | print_comp | |
818 | ) && | |
819 | test_cmp expected out | |
820 | ' | |
821 | ||
822 | test_expect_success '__git_complete_refs - track' ' | |
823 | sed -e "s/Z$//" >expected <<-EOF && | |
824 | HEAD Z | |
825 | master Z | |
826 | matching-branch Z | |
827 | other/branch-in-other Z | |
828 | other/master-in-other Z | |
829 | matching-tag Z | |
830 | branch-in-other Z | |
831 | master-in-other Z | |
832 | EOF | |
833 | ( | |
834 | cur= | |
835 | __git_complete_refs --track && | |
836 | print_comp | |
837 | ) && | |
838 | test_cmp expected out | |
839 | ' | |
840 | ||
841 | test_expect_success '__git_complete_refs - current word' ' | |
842 | sed -e "s/Z$//" >expected <<-EOF && | |
843 | matching-branch Z | |
844 | matching-tag Z | |
845 | EOF | |
846 | ( | |
847 | cur="--option=mat" && | |
848 | __git_complete_refs --cur="${cur#*=}" && | |
849 | print_comp | |
850 | ) && | |
851 | test_cmp expected out | |
852 | ' | |
853 | ||
854 | test_expect_success '__git_complete_refs - prefix' ' | |
855 | sed -e "s/Z$//" >expected <<-EOF && | |
856 | v1.0..matching-branch Z | |
857 | v1.0..matching-tag Z | |
858 | EOF | |
859 | ( | |
860 | cur=v1.0..mat && | |
861 | __git_complete_refs --pfx=v1.0.. --cur=mat && | |
862 | print_comp | |
863 | ) && | |
864 | test_cmp expected out | |
865 | ' | |
866 | ||
867 | test_expect_success '__git_complete_refs - suffix' ' | |
868 | cat >expected <<-EOF && | |
869 | HEAD. | |
870 | master. | |
871 | matching-branch. | |
872 | other/branch-in-other. | |
873 | other/master-in-other. | |
874 | matching-tag. | |
875 | EOF | |
876 | ( | |
877 | cur= && | |
878 | __git_complete_refs --sfx=. && | |
879 | print_comp | |
880 | ) && | |
881 | test_cmp expected out | |
882 | ' | |
883 | ||
fb9cd420 SG |
884 | test_expect_success 'teardown after ref completion' ' |
885 | git branch -d matching-branch && | |
886 | git tag -d matching-tag && | |
887 | git remote remove other | |
888 | ' | |
889 | ||
12bdc880 SG |
890 | test_expect_success '__git_get_config_variables' ' |
891 | cat >expect <<-EOF && | |
892 | name-1 | |
893 | name-2 | |
894 | EOF | |
895 | test_config interesting.name-1 good && | |
896 | test_config interesting.name-2 good && | |
897 | test_config subsection.interesting.name-3 bad && | |
898 | __git_get_config_variables interesting >actual && | |
899 | test_cmp expect actual | |
900 | ' | |
901 | ||
e8f9e428 SG |
902 | test_expect_success '__git_pretty_aliases' ' |
903 | cat >expect <<-EOF && | |
904 | author | |
905 | hash | |
906 | EOF | |
907 | test_config pretty.author "%an %ae" && | |
908 | test_config pretty.hash %H && | |
909 | __git_pretty_aliases >actual && | |
910 | test_cmp expect actual | |
911 | ' | |
912 | ||
913 | test_expect_success '__git_aliases' ' | |
914 | cat >expect <<-EOF && | |
915 | ci | |
916 | co | |
917 | EOF | |
918 | test_config alias.ci commit && | |
919 | test_config alias.co checkout && | |
920 | __git_aliases >actual && | |
921 | test_cmp expect actual | |
922 | ' | |
923 | ||
5c293a6b | 924 | test_expect_success 'basic' ' |
cdbff7d6 | 925 | run_completion "git " && |
5c293a6b FC |
926 | # built-in |
927 | grep -q "^add \$" out && | |
928 | # script | |
929 | grep -q "^filter-branch \$" out && | |
930 | # plumbing | |
931 | ! grep -q "^ls-files \$" out && | |
932 | ||
933 | run_completion "git f" && | |
934 | ! grep -q -v "^f" out | |
935 | ' | |
936 | ||
937 | test_expect_success 'double dash "git" itself' ' | |
2fbaf813 | 938 | test_completion "git --" <<-\EOF |
5c293a6b FC |
939 | --paginate Z |
940 | --no-pager Z | |
941 | --git-dir= | |
942 | --bare Z | |
943 | --version Z | |
944 | --exec-path Z | |
3ffcd086 | 945 | --exec-path= |
5c293a6b | 946 | --html-path Z |
66fb37d0 | 947 | --man-path Z |
69ef3c02 | 948 | --info-path Z |
5c293a6b FC |
949 | --work-tree= |
950 | --namespace= | |
69ef3c02 | 951 | --no-replace-objects Z |
5c293a6b FC |
952 | --help Z |
953 | EOF | |
5c293a6b FC |
954 | ' |
955 | ||
956 | test_expect_success 'double dash "git checkout"' ' | |
2fbaf813 | 957 | test_completion "git checkout --" <<-\EOF |
5c293a6b FC |
958 | --quiet Z |
959 | --ours Z | |
960 | --theirs Z | |
961 | --track Z | |
962 | --no-track Z | |
963 | --merge Z | |
964 | --conflict= | |
965 | --orphan Z | |
966 | --patch Z | |
967 | EOF | |
5c293a6b FC |
968 | ' |
969 | ||
69ef3c02 FC |
970 | test_expect_success 'general options' ' |
971 | test_completion "git --ver" "--version " && | |
972 | test_completion "git --hel" "--help " && | |
2fbaf813 | 973 | test_completion "git --exe" <<-\EOF && |
3ffcd086 JN |
974 | --exec-path Z |
975 | --exec-path= | |
976 | EOF | |
69ef3c02 FC |
977 | test_completion "git --htm" "--html-path " && |
978 | test_completion "git --pag" "--paginate " && | |
979 | test_completion "git --no-p" "--no-pager " && | |
980 | test_completion "git --git" "--git-dir=" && | |
981 | test_completion "git --wor" "--work-tree=" && | |
982 | test_completion "git --nam" "--namespace=" && | |
983 | test_completion "git --bar" "--bare " && | |
984 | test_completion "git --inf" "--info-path " && | |
985 | test_completion "git --no-r" "--no-replace-objects " | |
986 | ' | |
911d5da6 SG |
987 | |
988 | test_expect_success 'general options plus command' ' | |
989 | test_completion "git --version check" "checkout " && | |
990 | test_completion "git --paginate check" "checkout " && | |
991 | test_completion "git --git-dir=foo check" "checkout " && | |
992 | test_completion "git --bare check" "checkout " && | |
911d5da6 SG |
993 | test_completion "git --exec-path=foo check" "checkout " && |
994 | test_completion "git --html-path check" "checkout " && | |
995 | test_completion "git --no-pager check" "checkout " && | |
996 | test_completion "git --work-tree=foo check" "checkout " && | |
997 | test_completion "git --namespace=foo check" "checkout " && | |
998 | test_completion "git --paginate check" "checkout " && | |
999 | test_completion "git --info-path check" "checkout " && | |
336d694c SG |
1000 | test_completion "git --no-replace-objects check" "checkout " && |
1001 | test_completion "git --git-dir some/path check" "checkout " && | |
1002 | test_completion "git -c conf.var=value check" "checkout " && | |
1003 | test_completion "git -C some/path check" "checkout " && | |
1004 | test_completion "git --work-tree some/path check" "checkout " && | |
1005 | test_completion "git --namespace name/space check" "checkout " | |
911d5da6 SG |
1006 | ' |
1007 | ||
50478223 JH |
1008 | test_expect_success 'git --help completion' ' |
1009 | test_completion "git --help ad" "add " && | |
1010 | test_completion "git --help core" "core-tutorial " | |
1011 | ' | |
1012 | ||
fb9cd420 | 1013 | test_expect_success 'setup for integration tests' ' |
49ba92b4 JK |
1014 | echo content >file1 && |
1015 | echo more >file2 && | |
e5edbef4 | 1016 | git add file1 file2 && |
49ba92b4 JK |
1017 | git commit -m one && |
1018 | git branch mybranch && | |
1019 | git tag mytag | |
1020 | ' | |
1021 | ||
1022 | test_expect_success 'checkout completes ref names' ' | |
2fbaf813 | 1023 | test_completion "git checkout m" <<-\EOF |
43ea0812 FC |
1024 | master Z |
1025 | mybranch Z | |
1026 | mytag Z | |
49ba92b4 JK |
1027 | EOF |
1028 | ' | |
1029 | ||
80ac0744 SG |
1030 | test_expect_success 'git -C <path> checkout uses the right repo' ' |
1031 | test_completion "git -C subdir -C subsubdir -C .. -C ../otherrepo checkout b" <<-\EOF | |
1032 | branch-in-other Z | |
1033 | EOF | |
1034 | ' | |
1035 | ||
49ba92b4 | 1036 | test_expect_success 'show completes all refs' ' |
2fbaf813 | 1037 | test_completion "git show m" <<-\EOF |
43ea0812 FC |
1038 | master Z |
1039 | mybranch Z | |
1040 | mytag Z | |
49ba92b4 JK |
1041 | EOF |
1042 | ' | |
1043 | ||
1044 | test_expect_success '<ref>: completes paths' ' | |
2fbaf813 | 1045 | test_completion "git show mytag:f" <<-\EOF |
43ea0812 FC |
1046 | file1 Z |
1047 | file2 Z | |
49ba92b4 JK |
1048 | EOF |
1049 | ' | |
1050 | ||
bafed0df JK |
1051 | test_expect_success 'complete tree filename with spaces' ' |
1052 | echo content >"name with spaces" && | |
e5edbef4 | 1053 | git add "name with spaces" && |
bafed0df | 1054 | git commit -m spaces && |
2fbaf813 | 1055 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 | 1056 | name with spaces Z |
bafed0df JK |
1057 | EOF |
1058 | ' | |
1059 | ||
7d13e0a3 | 1060 | test_expect_success 'complete tree filename with metacharacters' ' |
bafed0df | 1061 | echo content >"name with \${meta}" && |
e5edbef4 | 1062 | git add "name with \${meta}" && |
bafed0df | 1063 | git commit -m meta && |
2fbaf813 | 1064 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 FC |
1065 | name with ${meta} Z |
1066 | name with spaces Z | |
bafed0df JK |
1067 | EOF |
1068 | ' | |
1069 | ||
2f65494d FC |
1070 | test_expect_success 'send-email' ' |
1071 | test_completion "git send-email --cov" "--cover-letter " && | |
1072 | test_completion "git send-email ma" "master " | |
1073 | ' | |
1074 | ||
ddf07bdd FC |
1075 | test_expect_success 'complete files' ' |
1076 | git init tmp && cd tmp && | |
1077 | test_when_finished "cd .. && rm -rf tmp" && | |
1078 | ||
1079 | echo "expected" > .gitignore && | |
1080 | echo "out" >> .gitignore && | |
1081 | ||
1082 | git add .gitignore && | |
1083 | test_completion "git commit " ".gitignore" && | |
1084 | ||
1085 | git commit -m ignore && | |
1086 | ||
1087 | touch new && | |
1088 | test_completion "git add " "new" && | |
1089 | ||
1090 | git add new && | |
1091 | git commit -a -m new && | |
1092 | test_completion "git add " "" && | |
1093 | ||
1094 | git mv new modified && | |
1095 | echo modify > modified && | |
1096 | test_completion "git add " "modified" && | |
1097 | ||
1098 | touch untracked && | |
1099 | ||
1100 | : TODO .gitignore should not be here && | |
1101 | test_completion "git rm " <<-\EOF && | |
1102 | .gitignore | |
1103 | modified | |
1104 | EOF | |
1105 | ||
1106 | test_completion "git clean " "untracked" && | |
1107 | ||
1108 | : TODO .gitignore should not be here && | |
1109 | test_completion "git mv " <<-\EOF && | |
1110 | .gitignore | |
1111 | modified | |
1112 | EOF | |
1113 | ||
1114 | mkdir dir && | |
1115 | touch dir/file-in-dir && | |
1116 | git add dir/file-in-dir && | |
1117 | git commit -m dir && | |
1118 | ||
1119 | mkdir untracked-dir && | |
1120 | ||
1121 | : TODO .gitignore should not be here && | |
1122 | test_completion "git mv modified " <<-\EOF && | |
1123 | .gitignore | |
1124 | dir | |
1125 | modified | |
1126 | untracked | |
1127 | untracked-dir | |
1128 | EOF | |
1129 | ||
1130 | test_completion "git commit " "modified" && | |
1131 | ||
1132 | : TODO .gitignore should not be here && | |
8fb26872 | 1133 | test_completion "git ls-files " <<-\EOF && |
ddf07bdd FC |
1134 | .gitignore |
1135 | dir | |
1136 | modified | |
1137 | EOF | |
1138 | ||
1139 | touch momified && | |
1140 | test_completion "git add mom" "momified" | |
1141 | ' | |
1142 | ||
56f24e80 SP |
1143 | test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' |
1144 | test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && | |
1145 | test_completion "git co m" <<-\EOF | |
1146 | master Z | |
1147 | mybranch Z | |
1148 | mytag Z | |
1149 | EOF | |
1150 | ' | |
1151 | ||
1152 | test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' | |
1153 | test_config alias.co "!f () { VAR=val git checkout ... ; } f" && | |
1154 | test_completion "git co m" <<-\EOF | |
1155 | master Z | |
1156 | mybranch Z | |
1157 | mytag Z | |
1158 | EOF | |
1159 | ' | |
1160 | ||
1161 | test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' | |
1162 | test_config alias.co "!f() { : git checkout ; if ... } f" && | |
1163 | test_completion "git co m" <<-\EOF | |
1164 | master Z | |
1165 | mybranch Z | |
1166 | mytag Z | |
1167 | EOF | |
1168 | ' | |
1169 | ||
f03efba4 FC |
1170 | test_expect_failure 'complete with tilde expansion' ' |
1171 | git init tmp && cd tmp && | |
1172 | test_when_finished "cd .. && rm -rf tmp" && | |
1173 | ||
1174 | touch ~/tmp/file && | |
1175 | ||
1176 | test_completion "git add ~/tmp/" "~/tmp/file" | |
1177 | ' | |
1178 | ||
5c293a6b | 1179 | test_done |