Skip to content

Commit fb9cd42

Browse files
szedergitster
authored andcommitted
completion tests: add tests for the __git_refs() helper function
Check how __git_refs() lists refs in different scenarios, i.e. - short and full refs, - from a local or from a remote repository, - remote specified via path, name or URL, - with or without a repository specified on the command line, - non-existing remote, - unique remote branches for 'git checkout's tracking DWIMery, - not in a git repository, and - interesting combinations of the above. Seven of these tests expect failure, mostly demonstrating bugs related to listing refs from a remote repository: - ignoring the repository specified on the command line (2 tests), - listing refs from the wrong place when the name of a configured remote happens to match a directory, - listing only 'HEAD' but no short refs from a remote given as URL, - listing 'HEAD' even from non-existing remotes (2 tests), and - listing 'HEAD' when not in a repository. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f0fa85 commit fb9cd42

File tree

1 file changed

+264
-1
lines changed

1 file changed

+264
-1
lines changed

t/t9902-completion.sh

Lines changed: 264 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,269 @@ test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from
365365
test_cmp expect actual
366366
'
367367

368+
test_expect_success 'setup for ref completion' '
369+
git commit --allow-empty -m initial &&
370+
git branch matching-branch &&
371+
git tag matching-tag &&
372+
(
373+
cd otherrepo &&
374+
git commit --allow-empty -m initial &&
375+
git branch -m master master-in-other &&
376+
git branch branch-in-other &&
377+
git tag tag-in-other
378+
) &&
379+
git remote add other "$ROOT/otherrepo/.git" &&
380+
git fetch --no-tags other &&
381+
rm -f .git/FETCH_HEAD &&
382+
git init thirdrepo
383+
'
384+
385+
test_expect_success '__git_refs - simple' '
386+
cat >expected <<-EOF &&
387+
HEAD
388+
master
389+
matching-branch
390+
other/branch-in-other
391+
other/master-in-other
392+
matching-tag
393+
EOF
394+
(
395+
cur= &&
396+
__git_refs >"$actual"
397+
) &&
398+
test_cmp expected "$actual"
399+
'
400+
401+
test_expect_success '__git_refs - full refs' '
402+
cat >expected <<-EOF &&
403+
refs/heads/master
404+
refs/heads/matching-branch
405+
EOF
406+
(
407+
cur=refs/heads/ &&
408+
__git_refs >"$actual"
409+
) &&
410+
test_cmp expected "$actual"
411+
'
412+
413+
test_expect_success '__git_refs - repo given on the command line' '
414+
cat >expected <<-EOF &&
415+
HEAD
416+
branch-in-other
417+
master-in-other
418+
tag-in-other
419+
EOF
420+
(
421+
__git_dir="$ROOT/otherrepo/.git" &&
422+
cur= &&
423+
__git_refs >"$actual"
424+
) &&
425+
test_cmp expected "$actual"
426+
'
427+
428+
test_expect_success '__git_refs - remote on local file system' '
429+
cat >expected <<-EOF &&
430+
HEAD
431+
branch-in-other
432+
master-in-other
433+
tag-in-other
434+
EOF
435+
(
436+
cur= &&
437+
__git_refs otherrepo >"$actual"
438+
) &&
439+
test_cmp expected "$actual"
440+
'
441+
442+
test_expect_success '__git_refs - remote on local file system - full refs' '
443+
cat >expected <<-EOF &&
444+
refs/heads/branch-in-other
445+
refs/heads/master-in-other
446+
refs/tags/tag-in-other
447+
EOF
448+
(
449+
cur=refs/ &&
450+
__git_refs otherrepo >"$actual"
451+
) &&
452+
test_cmp expected "$actual"
453+
'
454+
455+
test_expect_success '__git_refs - configured remote' '
456+
cat >expected <<-EOF &&
457+
HEAD
458+
branch-in-other
459+
master-in-other
460+
EOF
461+
(
462+
cur= &&
463+
__git_refs other >"$actual"
464+
) &&
465+
test_cmp expected "$actual"
466+
'
467+
468+
test_expect_success '__git_refs - configured remote - full refs' '
469+
cat >expected <<-EOF &&
470+
refs/heads/branch-in-other
471+
refs/heads/master-in-other
472+
refs/tags/tag-in-other
473+
EOF
474+
(
475+
cur=refs/ &&
476+
__git_refs other >"$actual"
477+
) &&
478+
test_cmp expected "$actual"
479+
'
480+
481+
test_expect_failure '__git_refs - configured remote - repo given on the command line' '
482+
cat >expected <<-EOF &&
483+
HEAD
484+
branch-in-other
485+
master-in-other
486+
EOF
487+
(
488+
cd thirdrepo &&
489+
__git_dir="$ROOT/.git" &&
490+
cur= &&
491+
__git_refs other >"$actual"
492+
) &&
493+
test_cmp expected "$actual"
494+
'
495+
496+
test_expect_failure '__git_refs - configured remote - full refs - repo given on the command line' '
497+
cat >expected <<-EOF &&
498+
refs/heads/branch-in-other
499+
refs/heads/master-in-other
500+
refs/tags/tag-in-other
501+
EOF
502+
(
503+
cd thirdrepo &&
504+
__git_dir="$ROOT/.git" &&
505+
cur=refs/ &&
506+
__git_refs other >"$actual"
507+
) &&
508+
test_cmp expected "$actual"
509+
'
510+
511+
test_expect_failure '__git_refs - configured remote - remote name matches a directory' '
512+
cat >expected <<-EOF &&
513+
HEAD
514+
branch-in-other
515+
master-in-other
516+
EOF
517+
mkdir other &&
518+
test_when_finished "rm -rf other" &&
519+
(
520+
cur= &&
521+
__git_refs other >"$actual"
522+
) &&
523+
test_cmp expected "$actual"
524+
'
525+
526+
test_expect_failure '__git_refs - URL remote' '
527+
cat >expected <<-EOF &&
528+
HEAD
529+
branch-in-other
530+
master-in-other
531+
tag-in-other
532+
EOF
533+
(
534+
cur= &&
535+
__git_refs "file://$ROOT/otherrepo/.git" >"$actual"
536+
) &&
537+
test_cmp expected "$actual"
538+
'
539+
540+
test_expect_success '__git_refs - URL remote - full refs' '
541+
cat >expected <<-EOF &&
542+
refs/heads/branch-in-other
543+
refs/heads/master-in-other
544+
refs/tags/tag-in-other
545+
EOF
546+
(
547+
cur=refs/ &&
548+
__git_refs "file://$ROOT/otherrepo/.git" >"$actual"
549+
) &&
550+
test_cmp expected "$actual"
551+
'
552+
553+
test_expect_failure '__git_refs - non-existing remote' '
554+
(
555+
cur= &&
556+
__git_refs non-existing >"$actual"
557+
) &&
558+
test_must_be_empty "$actual"
559+
'
560+
561+
test_expect_success '__git_refs - non-existing remote - full refs' '
562+
(
563+
cur=refs/ &&
564+
__git_refs non-existing >"$actual"
565+
) &&
566+
test_must_be_empty "$actual"
567+
'
568+
569+
test_expect_failure '__git_refs - non-existing URL remote' '
570+
(
571+
cur= &&
572+
__git_refs "file://$ROOT/non-existing" >"$actual"
573+
) &&
574+
test_must_be_empty "$actual"
575+
'
576+
577+
test_expect_success '__git_refs - non-existing URL remote - full refs' '
578+
(
579+
cur=refs/ &&
580+
__git_refs "file://$ROOT/non-existing" >"$actual"
581+
) &&
582+
test_must_be_empty "$actual"
583+
'
584+
585+
test_expect_failure '__git_refs - not in a git repository' '
586+
(
587+
GIT_CEILING_DIRECTORIES="$ROOT" &&
588+
export GIT_CEILING_DIRECTORIES &&
589+
cd subdir &&
590+
cur= &&
591+
__git_refs >"$actual"
592+
) &&
593+
test_must_be_empty "$actual"
594+
'
595+
596+
test_expect_success '__git_refs - unique remote branches for git checkout DWIMery' '
597+
cat >expected <<-EOF &&
598+
HEAD
599+
master
600+
matching-branch
601+
other/ambiguous
602+
other/branch-in-other
603+
other/master-in-other
604+
remote/ambiguous
605+
remote/branch-in-remote
606+
matching-tag
607+
branch-in-other
608+
branch-in-remote
609+
master-in-other
610+
EOF
611+
for remote_ref in refs/remotes/other/ambiguous \
612+
refs/remotes/remote/ambiguous \
613+
refs/remotes/remote/branch-in-remote
614+
do
615+
git update-ref $remote_ref master &&
616+
test_when_finished "git update-ref -d $remote_ref"
617+
done &&
618+
(
619+
cur= &&
620+
__git_refs "" 1 >"$actual"
621+
) &&
622+
test_cmp expected "$actual"
623+
'
624+
625+
test_expect_success 'teardown after ref completion' '
626+
git branch -d matching-branch &&
627+
git tag -d matching-tag &&
628+
git remote remove other
629+
'
630+
368631
test_expect_success '__git_get_config_variables' '
369632
cat >expect <<-EOF &&
370633
name-1
@@ -483,7 +746,7 @@ test_expect_success 'git --help completion' '
483746
test_completion "git --help core" "core-tutorial "
484747
'
485748

486-
test_expect_success 'setup for ref completion' '
749+
test_expect_success 'setup for integration tests' '
487750
echo content >file1 &&
488751
echo more >file2 &&
489752
git add file1 file2 &&

0 commit comments

Comments
 (0)