]>
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 | ||
c9a102e8 SG |
134 | test_expect_success 'setup for __gitdir tests' ' |
135 | mkdir -p subdir/subsubdir && | |
136 | git init otherrepo | |
137 | ' | |
138 | ||
139 | test_expect_success '__gitdir - from command line (through $__git_dir)' ' | |
f6114408 | 140 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 141 | ( |
f6114408 | 142 | __git_dir="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
143 | __gitdir >"$actual" |
144 | ) && | |
145 | test_cmp expected "$actual" | |
146 | ' | |
147 | ||
148 | test_expect_success '__gitdir - repo as argument' ' | |
149 | echo "otherrepo/.git" >expected && | |
150 | __gitdir "otherrepo" >"$actual" && | |
151 | test_cmp expected "$actual" | |
152 | ' | |
153 | ||
154 | test_expect_success '__gitdir - remote as argument' ' | |
155 | echo "remote" >expected && | |
156 | __gitdir "remote" >"$actual" && | |
157 | test_cmp expected "$actual" | |
158 | ' | |
159 | ||
160 | test_expect_success '__gitdir - .git directory in cwd' ' | |
161 | echo ".git" >expected && | |
162 | __gitdir >"$actual" && | |
163 | test_cmp expected "$actual" | |
164 | ' | |
165 | ||
166 | test_expect_success '__gitdir - .git directory in parent' ' | |
f6114408 | 167 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
168 | ( |
169 | cd subdir/subsubdir && | |
170 | __gitdir >"$actual" | |
171 | ) && | |
172 | test_cmp expected "$actual" | |
173 | ' | |
174 | ||
175 | test_expect_success '__gitdir - cwd is a .git directory' ' | |
176 | echo "." >expected && | |
177 | ( | |
178 | cd .git && | |
179 | __gitdir >"$actual" | |
180 | ) && | |
181 | test_cmp expected "$actual" | |
182 | ' | |
183 | ||
184 | test_expect_success '__gitdir - parent is a .git directory' ' | |
f6114408 | 185 | echo "$ROOT/.git" >expected && |
c9a102e8 SG |
186 | ( |
187 | cd .git/refs/heads && | |
188 | __gitdir >"$actual" | |
189 | ) && | |
190 | test_cmp expected "$actual" | |
191 | ' | |
192 | ||
193 | test_expect_success '__gitdir - $GIT_DIR set while .git directory in cwd' ' | |
f6114408 | 194 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 195 | ( |
f6114408 | 196 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
197 | export GIT_DIR && |
198 | __gitdir >"$actual" | |
199 | ) && | |
200 | test_cmp expected "$actual" | |
201 | ' | |
202 | ||
203 | test_expect_success '__gitdir - $GIT_DIR set while .git directory in parent' ' | |
f6114408 | 204 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 | 205 | ( |
f6114408 | 206 | GIT_DIR="$ROOT/otherrepo/.git" && |
c9a102e8 SG |
207 | export GIT_DIR && |
208 | cd subdir && | |
209 | __gitdir >"$actual" | |
210 | ) && | |
211 | test_cmp expected "$actual" | |
212 | ' | |
213 | ||
a2f03b0e SG |
214 | test_expect_success '__gitdir - non-existing path in $__git_dir' ' |
215 | ( | |
216 | __git_dir="non-existing" && | |
217 | test_must_fail __gitdir >"$actual" | |
218 | ) && | |
219 | test_must_be_empty "$actual" | |
220 | ' | |
221 | ||
c9a102e8 SG |
222 | test_expect_success '__gitdir - non-existing $GIT_DIR' ' |
223 | ( | |
f6114408 | 224 | GIT_DIR="$ROOT/non-existing" && |
c9a102e8 | 225 | export GIT_DIR && |
8f0fa85d SG |
226 | test_must_fail __gitdir >"$actual" |
227 | ) && | |
228 | test_must_be_empty "$actual" | |
c9a102e8 SG |
229 | ' |
230 | ||
231 | test_expect_success '__gitdir - gitfile in cwd' ' | |
f6114408 SG |
232 | echo "$ROOT/otherrepo/.git" >expected && |
233 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
234 | test_when_finished "rm -f subdir/.git" && |
235 | ( | |
236 | cd subdir && | |
237 | __gitdir >"$actual" | |
238 | ) && | |
239 | test_cmp expected "$actual" | |
240 | ' | |
241 | ||
242 | test_expect_success '__gitdir - gitfile in parent' ' | |
f6114408 SG |
243 | echo "$ROOT/otherrepo/.git" >expected && |
244 | echo "gitdir: $ROOT/otherrepo/.git" >subdir/.git && | |
c9a102e8 SG |
245 | test_when_finished "rm -f subdir/.git" && |
246 | ( | |
247 | cd subdir/subsubdir && | |
248 | __gitdir >"$actual" | |
249 | ) && | |
250 | test_cmp expected "$actual" | |
251 | ' | |
252 | ||
253 | test_expect_success SYMLINKS '__gitdir - resulting path avoids symlinks' ' | |
f6114408 | 254 | echo "$ROOT/otherrepo/.git" >expected && |
c9a102e8 SG |
255 | mkdir otherrepo/dir && |
256 | test_when_finished "rm -rf otherrepo/dir" && | |
257 | ln -s otherrepo/dir link && | |
258 | test_when_finished "rm -f link" && | |
259 | ( | |
260 | cd link && | |
261 | __gitdir >"$actual" | |
262 | ) && | |
263 | test_cmp expected "$actual" | |
264 | ' | |
265 | ||
266 | test_expect_success '__gitdir - not a git repository' ' | |
8f0fa85d SG |
267 | nongit test_must_fail __gitdir >"$actual" && |
268 | test_must_be_empty "$actual" | |
c9a102e8 SG |
269 | ' |
270 | ||
74a8c849 | 271 | test_expect_success '__gitcomp - trailing space - options' ' |
e4615238 FC |
272 | test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message= |
273 | --reset-author" <<-EOF | |
74a8c849 SG |
274 | --reuse-message=Z |
275 | --reedit-message=Z | |
276 | --reset-author Z | |
277 | EOF | |
74a8c849 SG |
278 | ' |
279 | ||
280 | test_expect_success '__gitcomp - trailing space - config keys' ' | |
e4615238 FC |
281 | test_gitcomp "br" "branch. branch.autosetupmerge |
282 | branch.autosetuprebase browser." <<-\EOF | |
74a8c849 SG |
283 | branch.Z |
284 | branch.autosetupmerge Z | |
285 | branch.autosetuprebase Z | |
286 | browser.Z | |
287 | EOF | |
74a8c849 SG |
288 | ' |
289 | ||
290 | test_expect_success '__gitcomp - option parameter' ' | |
e4615238 FC |
291 | test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \ |
292 | "" "re" <<-\EOF | |
74a8c849 SG |
293 | recursive Z |
294 | resolve Z | |
295 | EOF | |
74a8c849 SG |
296 | ' |
297 | ||
298 | test_expect_success '__gitcomp - prefix' ' | |
e4615238 FC |
299 | test_gitcomp "branch.me" "remote merge mergeoptions rebase" \ |
300 | "branch.maint." "me" <<-\EOF | |
74a8c849 SG |
301 | branch.maint.merge Z |
302 | branch.maint.mergeoptions Z | |
303 | EOF | |
74a8c849 SG |
304 | ' |
305 | ||
306 | test_expect_success '__gitcomp - suffix' ' | |
e4615238 FC |
307 | test_gitcomp "branch.me" "master maint next pu" "branch." \ |
308 | "ma" "." <<-\EOF | |
74a8c849 SG |
309 | branch.master.Z |
310 | branch.maint.Z | |
311 | EOF | |
74a8c849 SG |
312 | ' |
313 | ||
7d13e0a3 | 314 | test_expect_success '__gitcomp - doesnt fail because of invalid variable name' ' |
43369a22 FC |
315 | __gitcomp "$invalid_variable_name" |
316 | ' | |
317 | ||
318 | read -r -d "" refs <<-\EOF | |
319 | maint | |
320 | master | |
321 | next | |
322 | pu | |
323 | EOF | |
324 | ||
325 | test_expect_success '__gitcomp_nl - trailing space' ' | |
326 | test_gitcomp_nl "m" "$refs" <<-EOF | |
327 | maint Z | |
328 | master Z | |
329 | EOF | |
330 | ' | |
331 | ||
332 | test_expect_success '__gitcomp_nl - prefix' ' | |
333 | test_gitcomp_nl "--fixup=m" "$refs" "--fixup=" "m" <<-EOF | |
334 | --fixup=maint Z | |
335 | --fixup=master Z | |
336 | EOF | |
337 | ' | |
338 | ||
339 | test_expect_success '__gitcomp_nl - suffix' ' | |
340 | test_gitcomp_nl "branch.ma" "$refs" "branch." "ma" "." <<-\EOF | |
341 | branch.maint.Z | |
342 | branch.master.Z | |
343 | EOF | |
344 | ' | |
345 | ||
346 | test_expect_success '__gitcomp_nl - no suffix' ' | |
347 | test_gitcomp_nl "ma" "$refs" "" "ma" "" <<-\EOF | |
348 | maintZ | |
349 | masterZ | |
350 | EOF | |
351 | ' | |
352 | ||
7d13e0a3 | 353 | test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name' ' |
43369a22 FC |
354 | __gitcomp_nl "$invalid_variable_name" |
355 | ' | |
356 | ||
2acc1940 SG |
357 | test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' ' |
358 | cat >expect <<-EOF && | |
359 | remote_from_file_1 | |
360 | remote_from_file_2 | |
361 | remote_in_config_1 | |
362 | remote_in_config_2 | |
363 | EOF | |
364 | test_when_finished "rm -rf .git/remotes" && | |
365 | mkdir -p .git/remotes && | |
366 | >.git/remotes/remote_from_file_1 && | |
367 | >.git/remotes/remote_from_file_2 && | |
368 | test_when_finished "git remote remove remote_in_config_1" && | |
369 | git remote add remote_in_config_1 git://remote_1 && | |
370 | test_when_finished "git remote remove remote_in_config_2" && | |
371 | git remote add remote_in_config_2 git://remote_2 && | |
372 | __git_remotes >actual && | |
373 | test_cmp expect actual | |
374 | ' | |
375 | ||
69a77596 SG |
376 | test_expect_success '__git_is_configured_remote' ' |
377 | test_when_finished "git remote remove remote_1" && | |
378 | git remote add remote_1 git://remote_1 && | |
379 | test_when_finished "git remote remove remote_2" && | |
380 | git remote add remote_2 git://remote_2 && | |
381 | verbose __git_is_configured_remote remote_2 && | |
382 | test_must_fail __git_is_configured_remote non-existent | |
383 | ' | |
384 | ||
fb9cd420 SG |
385 | test_expect_success 'setup for ref completion' ' |
386 | git commit --allow-empty -m initial && | |
387 | git branch matching-branch && | |
388 | git tag matching-tag && | |
389 | ( | |
390 | cd otherrepo && | |
391 | git commit --allow-empty -m initial && | |
392 | git branch -m master master-in-other && | |
393 | git branch branch-in-other && | |
394 | git tag tag-in-other | |
395 | ) && | |
396 | git remote add other "$ROOT/otherrepo/.git" && | |
397 | git fetch --no-tags other && | |
398 | rm -f .git/FETCH_HEAD && | |
399 | git init thirdrepo | |
400 | ' | |
401 | ||
402 | test_expect_success '__git_refs - simple' ' | |
403 | cat >expected <<-EOF && | |
404 | HEAD | |
405 | master | |
406 | matching-branch | |
407 | other/branch-in-other | |
408 | other/master-in-other | |
409 | matching-tag | |
410 | EOF | |
411 | ( | |
412 | cur= && | |
413 | __git_refs >"$actual" | |
414 | ) && | |
415 | test_cmp expected "$actual" | |
416 | ' | |
417 | ||
418 | test_expect_success '__git_refs - full refs' ' | |
419 | cat >expected <<-EOF && | |
420 | refs/heads/master | |
421 | refs/heads/matching-branch | |
422 | EOF | |
423 | ( | |
424 | cur=refs/heads/ && | |
425 | __git_refs >"$actual" | |
426 | ) && | |
427 | test_cmp expected "$actual" | |
428 | ' | |
429 | ||
430 | test_expect_success '__git_refs - repo given on the command line' ' | |
431 | cat >expected <<-EOF && | |
432 | HEAD | |
433 | branch-in-other | |
434 | master-in-other | |
435 | tag-in-other | |
436 | EOF | |
437 | ( | |
438 | __git_dir="$ROOT/otherrepo/.git" && | |
439 | cur= && | |
440 | __git_refs >"$actual" | |
441 | ) && | |
442 | test_cmp expected "$actual" | |
443 | ' | |
444 | ||
445 | test_expect_success '__git_refs - remote on local file system' ' | |
446 | cat >expected <<-EOF && | |
447 | HEAD | |
448 | branch-in-other | |
449 | master-in-other | |
450 | tag-in-other | |
451 | EOF | |
452 | ( | |
453 | cur= && | |
454 | __git_refs otherrepo >"$actual" | |
455 | ) && | |
456 | test_cmp expected "$actual" | |
457 | ' | |
458 | ||
459 | test_expect_success '__git_refs - remote on local file system - full refs' ' | |
460 | cat >expected <<-EOF && | |
461 | refs/heads/branch-in-other | |
462 | refs/heads/master-in-other | |
463 | refs/tags/tag-in-other | |
464 | EOF | |
465 | ( | |
466 | cur=refs/ && | |
467 | __git_refs otherrepo >"$actual" | |
468 | ) && | |
469 | test_cmp expected "$actual" | |
470 | ' | |
471 | ||
472 | test_expect_success '__git_refs - configured remote' ' | |
473 | cat >expected <<-EOF && | |
474 | HEAD | |
475 | branch-in-other | |
476 | master-in-other | |
477 | EOF | |
478 | ( | |
479 | cur= && | |
480 | __git_refs other >"$actual" | |
481 | ) && | |
482 | test_cmp expected "$actual" | |
483 | ' | |
484 | ||
485 | test_expect_success '__git_refs - configured remote - full refs' ' | |
486 | cat >expected <<-EOF && | |
487 | refs/heads/branch-in-other | |
488 | refs/heads/master-in-other | |
489 | refs/tags/tag-in-other | |
490 | EOF | |
491 | ( | |
492 | cur=refs/ && | |
493 | __git_refs other >"$actual" | |
494 | ) && | |
495 | test_cmp expected "$actual" | |
496 | ' | |
497 | ||
5c12f642 | 498 | test_expect_success '__git_refs - configured remote - repo given on the command line' ' |
fb9cd420 SG |
499 | cat >expected <<-EOF && |
500 | HEAD | |
501 | branch-in-other | |
502 | master-in-other | |
503 | EOF | |
504 | ( | |
505 | cd thirdrepo && | |
506 | __git_dir="$ROOT/.git" && | |
507 | cur= && | |
508 | __git_refs other >"$actual" | |
509 | ) && | |
510 | test_cmp expected "$actual" | |
511 | ' | |
512 | ||
5c12f642 | 513 | test_expect_success '__git_refs - configured remote - full refs - repo given on the command line' ' |
fb9cd420 SG |
514 | cat >expected <<-EOF && |
515 | refs/heads/branch-in-other | |
516 | refs/heads/master-in-other | |
517 | refs/tags/tag-in-other | |
518 | EOF | |
519 | ( | |
520 | cd thirdrepo && | |
521 | __git_dir="$ROOT/.git" && | |
522 | cur=refs/ && | |
523 | __git_refs other >"$actual" | |
524 | ) && | |
525 | test_cmp expected "$actual" | |
526 | ' | |
527 | ||
69a77596 | 528 | test_expect_success '__git_refs - configured remote - remote name matches a directory' ' |
fb9cd420 SG |
529 | cat >expected <<-EOF && |
530 | HEAD | |
531 | branch-in-other | |
532 | master-in-other | |
533 | EOF | |
534 | mkdir other && | |
535 | test_when_finished "rm -rf other" && | |
536 | ( | |
537 | cur= && | |
538 | __git_refs other >"$actual" | |
539 | ) && | |
540 | test_cmp expected "$actual" | |
541 | ' | |
542 | ||
91b7ea81 | 543 | test_expect_success '__git_refs - URL remote' ' |
fb9cd420 SG |
544 | cat >expected <<-EOF && |
545 | HEAD | |
546 | branch-in-other | |
547 | master-in-other | |
548 | tag-in-other | |
549 | EOF | |
550 | ( | |
551 | cur= && | |
552 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
553 | ) && | |
554 | test_cmp expected "$actual" | |
555 | ' | |
556 | ||
557 | test_expect_success '__git_refs - URL remote - full refs' ' | |
558 | cat >expected <<-EOF && | |
559 | refs/heads/branch-in-other | |
560 | refs/heads/master-in-other | |
561 | refs/tags/tag-in-other | |
562 | EOF | |
563 | ( | |
564 | cur=refs/ && | |
565 | __git_refs "file://$ROOT/otherrepo/.git" >"$actual" | |
566 | ) && | |
567 | test_cmp expected "$actual" | |
568 | ' | |
569 | ||
91b7ea81 | 570 | test_expect_success '__git_refs - non-existing remote' ' |
fb9cd420 SG |
571 | ( |
572 | cur= && | |
573 | __git_refs non-existing >"$actual" | |
574 | ) && | |
575 | test_must_be_empty "$actual" | |
576 | ' | |
577 | ||
578 | test_expect_success '__git_refs - non-existing remote - full refs' ' | |
579 | ( | |
580 | cur=refs/ && | |
581 | __git_refs non-existing >"$actual" | |
582 | ) && | |
583 | test_must_be_empty "$actual" | |
584 | ' | |
585 | ||
91b7ea81 | 586 | test_expect_success '__git_refs - non-existing URL remote' ' |
fb9cd420 SG |
587 | ( |
588 | cur= && | |
589 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
590 | ) && | |
591 | test_must_be_empty "$actual" | |
592 | ' | |
593 | ||
594 | test_expect_success '__git_refs - non-existing URL remote - full refs' ' | |
595 | ( | |
596 | cur=refs/ && | |
597 | __git_refs "file://$ROOT/non-existing" >"$actual" | |
598 | ) && | |
599 | test_must_be_empty "$actual" | |
600 | ' | |
601 | ||
62a1b732 | 602 | test_expect_success '__git_refs - not in a git repository' ' |
fb9cd420 SG |
603 | ( |
604 | GIT_CEILING_DIRECTORIES="$ROOT" && | |
605 | export GIT_CEILING_DIRECTORIES && | |
606 | cd subdir && | |
607 | cur= && | |
608 | __git_refs >"$actual" | |
609 | ) && | |
610 | test_must_be_empty "$actual" | |
611 | ' | |
612 | ||
613 | test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' ' | |
614 | cat >expected <<-EOF && | |
615 | HEAD | |
616 | master | |
617 | matching-branch | |
618 | other/ambiguous | |
619 | other/branch-in-other | |
620 | other/master-in-other | |
621 | remote/ambiguous | |
622 | remote/branch-in-remote | |
623 | matching-tag | |
624 | branch-in-other | |
625 | branch-in-remote | |
626 | master-in-other | |
627 | EOF | |
628 | for remote_ref in refs/remotes/other/ambiguous \ | |
629 | refs/remotes/remote/ambiguous \ | |
630 | refs/remotes/remote/branch-in-remote | |
631 | do | |
632 | git update-ref $remote_ref master && | |
633 | test_when_finished "git update-ref -d $remote_ref" | |
634 | done && | |
635 | ( | |
636 | cur= && | |
637 | __git_refs "" 1 >"$actual" | |
638 | ) && | |
639 | test_cmp expected "$actual" | |
640 | ' | |
641 | ||
642 | test_expect_success 'teardown after ref completion' ' | |
643 | git branch -d matching-branch && | |
644 | git tag -d matching-tag && | |
645 | git remote remove other | |
646 | ' | |
647 | ||
12bdc880 SG |
648 | test_expect_success '__git_get_config_variables' ' |
649 | cat >expect <<-EOF && | |
650 | name-1 | |
651 | name-2 | |
652 | EOF | |
653 | test_config interesting.name-1 good && | |
654 | test_config interesting.name-2 good && | |
655 | test_config subsection.interesting.name-3 bad && | |
656 | __git_get_config_variables interesting >actual && | |
657 | test_cmp expect actual | |
658 | ' | |
659 | ||
e8f9e428 SG |
660 | test_expect_success '__git_pretty_aliases' ' |
661 | cat >expect <<-EOF && | |
662 | author | |
663 | hash | |
664 | EOF | |
665 | test_config pretty.author "%an %ae" && | |
666 | test_config pretty.hash %H && | |
667 | __git_pretty_aliases >actual && | |
668 | test_cmp expect actual | |
669 | ' | |
670 | ||
671 | test_expect_success '__git_aliases' ' | |
672 | cat >expect <<-EOF && | |
673 | ci | |
674 | co | |
675 | EOF | |
676 | test_config alias.ci commit && | |
677 | test_config alias.co checkout && | |
678 | __git_aliases >actual && | |
679 | test_cmp expect actual | |
680 | ' | |
681 | ||
5c293a6b | 682 | test_expect_success 'basic' ' |
cdbff7d6 | 683 | run_completion "git " && |
5c293a6b FC |
684 | # built-in |
685 | grep -q "^add \$" out && | |
686 | # script | |
687 | grep -q "^filter-branch \$" out && | |
688 | # plumbing | |
689 | ! grep -q "^ls-files \$" out && | |
690 | ||
691 | run_completion "git f" && | |
692 | ! grep -q -v "^f" out | |
693 | ' | |
694 | ||
695 | test_expect_success 'double dash "git" itself' ' | |
2fbaf813 | 696 | test_completion "git --" <<-\EOF |
5c293a6b FC |
697 | --paginate Z |
698 | --no-pager Z | |
699 | --git-dir= | |
700 | --bare Z | |
701 | --version Z | |
702 | --exec-path Z | |
3ffcd086 | 703 | --exec-path= |
5c293a6b | 704 | --html-path Z |
66fb37d0 | 705 | --man-path Z |
69ef3c02 | 706 | --info-path Z |
5c293a6b FC |
707 | --work-tree= |
708 | --namespace= | |
69ef3c02 | 709 | --no-replace-objects Z |
5c293a6b FC |
710 | --help Z |
711 | EOF | |
5c293a6b FC |
712 | ' |
713 | ||
714 | test_expect_success 'double dash "git checkout"' ' | |
2fbaf813 | 715 | test_completion "git checkout --" <<-\EOF |
5c293a6b FC |
716 | --quiet Z |
717 | --ours Z | |
718 | --theirs Z | |
719 | --track Z | |
720 | --no-track Z | |
721 | --merge Z | |
722 | --conflict= | |
723 | --orphan Z | |
724 | --patch Z | |
725 | EOF | |
5c293a6b FC |
726 | ' |
727 | ||
69ef3c02 FC |
728 | test_expect_success 'general options' ' |
729 | test_completion "git --ver" "--version " && | |
730 | test_completion "git --hel" "--help " && | |
2fbaf813 | 731 | test_completion "git --exe" <<-\EOF && |
3ffcd086 JN |
732 | --exec-path Z |
733 | --exec-path= | |
734 | EOF | |
69ef3c02 FC |
735 | test_completion "git --htm" "--html-path " && |
736 | test_completion "git --pag" "--paginate " && | |
737 | test_completion "git --no-p" "--no-pager " && | |
738 | test_completion "git --git" "--git-dir=" && | |
739 | test_completion "git --wor" "--work-tree=" && | |
740 | test_completion "git --nam" "--namespace=" && | |
741 | test_completion "git --bar" "--bare " && | |
742 | test_completion "git --inf" "--info-path " && | |
743 | test_completion "git --no-r" "--no-replace-objects " | |
744 | ' | |
911d5da6 SG |
745 | |
746 | test_expect_success 'general options plus command' ' | |
747 | test_completion "git --version check" "checkout " && | |
748 | test_completion "git --paginate check" "checkout " && | |
749 | test_completion "git --git-dir=foo check" "checkout " && | |
750 | test_completion "git --bare check" "checkout " && | |
911d5da6 SG |
751 | test_completion "git --exec-path=foo check" "checkout " && |
752 | test_completion "git --html-path check" "checkout " && | |
753 | test_completion "git --no-pager check" "checkout " && | |
754 | test_completion "git --work-tree=foo check" "checkout " && | |
755 | test_completion "git --namespace=foo check" "checkout " && | |
756 | test_completion "git --paginate check" "checkout " && | |
757 | test_completion "git --info-path check" "checkout " && | |
336d694c SG |
758 | test_completion "git --no-replace-objects check" "checkout " && |
759 | test_completion "git --git-dir some/path check" "checkout " && | |
760 | test_completion "git -c conf.var=value check" "checkout " && | |
761 | test_completion "git -C some/path check" "checkout " && | |
762 | test_completion "git --work-tree some/path check" "checkout " && | |
763 | test_completion "git --namespace name/space check" "checkout " | |
911d5da6 SG |
764 | ' |
765 | ||
50478223 JH |
766 | test_expect_success 'git --help completion' ' |
767 | test_completion "git --help ad" "add " && | |
768 | test_completion "git --help core" "core-tutorial " | |
769 | ' | |
770 | ||
fb9cd420 | 771 | test_expect_success 'setup for integration tests' ' |
49ba92b4 JK |
772 | echo content >file1 && |
773 | echo more >file2 && | |
e5edbef4 | 774 | git add file1 file2 && |
49ba92b4 JK |
775 | git commit -m one && |
776 | git branch mybranch && | |
777 | git tag mytag | |
778 | ' | |
779 | ||
780 | test_expect_success 'checkout completes ref names' ' | |
2fbaf813 | 781 | test_completion "git checkout m" <<-\EOF |
43ea0812 FC |
782 | master Z |
783 | mybranch Z | |
784 | mytag Z | |
49ba92b4 JK |
785 | EOF |
786 | ' | |
787 | ||
788 | test_expect_success 'show completes all refs' ' | |
2fbaf813 | 789 | test_completion "git show m" <<-\EOF |
43ea0812 FC |
790 | master Z |
791 | mybranch Z | |
792 | mytag Z | |
49ba92b4 JK |
793 | EOF |
794 | ' | |
795 | ||
796 | test_expect_success '<ref>: completes paths' ' | |
2fbaf813 | 797 | test_completion "git show mytag:f" <<-\EOF |
43ea0812 FC |
798 | file1 Z |
799 | file2 Z | |
49ba92b4 JK |
800 | EOF |
801 | ' | |
802 | ||
bafed0df JK |
803 | test_expect_success 'complete tree filename with spaces' ' |
804 | echo content >"name with spaces" && | |
e5edbef4 | 805 | git add "name with spaces" && |
bafed0df | 806 | git commit -m spaces && |
2fbaf813 | 807 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 | 808 | name with spaces Z |
bafed0df JK |
809 | EOF |
810 | ' | |
811 | ||
7d13e0a3 | 812 | test_expect_success 'complete tree filename with metacharacters' ' |
bafed0df | 813 | echo content >"name with \${meta}" && |
e5edbef4 | 814 | git add "name with \${meta}" && |
bafed0df | 815 | git commit -m meta && |
2fbaf813 | 816 | test_completion "git show HEAD:nam" <<-\EOF |
43ea0812 FC |
817 | name with ${meta} Z |
818 | name with spaces Z | |
bafed0df JK |
819 | EOF |
820 | ' | |
821 | ||
2f65494d FC |
822 | test_expect_success 'send-email' ' |
823 | test_completion "git send-email --cov" "--cover-letter " && | |
824 | test_completion "git send-email ma" "master " | |
825 | ' | |
826 | ||
ddf07bdd FC |
827 | test_expect_success 'complete files' ' |
828 | git init tmp && cd tmp && | |
829 | test_when_finished "cd .. && rm -rf tmp" && | |
830 | ||
831 | echo "expected" > .gitignore && | |
832 | echo "out" >> .gitignore && | |
833 | ||
834 | git add .gitignore && | |
835 | test_completion "git commit " ".gitignore" && | |
836 | ||
837 | git commit -m ignore && | |
838 | ||
839 | touch new && | |
840 | test_completion "git add " "new" && | |
841 | ||
842 | git add new && | |
843 | git commit -a -m new && | |
844 | test_completion "git add " "" && | |
845 | ||
846 | git mv new modified && | |
847 | echo modify > modified && | |
848 | test_completion "git add " "modified" && | |
849 | ||
850 | touch untracked && | |
851 | ||
852 | : TODO .gitignore should not be here && | |
853 | test_completion "git rm " <<-\EOF && | |
854 | .gitignore | |
855 | modified | |
856 | EOF | |
857 | ||
858 | test_completion "git clean " "untracked" && | |
859 | ||
860 | : TODO .gitignore should not be here && | |
861 | test_completion "git mv " <<-\EOF && | |
862 | .gitignore | |
863 | modified | |
864 | EOF | |
865 | ||
866 | mkdir dir && | |
867 | touch dir/file-in-dir && | |
868 | git add dir/file-in-dir && | |
869 | git commit -m dir && | |
870 | ||
871 | mkdir untracked-dir && | |
872 | ||
873 | : TODO .gitignore should not be here && | |
874 | test_completion "git mv modified " <<-\EOF && | |
875 | .gitignore | |
876 | dir | |
877 | modified | |
878 | untracked | |
879 | untracked-dir | |
880 | EOF | |
881 | ||
882 | test_completion "git commit " "modified" && | |
883 | ||
884 | : TODO .gitignore should not be here && | |
8fb26872 | 885 | test_completion "git ls-files " <<-\EOF && |
ddf07bdd FC |
886 | .gitignore |
887 | dir | |
888 | modified | |
889 | EOF | |
890 | ||
891 | touch momified && | |
892 | test_completion "git add mom" "momified" | |
893 | ' | |
894 | ||
56f24e80 SP |
895 | test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' |
896 | test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && | |
897 | test_completion "git co m" <<-\EOF | |
898 | master Z | |
899 | mybranch Z | |
900 | mytag Z | |
901 | EOF | |
902 | ' | |
903 | ||
904 | test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' | |
905 | test_config alias.co "!f () { VAR=val git checkout ... ; } f" && | |
906 | test_completion "git co m" <<-\EOF | |
907 | master Z | |
908 | mybranch Z | |
909 | mytag Z | |
910 | EOF | |
911 | ' | |
912 | ||
913 | test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' | |
914 | test_config alias.co "!f() { : git checkout ; if ... } f" && | |
915 | test_completion "git co m" <<-\EOF | |
916 | master Z | |
917 | mybranch Z | |
918 | mytag Z | |
919 | EOF | |
920 | ' | |
921 | ||
f03efba4 FC |
922 | test_expect_failure 'complete with tilde expansion' ' |
923 | git init tmp && cd tmp && | |
924 | test_when_finished "cd .. && rm -rf tmp" && | |
925 | ||
926 | touch ~/tmp/file && | |
927 | ||
928 | test_completion "git add ~/tmp/" "~/tmp/file" | |
929 | ' | |
930 | ||
5c293a6b | 931 | test_done |