1#!/bin/sh
2#
3# Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
4#
5
6test_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
11reachable_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
19test_valid_repo() {
20 git fsck-objects --full > fsck.log &&
21 test `wc -l < fsck.log` = 0
22}
23
24base_dir=`pwd`
25
26test_expect_success 'preparing first repository' \
27'test_create_repo A && cd A &&
28echo "Hello World" > file1 &&
29git add file1 &&
30git commit -m "Initial commit" file1 &&
31git repack -a -d &&
32git prune'
33
34cd "$base_dir"
35
36test_expect_success 'preparing second repository' \
37'git clone -l -s A B && cd B &&
38echo "foo bar" > file2 &&
39git add file2 &&
40git commit -m "next commit" file2 &&
41git repack -a -d -l &&
42git prune'
43
44cd "$base_dir"
45
46test_expect_success 'preparing third repository' \
47'git clone -l -s B C && cd C &&
48echo "Goodbye, cruel world" > file3 &&
49git add file3 &&
50git commit -m "one more" file3 &&
51git repack -a -d -l &&
52git prune'
53
54cd "$base_dir"
55
56test_expect_failure 'creating too deep nesting' \
57'git clone -l -s C D &&
58git clone -l -s D E &&
59git clone -l -s E F &&
60git clone -l -s F G &&
61git clone -l -s G H &&
62cd H &&
63test_valid_repo'
64
65cd "$base_dir"
66
67test_expect_success 'validity of third repository' \
68'cd C &&
69test_valid_repo'
70
71cd "$base_dir"
72
73test_expect_success 'validity of fourth repository' \
74'cd D &&
75test_valid_repo'
76
77cd "$base_dir"
78
79test_expect_success 'breaking of loops' \
80"echo '$base_dir/B/.git/objects' >> '$base_dir'/A/.git/objects/info/alternates&&
81cd C &&
82test_valid_repo"
83
84cd "$base_dir"
85
86test_expect_failure 'that info/alternates is necessary' \
87'cd C &&
88rm .git/objects/info/alternates &&
89test_valid_repo'
90
91cd "$base_dir"
92
93test_expect_success 'that relative alternate is possible for current dir' \
94'cd C &&
95echo "../../../B/.git/objects" > .git/objects/info/alternates &&
96test_valid_repo'
97
98cd "$base_dir"
99
100test_expect_failure 'that relative alternate is only possible for current dir' \
101'cd D &&
102test_valid_repo'
103
104cd "$base_dir"
105
106test_done
107