Commit e7303626967ed721dd323a8a6ea6c638aed46c50

Stefan Sperling 2020-05-14T19:27:44

add submodule tests ok semarie

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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
diff --git a/regress/cmdline/add.sh b/regress/cmdline/add.sh
index c77f4d7..030ece4 100755
--- a/regress/cmdline/add.sh
+++ b/regress/cmdline/add.sh
@@ -249,9 +249,57 @@ function test_add_directory {
 	test_done "$testroot" "$ret"
 }
 
+function test_add_clashes_with_submodule {
+	local testroot=`test_init add_clashes_with_submodule`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	# Atttempt to add a file clashes with a submodule
+	echo "This is a file called repo2" > $testroot/wt/repo2
+	(cd $testroot/wt && got add repo2 > /dev/null)
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+	echo "A  repo2" > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# Update for good measure; see the error below.
+	(cd $testroot/wt && got update > /dev/null)
+
+	# This currently fails with "work tree must be updated"...
+	(cd $testroot/wt && got commit -m 'add file repo2' \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "commit succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	echo -n "got: work tree must be updated " > $testroot/stderr.expected
+	echo "before these changes can be committed" >> $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_add_basic
 run_test test_double_add
 run_test test_add_multiple
 run_test test_add_file_in_new_subdir
 run_test test_add_deleted
 run_test test_add_directory
+run_test test_add_clashes_with_submodule
diff --git a/regress/cmdline/blame.sh b/regress/cmdline/blame.sh
index 33d4c77..9e0475a 100755
--- a/regress/cmdline/blame.sh
+++ b/regress/cmdline/blame.sh
@@ -731,6 +731,37 @@ function test_blame_added_on_branch {
 	test_done "$testroot" "$ret"
 }
 
+function test_blame_submodule {
+	local testroot=`test_init blame_submodule`
+	local commit_id0=`git_show_head $testroot/repo`
+	local author_time=`git_show_author_time $testroot/repo`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	# Attempt a (nonsensical) blame of a submodule.
+	got blame -r $testroot/repo repo2 \
+		> $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "blame command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	local submodule_id=$(got tree -r $testroot/repo -i | \
+		grep 'repo2\$$' | cut -d ' ' -f1)
+	echo "got: object $submodule_id not found" > $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_blame_basic
 run_test test_blame_tag
 run_test test_blame_file_single_line
@@ -741,3 +772,4 @@ run_test test_blame_lines_shifted_down
 run_test test_blame_commit_subsumed
 run_test test_blame_blame_h
 run_test test_blame_added_on_branch
+run_test test_blame_submodule
diff --git a/regress/cmdline/cat.sh b/regress/cmdline/cat.sh
index e94f002..3c88697 100755
--- a/regress/cmdline/cat.sh
+++ b/regress/cmdline/cat.sh
@@ -202,5 +202,64 @@ function test_cat_path {
 	test_done "$testroot" "$ret"
 }
 
+function test_cat_submodule {
+	local testroot=`test_init cat_submodule`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	got cat -r $testroot/repo repo2 > $testroot/stdout \
+		> $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "cat command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	local submodule_id=$(got tree -r $testroot/repo -i | \
+		grep 'repo2\$$' | cut -d ' ' -f1)
+	echo "got: object $submodule_id not found" > $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_cat_submodule_of_same_repo {
+	local testroot=`test_init cat_submodule_of_same_repo`
+	local commit_id0=`git_show_head $testroot/repo`
+	local author_time=`git_show_author_time $testroot/repo`
+
+	(cd $testroot && git clone -q repo repo2 >/dev/null)
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	# 'got cat' shows the commit object which the submodule points to
+	# because a commit with the same ID exists in the outer repository
+	got cat -r $testroot/repo $commit_id0 | grep ^tree > $testroot/stdout.expected
+	echo "numparents 0" >> $testroot/stdout.expected
+	echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected
+	echo "committer $GOT_AUTHOR $author_time +0000" \
+		>> $testroot/stdout.expected
+	echo "messagelen 22" >> $testroot/stdout.expected
+	printf "\nadding the test tree\n" >> $testroot/stdout.expected
+
+	got cat -r $testroot/repo repo2 > $testroot/stdout
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 run_test test_cat_basic
 run_test test_cat_path
+run_test test_cat_submodule
+run_test test_cat_submodule_of_same_repo
diff --git a/regress/cmdline/checkout.sh b/regress/cmdline/checkout.sh
index 6d3a99a..abba81a 100755
--- a/regress/cmdline/checkout.sh
+++ b/regress/cmdline/checkout.sh
@@ -261,7 +261,8 @@ function test_checkout_tag {
 function test_checkout_ignores_submodules {
 	local testroot=`test_init checkout_ignores_submodules`
 
-	(cd $testroot && git clone -q repo repo2 >/dev/null)
+	make_single_file_repo $testroot/repo2 foo
+
 	(cd $testroot/repo && git submodule -q add ../repo2)
 	(cd $testroot/repo && git commit -q -m 'adding submodule')
 
diff --git a/regress/cmdline/cherrypick.sh b/regress/cmdline/cherrypick.sh
index 8cca1c7..1536606 100755
--- a/regress/cmdline/cherrypick.sh
+++ b/regress/cmdline/cherrypick.sh
@@ -234,6 +234,120 @@ function test_cherrypick_into_work_tree_with_conflicts {
 	test_done "$testroot" "$ret"
 }
 
+function test_cherrypick_modified_submodule {
+	local testroot=`test_init cherrypick_modified_submodules`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	echo "modified foo" > $testroot/repo2/foo
+	(cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
+
+	(cd $testroot/repo && git checkout -q -b newbranch)
+	# Update the repo/repo2 submodule link on newbranch
+	(cd $testroot/repo && git -C repo2 pull -q)
+	(cd $testroot/repo && git add repo2)
+	git_commit $testroot/repo -m "modified submodule link"
+	local commit_id=`git_show_head $testroot/repo`
+
+	# This cherrypick is a no-op because Got's file index
+	# does not track submodules.
+	(cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
+
+	echo -n > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_cherrypick_added_submodule {
+	local testroot=`test_init cherrypick_added_submodules`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	make_single_file_repo $testroot/repo2 foo
+
+	# Add the repo/repo2 submodule on newbranch
+	(cd $testroot/repo && git checkout -q -b newbranch)
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+	local commit_id=`git_show_head $testroot/repo`
+
+	(cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
+
+	echo "A  .gitmodules" > $testroot/stdout.expected
+	echo "Merged commit $commit_id" >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_cherrypick_conflict_wt_file_vs_repo_submodule {
+	local testroot=`test_init cherrypick_conflict_wt_file_vs_repo_submodule`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	# Add a file which will clash with the submodule
+	echo "This is a file called repo2" > $testroot/wt/repo2
+	(cd $testroot/wt && got add repo2 > /dev/null)
+	(cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "commit failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	make_single_file_repo $testroot/repo2 foo
+
+	# Add the repo/repo2 submodule on newbranch
+	(cd $testroot/repo && git checkout -q -b newbranch)
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+	local commit_id=`git_show_head $testroot/repo`
+
+	# Modify the clashing file such that any modifications brought
+	# in by 'got cherrypick' would require a merge.
+	echo "This file was changed" > $testroot/wt/repo2
+
+	(cd $testroot/wt && got update >/dev/null)
+	(cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout)
+
+	echo "A  .gitmodules" > $testroot/stdout.expected
+	echo "Merged commit $commit_id" >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo "A  .gitmodules" > $testroot/stdout.expected
+	echo "M  repo2" >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_cherrypick_basic
 run_test test_cherrypick_root_commit
 run_test test_cherrypick_into_work_tree_with_conflicts
+run_test test_cherrypick_modified_submodule
+run_test test_cherrypick_added_submodule
+run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index aafe145..3c8e833 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -862,6 +862,43 @@ function test_commit_normalizes_filemodes {
 	test_done "$testroot" "$ret"
 }
 
+function test_commit_with_unrelated_submodule {
+	local testroot=`test_init commit_with_unrelated_submodule`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified alpha" > $testroot/wt/alpha
+
+	# Currently fails with "bad file type" error
+	(cd $testroot/wt && got commit -m 'modify alpha' \
+		> $testroot/stdout 2> $testroot/stderr)
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "commit succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	echo "got: bad file type" > $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		return 1
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_commit_basic
 run_test test_commit_new_subdir
 run_test test_commit_subdir
@@ -881,3 +918,4 @@ run_test test_commit_tree_entry_sorting
 run_test test_commit_gitconfig_author
 run_test test_commit_xbit_change
 run_test test_commit_normalizes_filemodes
+run_test test_commit_with_unrelated_submodule
diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index ff453b2..5104375 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -129,6 +129,27 @@ function make_test_tree
 	echo zeta > $repo/epsilon/zeta
 }
 
+function make_single_file_repo
+{
+	repo="$1"
+	file="$2"
+
+	mkdir $repo
+	git_init $repo
+	echo "this is file $file" > $repo/$file
+	(cd $repo && git add .)
+	git_commit $repo -m "intialize $repo with file $file"
+}
+
+function get_loose_object_path
+{
+	local repo="$1"
+	local id="$2"
+	local id0=`trim_obj_id 38 $id`
+	local idrest=`echo ${id#[0-9a-f][0-9a-f]}`
+	echo "$repo/.git/objects/$id0/$idrest"
+}
+
 function get_blob_id
 {
 	repo="$1"
diff --git a/regress/cmdline/diff.sh b/regress/cmdline/diff.sh
index 6fb2ea6..a3f99c8 100755
--- a/regress/cmdline/diff.sh
+++ b/regress/cmdline/diff.sh
@@ -329,8 +329,42 @@ function test_diff_ignore_whitespace {
 	test_done "$testroot" "$ret"
 }
 
+function test_diff_submodule_of_same_repo {
+	local testroot=`test_init diff_submodule_of_same_repo`
+
+	(cd $testroot && git clone -q repo repo2 >/dev/null)
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \
+		cut -d ' ' -f 1)
+	submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \
+		cut -d ' ' -f 1)
+
+	# Attempt a (nonsensical) diff between a tree object and a submodule.
+	# Currently fails with "wrong type of object" error
+	got diff -r $testroot/repo $epsilon_id $submodule_id \
+		> $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "diff command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	echo "got: wrong type of object" > $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		return 1
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_diff_basic
 run_test test_diff_shows_conflict
 run_test test_diff_tag
 run_test test_diff_lightweight_tag
 run_test test_diff_ignore_whitespace
+run_test test_diff_submodule_of_same_repo
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index d88d0fa..c563ee1 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -690,6 +690,85 @@ function test_log_changed_paths {
 	test_done "$testroot" "$ret"
 }
 
+function test_log_submodule {
+	local testroot=`test_init log_submodule`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+	local head_commit=`git_show_head $testroot/repo`
+
+	echo "commit $head_commit (master)" > $testroot/stdout.expected
+
+	got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo " A  .gitmodules" > $testroot/stdout.expected
+
+	got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \
+		> $testroot/stdout
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got log -p -r $testroot/repo -l1 repo2 \
+		> $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "log command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	local submodule_id=$(got tree -r $testroot/repo -i | \
+		grep 'repo2\$$' | cut -d ' ' -f1)
+	echo "got: object $submodule_id not found" > $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "modified foo" > $testroot/repo2/foo
+	(cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
+
+	# Update the repo/repo2 submodule link
+	(cd $testroot/repo && git -C repo2 pull -q)
+	(cd $testroot/repo && git add repo2)
+	git_commit $testroot/repo -m "changed submodule link"
+
+	# log -P does not show the changed submodule path
+	got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "log command failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout
+
+	echo -n > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_log_in_repo
 run_test test_log_in_bare_repo
 run_test test_log_in_worktree
@@ -702,3 +781,4 @@ run_test test_log_end_at_commit
 run_test test_log_reverse_display
 run_test test_log_in_worktree_different_repo
 run_test test_log_changed_paths
+run_test test_log_submodule
diff --git a/regress/cmdline/tree.sh b/regress/cmdline/tree.sh
index 5a9d63d..44be74f 100755
--- a/regress/cmdline/tree.sh
+++ b/regress/cmdline/tree.sh
@@ -77,5 +77,65 @@ function test_tree_branch {
 	test_done "$testroot" "$ret"
 }
 
+function test_tree_submodule {
+	local testroot=`test_init tree_submodule`
+
+	make_single_file_repo $testroot/repo2 foo
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	local submodule_id=$(got tree -r $testroot/repo -i | \
+		grep 'repo2\$$' | cut -d ' ' -f1)
+	local objpath=`get_loose_object_path $testroot/repo $submodule_id`
+
+	# Currently fails in open(2)
+	got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "tree command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	echo "got: open: $objpath: No such file or directory" \
+		> $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		return 1
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_tree_submodule_of_same_repo {
+	local testroot=`test_init tree_submodule_of_same_repo`
+
+	(cd $testroot && git clone -q repo repo2 >/dev/null)
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	# Currently fails with "bad object data"
+	got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "tree command succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	echo "got-read-tree: bad object data" > $testroot/stderr.expected
+	echo "got: bad object data" >> $testroot/stderr.expected
+
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		return 1
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_tree_basic
 run_test test_tree_branch
+run_test test_tree_submodule
+run_test test_tree_submodule_of_same_repo
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 05fd291..60a1a2a 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -1710,6 +1710,122 @@ function test_update_preserves_conflicted_file {
 	test_done "$testroot" "$ret"
 }
 
+function test_update_modified_submodules {
+	local testroot=`test_init update_modified_submodules`
+
+	make_single_file_repo $testroot/repo2 foo
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	echo "modified foo" > $testroot/repo2/foo
+	(cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
+
+	# Update the repo/repo2 submodule link
+	(cd $testroot/repo && git -C repo2 pull -q)
+	(cd $testroot/repo && git add repo2)
+	git_commit $testroot/repo -m "modified submodule link"
+
+	# This update only records the new base commit. Otherwise it is a
+	# no-op change because Got's file index does not track submodules.
+	echo -n "Updated to commit " > $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
+
+	(cd $testroot/wt && got update > $testroot/stdout)
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_update_adds_submodule {
+	local testroot=`test_init update_adds_submodule`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	make_single_file_repo $testroot/repo2 foo
+
+	echo "modified foo" > $testroot/repo2/foo
+	(cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	echo "A  .gitmodules" > $testroot/stdout.expected
+	echo -n "Updated to commit " >> $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
+
+	(cd $testroot/wt && got update > $testroot/stdout)
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_update_conflict_wt_file_vs_repo_submodule {
+	local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+
+	make_single_file_repo $testroot/repo2 foo
+
+	# Add a file which will clash with the submodule
+	echo "This is a file called repo2" > $testroot/wt/repo2
+	(cd $testroot/wt && got add repo2 > /dev/null)
+	(cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "commit failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	(cd $testroot/repo && git submodule -q add ../repo2)
+	(cd $testroot/repo && git commit -q -m 'adding submodule')
+
+	# Modify the clashing file such that any modifications brought
+	# in by 'got update' would require a merge.
+	echo "This file was changed" > $testroot/wt/repo2
+
+	# No conflict occurs because 'got update' ignores the submodule
+	# and leaves the clashing file as it was.
+	echo "A  .gitmodules" > $testroot/stdout.expected
+	echo -n "Updated to commit " >> $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
+
+	(cd $testroot/wt && got update > $testroot/stdout)
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got status > $testroot/stdout)
+
+	echo "M  repo2" > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
+
 run_test test_update_basic
 run_test test_update_adds_file
 run_test test_update_deletes_file
@@ -1742,3 +1858,6 @@ run_test test_update_bumps_base_commit_id
 run_test test_update_tag
 run_test test_update_toggles_xbit
 run_test test_update_preserves_conflicted_file
+run_test test_update_modified_submodules
+run_test test_update_adds_submodule
+run_test test_update_conflict_wt_file_vs_repo_submodule