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