Commit | Line | Data |
---|---|---|
b3256eb8 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='selecting remote repo in ambiguous cases' | |
4 | . ./test-lib.sh | |
5 | ||
6 | reset() { | |
7 | rm -rf foo foo.git fetch clone | |
8 | } | |
9 | ||
10 | make_tree() { | |
11 | git init "$1" && | |
12 | (cd "$1" && test_commit "$1") | |
13 | } | |
14 | ||
15 | make_bare() { | |
16 | git init --bare "$1" && | |
17 | (cd "$1" && | |
14a771ee | 18 | tree=$(git hash-object -w -t tree /dev/null) && |
b3256eb8 JK |
19 | commit=$(echo "$1" | git commit-tree $tree) && |
20 | git update-ref HEAD $commit | |
21 | ) | |
22 | } | |
23 | ||
24 | get() { | |
25 | git init --bare fetch && | |
26 | (cd fetch && git fetch "../$1") && | |
27 | git clone "$1" clone | |
28 | } | |
29 | ||
30 | check() { | |
31 | echo "$1" >expect && | |
32 | (cd fetch && git log -1 --format=%s FETCH_HEAD) >actual.fetch && | |
33 | (cd clone && git log -1 --format=%s HEAD) >actual.clone && | |
34 | test_cmp expect actual.fetch && | |
35 | test_cmp expect actual.clone | |
36 | } | |
37 | ||
38 | test_expect_success 'find .git dir in worktree' ' | |
39 | reset && | |
40 | make_tree foo && | |
41 | get foo && | |
42 | check foo | |
43 | ' | |
44 | ||
45 | test_expect_success 'automagically add .git suffix' ' | |
46 | reset && | |
47 | make_bare foo.git && | |
48 | get foo && | |
49 | check foo.git | |
50 | ' | |
51 | ||
52 | test_expect_success 'automagically add .git suffix to worktree' ' | |
53 | reset && | |
54 | make_tree foo.git && | |
55 | get foo && | |
56 | check foo.git | |
57 | ' | |
58 | ||
59 | test_expect_success 'prefer worktree foo over bare foo.git' ' | |
60 | reset && | |
61 | make_tree foo && | |
62 | make_bare foo.git && | |
63 | get foo && | |
64 | check foo | |
65 | ' | |
66 | ||
67 | test_expect_success 'prefer bare foo over bare foo.git' ' | |
68 | reset && | |
69 | make_bare foo && | |
70 | make_bare foo.git && | |
71 | get foo && | |
72 | check foo | |
73 | ' | |
74 | ||
75 | test_expect_success 'disambiguate with full foo.git' ' | |
76 | reset && | |
77 | make_bare foo && | |
78 | make_bare foo.git && | |
79 | get foo.git && | |
80 | check foo.git | |
81 | ' | |
82 | ||
83 | test_expect_success 'we are not fooled by non-git foo directory' ' | |
84 | reset && | |
85 | make_bare foo.git && | |
86 | mkdir foo && | |
87 | get foo && | |
88 | check foo.git | |
89 | ' | |
90 | ||
91 | test_expect_success 'prefer inner .git over outer bare' ' | |
92 | reset && | |
93 | make_tree foo && | |
94 | make_bare foo.git && | |
95 | mv foo/.git foo.git && | |
96 | get foo.git && | |
97 | check foo | |
98 | ' | |
99 | ||
100 | test_done |