@@ -49,63 +49,136 @@ test_expect_success 'setup - add an example entry to .gitmodules' '
49
49
git config submodule.example.url git://example.com/init.git
50
50
'
51
51
52
- test_expect_success ' Prepare submodule add testing' '
53
- submodurl=$(pwd)
52
+ test_expect_success ' setup - repository to add submodules to' '
53
+ git init addtest
54
+ '
55
+
56
+ # The 'submodule add' tests need some repository to add as a submodule.
57
+ # The trash directory is a good one as any.
58
+ submodurl=$TRASH_DIRECTORY
59
+
60
+ listbranches () {
61
+ git for-each-ref --format=' %(refname)' ' refs/heads/*'
62
+ }
63
+
64
+ inspect () {
65
+ dir=$1 &&
66
+ dotdot=" ${2:- ..} " &&
67
+
54
68
(
55
- mkdir addtest &&
56
- cd addtest &&
57
- git init
69
+ cd " $dir " &&
70
+ listbranches > " $dotdot /heads" &&
71
+ { git symbolic-ref HEAD || : ; } > " $dotdot /head" &&
72
+ git update-index --refresh &&
73
+ git diff-files --exit-code &&
74
+ git clean -n -d -x > " $dotdot /untracked"
58
75
)
59
- '
76
+ }
60
77
61
78
test_expect_success ' submodule add' '
79
+ echo "refs/heads/master" >expect &&
80
+ >empty &&
81
+
62
82
(
63
83
cd addtest &&
64
84
git submodule add "$submodurl" submod &&
65
85
git submodule init
66
- )
86
+ ) &&
87
+
88
+ rm -f heads head untracked &&
89
+ inspect addtest/submod ../.. &&
90
+ test_cmp expect heads &&
91
+ test_cmp expect head &&
92
+ test_cmp empty untracked
67
93
'
68
94
69
95
test_expect_success ' submodule add --branch' '
96
+ echo "refs/heads/initial" >expect-head &&
97
+ cat <<-\EOF >expect-heads &&
98
+ refs/heads/initial
99
+ refs/heads/master
100
+ EOF
101
+ >empty &&
102
+
70
103
(
71
104
cd addtest &&
72
105
git submodule add -b initial "$submodurl" submod-branch &&
73
- git submodule init &&
74
- cd submod-branch &&
75
- git branch | grep initial
76
- )
106
+ git submodule init
107
+ ) &&
108
+
109
+ rm -f heads head untracked &&
110
+ inspect addtest/submod-branch ../.. &&
111
+ test_cmp expect-heads heads &&
112
+ test_cmp expect-head head &&
113
+ test_cmp empty untracked
77
114
'
78
115
79
116
test_expect_success ' submodule add with ./ in path' '
117
+ echo "refs/heads/master" >expect &&
118
+ >empty &&
119
+
80
120
(
81
121
cd addtest &&
82
122
git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
83
123
git submodule init
84
- )
124
+ ) &&
125
+
126
+ rm -f heads head untracked &&
127
+ inspect addtest/dotsubmod/frotz ../../.. &&
128
+ test_cmp expect heads &&
129
+ test_cmp expect head &&
130
+ test_cmp empty untracked
85
131
'
86
132
87
133
test_expect_success ' submodule add with // in path' '
134
+ echo "refs/heads/master" >expect &&
135
+ >empty &&
136
+
88
137
(
89
138
cd addtest &&
90
139
git submodule add "$submodurl" slashslashsubmod///frotz// &&
91
140
git submodule init
92
- )
141
+ ) &&
142
+
143
+ rm -f heads head untracked &&
144
+ inspect addtest/slashslashsubmod/frotz ../../.. &&
145
+ test_cmp expect heads &&
146
+ test_cmp expect head &&
147
+ test_cmp empty untracked
93
148
'
94
149
95
150
test_expect_success ' submodule add with /.. in path' '
151
+ echo "refs/heads/master" >expect &&
152
+ >empty &&
153
+
96
154
(
97
155
cd addtest &&
98
156
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
99
157
git submodule init
100
- )
158
+ ) &&
159
+
160
+ rm -f heads head untracked &&
161
+ inspect addtest/realsubmod ../.. &&
162
+ test_cmp expect heads &&
163
+ test_cmp expect head &&
164
+ test_cmp empty untracked
101
165
'
102
166
103
167
test_expect_success ' submodule add with ./, /.. and // in path' '
168
+ echo "refs/heads/master" >expect &&
169
+ >empty &&
170
+
104
171
(
105
172
cd addtest &&
106
173
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
107
174
git submodule init
108
- )
175
+ ) &&
176
+
177
+ rm -f heads head untracked &&
178
+ inspect addtest/realsubmod2 ../.. &&
179
+ test_cmp expect heads &&
180
+ test_cmp expect head &&
181
+ test_cmp empty untracked
109
182
'
110
183
111
184
test_expect_success ' status should fail for unmapped paths' '
0 commit comments