]>
Commit | Line | Data |
---|---|---|
5c2bd8b7 BW |
1 | #!/bin/sh |
2 | ||
9fb2a970 | 3 | test_description='Test with test-tool submodule is-active |
5c2bd8b7 | 4 | |
9fb2a970 | 5 | This test verifies that `test-tool submodule is-active` correctly identifies |
5c2bd8b7 | 6 | submodules which are "active" and interesting to the user. |
9fb2a970 ÆAB |
7 | |
8 | This is a unit test of the submodule.c is_submodule_active() function, | |
9 | which is also indirectly tested elsewhere. | |
5c2bd8b7 BW |
10 | ' |
11 | ||
fe4c750f | 12 | TEST_PASSES_SANITIZE_LEAK=true |
5c2bd8b7 BW |
13 | . ./test-lib.sh |
14 | ||
15 | test_expect_success 'setup' ' | |
0d3beb71 | 16 | git config --global protocol.file.allow always && |
5c2bd8b7 BW |
17 | git init sub && |
18 | test_commit -C sub initial && | |
19 | git init super && | |
20 | test_commit -C super initial && | |
21 | git -C super submodule add ../sub sub1 && | |
22 | git -C super submodule add ../sub sub2 && | |
1b614c07 BW |
23 | |
24 | # Remove submodule.<name>.active entries in order to test in an | |
25 | # environment where only URLs are present in the conifg | |
26 | git -C super config --unset submodule.sub1.active && | |
27 | git -C super config --unset submodule.sub2.active && | |
28 | ||
5c2bd8b7 BW |
29 | git -C super commit -a -m "add 2 submodules at sub{1,2}" |
30 | ' | |
31 | ||
32 | test_expect_success 'is-active works with urls' ' | |
9fb2a970 ÆAB |
33 | test-tool -C super submodule is-active sub1 && |
34 | test-tool -C super submodule is-active sub2 && | |
5c2bd8b7 BW |
35 | |
36 | git -C super config --unset submodule.sub1.URL && | |
9fb2a970 | 37 | test_must_fail test-tool -C super submodule is-active sub1 && |
5c2bd8b7 | 38 | git -C super config submodule.sub1.URL ../sub && |
9fb2a970 | 39 | test-tool -C super submodule is-active sub1 |
5c2bd8b7 BW |
40 | ' |
41 | ||
a086f921 BW |
42 | test_expect_success 'is-active works with submodule.<name>.active config' ' |
43 | test_when_finished "git -C super config --unset submodule.sub1.active" && | |
44 | test_when_finished "git -C super config submodule.sub1.URL ../sub" && | |
45 | ||
46 | git -C super config --bool submodule.sub1.active "false" && | |
9fb2a970 | 47 | test_must_fail test-tool -C super submodule is-active sub1 && |
a086f921 BW |
48 | |
49 | git -C super config --bool submodule.sub1.active "true" && | |
50 | git -C super config --unset submodule.sub1.URL && | |
9fb2a970 | 51 | test-tool -C super submodule is-active sub1 |
a086f921 BW |
52 | ' |
53 | ||
9e2d884d | 54 | test_expect_success 'is-active handles submodule.active config missing a value' ' |
1c7e239b ÆAB |
55 | cp super/.git/config super/.git/config.orig && |
56 | test_when_finished mv super/.git/config.orig super/.git/config && | |
57 | ||
58 | cat >>super/.git/config <<-\EOF && | |
59 | [submodule] | |
60 | active | |
61 | EOF | |
62 | ||
9e2d884d ÆAB |
63 | cat >expect <<-\EOF && |
64 | error: missing value for '\''submodule.active'\'' | |
65 | EOF | |
66 | test-tool -C super submodule is-active sub1 2>actual && | |
67 | test_cmp expect actual | |
1c7e239b ÆAB |
68 | ' |
69 | ||
a086f921 BW |
70 | test_expect_success 'is-active works with basic submodule.active config' ' |
71 | test_when_finished "git -C super config submodule.sub1.URL ../sub" && | |
72 | test_when_finished "git -C super config --unset-all submodule.active" && | |
73 | ||
74 | git -C super config --add submodule.active "." && | |
75 | git -C super config --unset submodule.sub1.URL && | |
76 | ||
9fb2a970 ÆAB |
77 | test-tool -C super submodule is-active sub1 && |
78 | test-tool -C super submodule is-active sub2 | |
a086f921 BW |
79 | ' |
80 | ||
81 | test_expect_success 'is-active correctly works with paths that are not submodules' ' | |
82 | test_when_finished "git -C super config --unset-all submodule.active" && | |
83 | ||
9fb2a970 | 84 | test_must_fail test-tool -C super submodule is-active not-a-submodule && |
a086f921 BW |
85 | |
86 | git -C super config --add submodule.active "." && | |
9fb2a970 | 87 | test_must_fail test-tool -C super submodule is-active not-a-submodule |
a086f921 BW |
88 | ' |
89 | ||
90 | test_expect_success 'is-active works with exclusions in submodule.active config' ' | |
91 | test_when_finished "git -C super config --unset-all submodule.active" && | |
92 | ||
93 | git -C super config --add submodule.active "." && | |
94 | git -C super config --add submodule.active ":(exclude)sub1" && | |
95 | ||
9fb2a970 ÆAB |
96 | test_must_fail test-tool -C super submodule is-active sub1 && |
97 | test-tool -C super submodule is-active sub2 | |
a086f921 BW |
98 | ' |
99 | ||
100 | test_expect_success 'is-active with submodule.active and submodule.<name>.active' ' | |
101 | test_when_finished "git -C super config --unset-all submodule.active" && | |
102 | test_when_finished "git -C super config --unset submodule.sub1.active" && | |
103 | test_when_finished "git -C super config --unset submodule.sub2.active" && | |
104 | ||
105 | git -C super config --add submodule.active "sub1" && | |
106 | git -C super config --bool submodule.sub1.active "false" && | |
107 | git -C super config --bool submodule.sub2.active "true" && | |
108 | ||
9fb2a970 ÆAB |
109 | test_must_fail test-tool -C super submodule is-active sub1 && |
110 | test-tool -C super submodule is-active sub2 | |
a086f921 BW |
111 | ' |
112 | ||
1b614c07 BW |
113 | test_expect_success 'is-active, submodule.active and submodule add' ' |
114 | test_when_finished "rm -rf super2" && | |
115 | git init super2 && | |
116 | test_commit -C super2 initial && | |
117 | git -C super2 config --add submodule.active "sub*" && | |
118 | ||
119 | # submodule add should only add submodule.<name>.active | |
120 | # to the config if not matched by the pathspec | |
121 | git -C super2 submodule add ../sub sub1 && | |
122 | test_must_fail git -C super2 config --get submodule.sub1.active && | |
123 | ||
124 | git -C super2 submodule add ../sub mod && | |
125 | git -C super2 config --get submodule.mod.active | |
126 | ' | |
127 | ||
5c2bd8b7 | 128 | test_done |