Commit 7dbf4039ae0881407fc9ead24c09c1d7cfd4103a

Vicent Martí 2013-03-19T11:47:23

Merge pull request #1423 from arrbee/submodule-status-errors Three submodule status bug fixes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
diff --git a/src/diff.c b/src/diff.c
index fc37d13..fb69f89 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -512,13 +512,17 @@ static int maybe_modified(
 			status = GIT_DELTA_UNMODIFIED;
 
 		else if (S_ISGITLINK(nmode)) {
+			int err;
 			git_submodule *sub;
 
 			if ((diff->opts.flags & GIT_DIFF_IGNORE_SUBMODULES) != 0)
 				status = GIT_DELTA_UNMODIFIED;
-			else if (git_submodule_lookup(&sub, diff->repo, nitem->path) < 0)
-				return -1;
-			else if (git_submodule_ignore(sub) == GIT_SUBMODULE_IGNORE_ALL)
+			else if ((err = git_submodule_lookup(&sub, diff->repo, nitem->path)) < 0) {
+				if (err == GIT_EEXISTS)
+					status = GIT_DELTA_UNMODIFIED;
+				else
+					return err;
+			} else if (git_submodule_ignore(sub) == GIT_SUBMODULE_IGNORE_ALL)
 				status = GIT_DELTA_UNMODIFIED;
 			else {
 				unsigned int sm_status = 0;
diff --git a/src/diff_output.c b/src/diff_output.c
index b938cc0..fba6129 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -299,7 +299,12 @@ static int get_workdir_sm_content(
 
 	if ((error = git_submodule_lookup(&sm, ctxt->repo, file->path)) < 0 ||
 		(error = git_submodule_status(&sm_status, sm)) < 0)
+	{
+		/* GIT_EEXISTS means a "submodule" that has not been git added */
+		if (error == GIT_EEXISTS)
+			error = 0;
 		return error;
+	}
 
 	/* update OID if we didn't have it previously */
 	if ((file->flags & GIT_DIFF_FLAG_VALID_OID) == 0) {
diff --git a/src/iterator.c b/src/iterator.c
index b15bced..805a3c9 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -1150,11 +1150,13 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
 		return 0;
 
 	/* detect submodules */
-
 	error = git_submodule_lookup(NULL, wi->base.repo, wi->entry.path);
 	if (error == GIT_ENOTFOUND)
 		giterr_clear();
 
+	if (error == GIT_EEXISTS) /* if contains .git, treat as untracked submod */
+		error = 0;
+
 	/* if submodule, mark as GITLINK and remove trailing slash */
 	if (!error) {
 		size_t len = strlen(wi->entry.path);
diff --git a/src/path.c b/src/path.c
index 5767fae..6437979 100644
--- a/src/path.c
+++ b/src/path.c
@@ -877,15 +877,22 @@ int git_path_dirload_with_stat(
 		if (cmp_len && strncomp(ps->path, end_stat, cmp_len) > 0)
 			continue;
 
+		git_buf_truncate(&full, prefix_len);
+
 		if ((error = git_buf_joinpath(&full, full.ptr, ps->path)) < 0 ||
 			(error = git_path_lstat(full.ptr, &ps->st)) < 0)
 			break;
 
-		git_buf_truncate(&full, prefix_len);
-
 		if (S_ISDIR(ps->st.st_mode)) {
-			ps->path[ps->path_len++] = '/';
-			ps->path[ps->path_len] = '\0';
+			if ((error = git_buf_joinpath(&full, full.ptr, ".git")) < 0)
+				break;
+
+			if (p_access(full.ptr, F_OK) == 0) {
+				ps->st.st_mode = GIT_FILEMODE_COMMIT;
+			} else {
+				ps->path[ps->path_len++] = '/';
+				ps->path[ps->path_len] = '\0';
+			}
 		}
 	}
 
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index f1efdfb..15b1046 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -720,13 +720,13 @@ void test_diff_iterator__workdir_builtin_ignores(void)
 		{ "root_test2", false },
 		{ "root_test3", false },
 		{ "root_test4.txt", false },
-		{ "sub/", false },
+		{ "sub", false },
 		{ "sub/.gitattributes", false },
 		{ "sub/abc", false },
 		{ "sub/dir/", true },
 		{ "sub/file", false },
 		{ "sub/ign/", true },
-		{ "sub/sub/", false },
+		{ "sub/sub", false },
 		{ "sub/sub/.gitattributes", false },
 		{ "sub/sub/dir", false }, /* file is not actually a dir */
 		{ "sub/sub/file", false },
@@ -746,9 +746,13 @@ void test_diff_iterator__workdir_builtin_ignores(void)
 		cl_assert_equal_s(expected[idx].path, entry->path);
 		cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
 
-		if (!ignored && S_ISDIR(entry->mode))
+		if (!ignored &&
+			(entry->mode == GIT_FILEMODE_TREE ||
+			 entry->mode == GIT_FILEMODE_COMMIT))
+		{
+			/* it is possible to advance "into" a submodule */
 			cl_git_pass(git_iterator_advance_into(&entry, i));
-		else
+		} else
 			cl_git_pass(git_iterator_advance(&entry, i));
 	}
 
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 7e8915c..983465b 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -936,7 +936,8 @@ void test_diff_workdir__submodules(void)
 	p_rename("submod2_target/.gitted", "submod2_target/.git");
 
 	rewrite_gitmodules(git_repository_workdir(g_repo));
-	p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git");
+	p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+	p_rename("submod2/not/.gitted", "submod2/not/.git");
 
 	cl_fixture_cleanup("submod2_target");
 
@@ -954,21 +955,22 @@ void test_diff_workdir__submodules(void)
 	/* essentially doing: git diff 873585b94bdeabccea991ea5e3ec1a277895b698 */
 
 	memset(&exp, 0, sizeof(exp));
+
 	cl_git_pass(git_diff_foreach(
 		diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
 
-	/* the following differs from "git diff 873585" by one "untracked" file
-	 * because the diff list includes the "not_submodule/" directory which
-	 * is not displayed in the text diff.
+	/* the following differs from "git diff 873585" by two "untracked" file
+	 * because the diff list includes the "not" and "not-submodule" dirs which
+	 * are not displayed in the text diff.
 	 */
 
-	cl_assert_equal_i(10, exp.files);
+	cl_assert_equal_i(11, exp.files);
 
 	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
 	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
 	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
 	cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
-	cl_assert_equal_i(9, exp.file_status[GIT_DELTA_UNTRACKED]);
+	cl_assert_equal_i(10, exp.file_status[GIT_DELTA_UNTRACKED]);
 
 	/* the following numbers match "git diff 873585" exactly */
 
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/HEAD b/tests-clar/resources/submod2/not-submodule/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/config b/tests-clar/resources/submod2/not-submodule/.gitted/config
new file mode 100644
index 0000000..af10792
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/description b/tests-clar/resources/submod2/not-submodule/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/index b/tests-clar/resources/submod2/not-submodule/.gitted/index
new file mode 100644
index 0000000..f3fafa5
Binary files /dev/null and b/tests-clar/resources/submod2/not-submodule/.gitted/index differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/info/exclude b/tests-clar/resources/submod2/not-submodule/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/info/exclude
@@ -0,0 +1,6 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD b/tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD
new file mode 100644
index 0000000..1749e7d
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/logs/HEAD
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700	commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master b/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master
new file mode 100644
index 0000000..1749e7d
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/logs/refs/heads/master
@@ -0,0 +1 @@
+0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700	commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444 b/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444
new file mode 100644
index 0000000..8892531
Binary files /dev/null and b/tests-clar/resources/submod2/not-submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444 differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627 b/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627
new file mode 100644
index 0000000..c4e1a77
Binary files /dev/null and b/tests-clar/resources/submod2/not-submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627 differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e b/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e
new file mode 100644
index 0000000..e9f1942
Binary files /dev/null and b/tests-clar/resources/submod2/not-submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e differ
diff --git a/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master b/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master
new file mode 100644
index 0000000..0bd8514
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/.gitted/refs/heads/master
@@ -0,0 +1 @@
+68e92c611b80ee1ed8f38314ff9577f0d15b2444
diff --git a/tests-clar/resources/submod2/not-submodule/README.txt b/tests-clar/resources/submod2/not-submodule/README.txt
new file mode 100644
index 0000000..71ff992
--- /dev/null
+++ b/tests-clar/resources/submod2/not-submodule/README.txt
@@ -0,0 +1 @@
+This is a git repo but not a submodule
diff --git a/tests-clar/resources/submod2/not/.gitted/notempty b/tests-clar/resources/submod2/not/.gitted/notempty
new file mode 100644
index 0000000..9b33ac4
--- /dev/null
+++ b/tests-clar/resources/submod2/not/.gitted/notempty
@@ -0,0 +1 @@
+fooled you
diff --git a/tests-clar/resources/submod2/not/README.txt b/tests-clar/resources/submod2/not/README.txt
new file mode 100644
index 0000000..4f6935b
--- /dev/null
+++ b/tests-clar/resources/submod2/not/README.txt
@@ -0,0 +1 @@
+what am I really
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/COMMIT_EDITMSG b/tests-clar/resources/submod2/not_submodule/.gitted/COMMIT_EDITMSG
deleted file mode 100644
index 5852f44..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/COMMIT_EDITMSG
+++ /dev/null
@@ -1 +0,0 @@
-Initial commit
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/HEAD b/tests-clar/resources/submod2/not_submodule/.gitted/HEAD
deleted file mode 100644
index cb089cd..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/HEAD
+++ /dev/null
@@ -1 +0,0 @@
-ref: refs/heads/master
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/config b/tests-clar/resources/submod2/not_submodule/.gitted/config
deleted file mode 100644
index af10792..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/config
+++ /dev/null
@@ -1,6 +0,0 @@
-[core]
-	repositoryformatversion = 0
-	filemode = true
-	bare = false
-	logallrefupdates = true
-	ignorecase = true
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/description b/tests-clar/resources/submod2/not_submodule/.gitted/description
deleted file mode 100644
index 498b267..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/description
+++ /dev/null
@@ -1 +0,0 @@
-Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/index b/tests-clar/resources/submod2/not_submodule/.gitted/index
deleted file mode 100644
index f3fafa5..0000000
Binary files a/tests-clar/resources/submod2/not_submodule/.gitted/index and /dev/null differ
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/info/exclude b/tests-clar/resources/submod2/not_submodule/.gitted/info/exclude
deleted file mode 100644
index a5196d1..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/info/exclude
+++ /dev/null
@@ -1,6 +0,0 @@
-# git ls-files --others --exclude-from=.git/info/exclude
-# Lines that start with '#' are comments.
-# For a project mostly in C, the following would be a good set of
-# exclude patterns (uncomment them if you want to use them):
-# *.[oa]
-# *~
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/logs/HEAD b/tests-clar/resources/submod2/not_submodule/.gitted/logs/HEAD
deleted file mode 100644
index 1749e7d..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/logs/HEAD
+++ /dev/null
@@ -1 +0,0 @@
-0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700	commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/logs/refs/heads/master b/tests-clar/resources/submod2/not_submodule/.gitted/logs/refs/heads/master
deleted file mode 100644
index 1749e7d..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/logs/refs/heads/master
+++ /dev/null
@@ -1 +0,0 @@
-0000000000000000000000000000000000000000 68e92c611b80ee1ed8f38314ff9577f0d15b2444 Russell Belfer <rb@github.com> 1342560358 -0700	commit (initial): Initial commit
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444 b/tests-clar/resources/submod2/not_submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444
deleted file mode 100644
index 8892531..0000000
Binary files a/tests-clar/resources/submod2/not_submodule/.gitted/objects/68/e92c611b80ee1ed8f38314ff9577f0d15b2444 and /dev/null differ
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627 b/tests-clar/resources/submod2/not_submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627
deleted file mode 100644
index c4e1a77..0000000
Binary files a/tests-clar/resources/submod2/not_submodule/.gitted/objects/71/ff9927d7c8a5639e062c38a7d35c433c424627 and /dev/null differ
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e b/tests-clar/resources/submod2/not_submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e
deleted file mode 100644
index e9f1942..0000000
Binary files a/tests-clar/resources/submod2/not_submodule/.gitted/objects/f0/1d56b18efd353ef2bb93a4585d590a0847195e and /dev/null differ
diff --git a/tests-clar/resources/submod2/not_submodule/.gitted/refs/heads/master b/tests-clar/resources/submod2/not_submodule/.gitted/refs/heads/master
deleted file mode 100644
index 0bd8514..0000000
--- a/tests-clar/resources/submod2/not_submodule/.gitted/refs/heads/master
+++ /dev/null
@@ -1 +0,0 @@
-68e92c611b80ee1ed8f38314ff9577f0d15b2444
diff --git a/tests-clar/resources/submod2/not_submodule/README.txt b/tests-clar/resources/submod2/not_submodule/README.txt
deleted file mode 100644
index 71ff992..0000000
--- a/tests-clar/resources/submod2/not_submodule/README.txt
+++ /dev/null
@@ -1 +0,0 @@
-This is a git repo but not a submodule
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c
index 868b51e..acf8f64 100644
--- a/tests-clar/submodule/lookup.c
+++ b/tests-clar/submodule/lookup.c
@@ -13,7 +13,7 @@ void test_submodule_lookup__initialize(void)
 
 	/* must create submod2_target before rewrite so prettify will work */
 	rewrite_gitmodules(git_repository_workdir(g_repo));
-	p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git");
+	p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
 }
 
 void test_submodule_lookup__cleanup(void)
@@ -39,7 +39,7 @@ void test_submodule_lookup__simple_lookup(void)
 	cl_assert(sm);
 
 	/* lookup git repo subdir that is not added as submodule */
-	cl_assert(git_submodule_lookup(&sm, g_repo, "not_submodule") == GIT_EEXISTS);
+	cl_assert(git_submodule_lookup(&sm, g_repo, "not-submodule") == GIT_EEXISTS);
 
 	/* lookup existing directory that is not a submodule */
 	cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_dir") == GIT_ENOTFOUND);
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
index f6d41fd..94eb373 100644
--- a/tests-clar/submodule/modify.c
+++ b/tests-clar/submodule/modify.c
@@ -18,7 +18,7 @@ void test_submodule_modify__initialize(void)
 
 	/* must create submod2_target before rewrite so prettify will work */
 	rewrite_gitmodules(git_repository_workdir(g_repo));
-	p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git");
+	p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
 }
 
 void test_submodule_modify__cleanup(void)
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 3fd6960..282e827 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -3,6 +3,7 @@
 #include "path.h"
 #include "submodule_helpers.h"
 #include "fileops.h"
+#include "iterator.h"
 
 static git_repository *g_repo = NULL;
 
@@ -15,7 +16,8 @@ void test_submodule_status__initialize(void)
 
 	/* must create submod2_target before rewrite so prettify will work */
 	rewrite_gitmodules(git_repository_workdir(g_repo));
-	p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git");
+	p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+	p_rename("submod2/not/.gitted", "submod2/not/.git");
 }
 
 void test_submodule_status__cleanup(void)
@@ -52,7 +54,12 @@ void test_submodule_status__ignore_none(void)
 	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged"));
 	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
 
-	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule"));
+	cl_assert_equal_i(GIT_ENOTFOUND,
+		git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not-submodule"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
 	cl_git_pass(git_submodule_status(&status, sm));
@@ -138,7 +145,7 @@ void test_submodule_status__ignore_untracked(void)
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
 
-	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule"));
+	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not-submodule"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
 	cl_git_pass(git_submodule_status(&status, sm));
@@ -198,7 +205,12 @@ void test_submodule_status__ignore_dirty(void)
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
 
-	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule"));
+	cl_assert_equal_i(GIT_ENOTFOUND,
+		git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not-submodule"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
 	cl_git_pass(git_submodule_status(&status, sm));
@@ -258,7 +270,12 @@ void test_submodule_status__ignore_all(void)
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
 
-	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule"));
+	cl_assert_equal_i(GIT_ENOTFOUND,
+		git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not-submodule"));
+	cl_assert_equal_i(GIT_EEXISTS,
+		git_submodule_lookup(&sm, g_repo, "not"));
 
 	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index"));
 	cl_git_pass(git_submodule_status(&status, sm));
@@ -305,3 +322,64 @@ void test_submodule_status__ignore_all(void)
 
 	git_buf_free(&path);
 }
+
+typedef struct {
+	size_t counter;
+	const char **paths;
+} submodule_expectations;
+
+static int confirm_submodule_status(
+	const char *path, unsigned int status_flags, void *payload)
+{
+	submodule_expectations *exp = payload;
+
+	while (git__suffixcmp(exp->paths[exp->counter], "/") == 0)
+		exp->counter++;
+
+	cl_assert_equal_s(exp->paths[exp->counter++], path);
+
+	GIT_UNUSED(status_flags);
+
+	return 0;
+}
+
+void test_submodule_status__iterator(void)
+{
+	git_iterator *iter;
+	const git_index_entry *entry;
+	size_t i;
+	static const char *expected[] = {
+		".gitmodules",
+		"just_a_dir/",
+		"just_a_dir/contents",
+		"just_a_file",
+		"not",
+		"not-submodule",
+		"README.txt",
+		"sm_added_and_uncommited",
+		"sm_changed_file",
+		"sm_changed_head",
+		"sm_changed_index",
+		"sm_changed_untracked_file",
+		"sm_missing_commits",
+		"sm_unchanged",
+		NULL
+	};
+	submodule_expectations exp = { 0, expected };
+	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+
+	cl_git_pass(git_iterator_for_workdir(&iter, g_repo,
+		GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL));
+	cl_git_pass(git_iterator_current(&entry, iter));
+
+	for (i = 0; entry; ++i) {
+		cl_assert_equal_s(expected[i], entry->path);
+		cl_git_pass(git_iterator_advance(&entry, iter));
+	}
+
+	git_iterator_free(iter);
+
+	opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+	cl_git_pass(git_status_foreach_ext(g_repo, &opts, confirm_submodule_status, &exp));
+}