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