Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (C) 2006 Martin Waitz <tali@admingilde.org> |
| 4 | # |
| 5 | |
| 6 | test_description='test transitive info/alternate entries' |
| 7 | . ./test-lib.sh |
| 8 | |
| 9 | # test that a file is not reachable in the current repository |
| 10 | # but that it is after creating a info/alternate entry |
| 11 | reachable_via() { |
| 12 | alternate="$1" |
| 13 | file="$2" |
| 14 | if git cat-file -e "HEAD:$file"; then return 1; fi |
| 15 | echo "$alternate" >> .git/objects/info/alternate |
| 16 | git cat-file -e "HEAD:$file" |
| 17 | } |
| 18 | |
| 19 | test_valid_repo() { |
Junio C Hamano | df391b1 | 2007-01-28 16:33:58 -0800 | [diff] [blame] | 20 | git fsck --full > fsck.log && |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 21 | test `wc -l < fsck.log` = 0 |
| 22 | } |
| 23 | |
| 24 | base_dir=`pwd` |
| 25 | |
| 26 | test_expect_success 'preparing first repository' \ |
| 27 | 'test_create_repo A && cd A && |
| 28 | echo "Hello World" > file1 && |
| 29 | git add file1 && |
| 30 | git commit -m "Initial commit" file1 && |
| 31 | git repack -a -d && |
Junio C Hamano | 026aa93 | 2007-01-21 21:29:44 -0800 | [diff] [blame] | 32 | git prune' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 33 | |
| 34 | cd "$base_dir" |
| 35 | |
| 36 | test_expect_success 'preparing second repository' \ |
| 37 | 'git clone -l -s A B && cd B && |
| 38 | echo "foo bar" > file2 && |
| 39 | git add file2 && |
| 40 | git commit -m "next commit" file2 && |
| 41 | git repack -a -d -l && |
Junio C Hamano | 026aa93 | 2007-01-21 21:29:44 -0800 | [diff] [blame] | 42 | git prune' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 43 | |
| 44 | cd "$base_dir" |
| 45 | |
| 46 | test_expect_success 'preparing third repository' \ |
| 47 | 'git clone -l -s B C && cd C && |
| 48 | echo "Goodbye, cruel world" > file3 && |
| 49 | git add file3 && |
| 50 | git commit -m "one more" file3 && |
| 51 | git repack -a -d -l && |
Junio C Hamano | 026aa93 | 2007-01-21 21:29:44 -0800 | [diff] [blame] | 52 | git prune' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 53 | |
| 54 | cd "$base_dir" |
| 55 | |
Alex Riesen | 9288bed | 2008-01-21 21:53:25 +0100 | [diff] [blame] | 56 | test_expect_success 'creating too deep nesting' \ |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 57 | 'git clone -l -s C D && |
| 58 | git clone -l -s D E && |
| 59 | git clone -l -s E F && |
| 60 | git clone -l -s F G && |
Alex Riesen | 9288bed | 2008-01-21 21:53:25 +0100 | [diff] [blame] | 61 | git clone -l -s G H' |
| 62 | |
| 63 | test_expect_success 'invalidity of deepest repository' \ |
| 64 | 'cd H && { |
| 65 | test_valid_repo |
| 66 | test $? -ne 0 |
| 67 | }' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 68 | |
| 69 | cd "$base_dir" |
| 70 | |
| 71 | test_expect_success 'validity of third repository' \ |
| 72 | 'cd C && |
| 73 | test_valid_repo' |
| 74 | |
| 75 | cd "$base_dir" |
| 76 | |
| 77 | test_expect_success 'validity of fourth repository' \ |
| 78 | 'cd D && |
| 79 | test_valid_repo' |
| 80 | |
| 81 | cd "$base_dir" |
| 82 | |
| 83 | test_expect_success 'breaking of loops' \ |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 84 | 'echo "$base_dir"/B/.git/objects >> "$base_dir"/A/.git/objects/info/alternates&& |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 85 | cd C && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 86 | test_valid_repo' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 87 | |
| 88 | cd "$base_dir" |
| 89 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 90 | test_expect_success 'that info/alternates is necessary' \ |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 91 | 'cd C && |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 92 | rm -f .git/objects/info/alternates && |
| 93 | ! (test_valid_repo)' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 94 | |
| 95 | cd "$base_dir" |
| 96 | |
| 97 | test_expect_success 'that relative alternate is possible for current dir' \ |
| 98 | 'cd C && |
| 99 | echo "../../../B/.git/objects" > .git/objects/info/alternates && |
| 100 | test_valid_repo' |
| 101 | |
| 102 | cd "$base_dir" |
| 103 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 104 | test_expect_success \ |
| 105 | 'that relative alternate is only possible for current dir' ' |
| 106 | cd D && |
| 107 | ! (test_valid_repo) |
| 108 | ' |
Martin Waitz | dd05ea1 | 2006-05-07 20:19:47 +0200 | [diff] [blame] | 109 | |
| 110 | cd "$base_dir" |
| 111 | |
| 112 | test_done |