Raw
1 #!/bin/sh
2 #
3 # Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
4 #
5
6 test_description='test transitive info/alternate entries'
7
8 . ./test-lib.sh
9
10 test_expect_success 'preparing first repository' '
11 test_create_repo A && (
12 cd A &&
13 echo "Hello World" > file1 &&
14 git add file1 &&
15 git commit -m "Initial commit" file1 &&
16 git repack -a -d &&
17 git prune
18 )
19 '
20
21 test_expect_success 'preparing second repository' '
22 git clone -l -s A B && (
23 cd B &&
24 echo "foo bar" > file2 &&
25 git add file2 &&
26 git commit -m "next commit" file2 &&
27 git repack -a -d -l &&
28 git prune
29 )
30 '
31
32 test_expect_success 'preparing third repository' '
33 git clone -l -s B C && (
34 cd C &&
35 echo "Goodbye, cruel world" > file3 &&
36 git add file3 &&
37 git commit -m "one more" file3 &&
38 git repack -a -d -l &&
39 git prune
40 )
41 '
42
43 test_expect_success 'count-objects shows the alternates' '
44 cat >expect <<-EOF &&
45 alternate: $(pwd)/B/.git/objects
46 alternate: $(pwd)/A/.git/objects
47 EOF
48 git -C C count-objects -v >actual &&
49 grep ^alternate: actual >actual.alternates &&
50 test_cmp expect actual.alternates
51 '
52
53 # Note: These tests depend on the hard-coded value of 5 as the maximum depth
54 # we will follow recursion. We start the depth at 0 and count links, not
55 # repositories. This means that in a chain like:
56 #
57 # A --> B --> C --> D --> E --> F --> G --> H
58 # 0 1 2 3 4 5 6
59 #
60 # we are OK at "G", but break at "H", even though "H" is actually the 8th
61 # repository, not the 6th, which you might expect. Counting the links allows
62 # N+1 repositories, and counting from 0 to 5 inclusive allows 6 links.
63 #
64 # Note also that we must use "--bare -l" to make the link to H. The "-l"
65 # ensures we do not do a connectivity check, and the "--bare" makes sure
66 # we do not try to checkout the result (which needs objects), either of
67 # which would cause the clone to fail.
68 test_expect_success 'creating too deep nesting' '
69 git clone -l -s C D &&
70 git clone -l -s D E &&
71 git clone -l -s E F &&
72 git clone -l -s F G &&
73 git clone --bare -l -s G H
74 '
75
76 test_expect_success 'validity of seventh repository' '
77 git -C G fsck
78 '
79
80 test_expect_success 'invalidity of eighth repository' '
81 test_must_fail git -C H fsck
82 '
83
84 test_expect_success 'breaking of loops' '
85 echo "$(pwd)"/B/.git/objects >>A/.git/objects/info/alternates &&
86 git -C C fsck
87 '
88
89 test_expect_success 'that info/alternates is necessary' '
90 rm -f C/.git/objects/info/alternates &&
91 test_must_fail git -C C fsck
92 '
93
94 test_expect_success 'that relative alternate is possible for current dir' '
95 echo "../../../B/.git/objects" >C/.git/objects/info/alternates &&
96 git fsck
97 '
98
99 test_expect_success 'that relative alternate is recursive' '
100 git -C D fsck
101 '
102
103 # we can reach "A" from our new repo both directly, and via "C".
104 # The deep/subdir is there to make sure we are not doing a stupid
105 # pure-text comparison of the alternate names.
106 test_expect_success 'relative duplicates are eliminated' '
107 mkdir -p deep/subdir &&
108 git init --bare deep/subdir/duplicate.git &&
109 cat >deep/subdir/duplicate.git/objects/info/alternates <<-\EOF &&
110 ../../../../C/.git/objects
111 ../../../../A/.git/objects
112 EOF
113 cat >expect <<-EOF &&
114 alternate: $(pwd)/C/.git/objects
115 alternate: $(pwd)/B/.git/objects
116 alternate: $(pwd)/A/.git/objects
117 EOF
118 git -C deep/subdir/duplicate.git count-objects -v >actual &&
119 grep ^alternate: actual >actual.alternates &&
120 test_cmp expect actual.alternates
121 '
122
123 test_expect_success CASE_INSENSITIVE_FS 'dup finding can be case-insensitive' '
124 git init --bare insensitive.git &&
125 # the previous entry for "A" will have used uppercase
126 cat >insensitive.git/objects/info/alternates <<-\EOF &&
127 ../../C/.git/objects
128 ../../a/.git/objects
129 EOF
130 cat >expect <<-EOF &&
131 alternate: $(pwd)/C/.git/objects
132 alternate: $(pwd)/B/.git/objects
133 alternate: $(pwd)/A/.git/objects
134 EOF
135 git -C insensitive.git count-objects -v >actual &&
136 grep ^alternate: actual >actual.alternates &&
137 test_cmp expect actual.alternates
138 '
139
140 test_done