Commit 4c47a8bcfe03c42096b74d4af06ab95fb95fd211

Russell Belfer 2012-10-17T14:14:51

Merge pull request #968 from arrbee/diff-support-typechange Support TYPECHANGE records in status and adjust checkout accordingly

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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index a4d0a0c..0bac569 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -21,22 +21,39 @@
  */
 GIT_BEGIN_DECL
 
-enum {
-	GIT_CHECKOUT_DEFAULT			= (1 << 0),
-	GIT_CHECKOUT_OVERWRITE_MODIFIED	= (1 << 1),
-	GIT_CHECKOUT_CREATE_MISSING		= (1 << 2),
-	GIT_CHECKOUT_REMOVE_UNTRACKED	= (1 << 3),
-};
+/**
+ * Checkout behavior flags
+ *
+ * These flags control what checkout does with files.  Pass in a
+ * combination of these values OR'ed together.
+ */
+typedef enum {
+	/** Checkout does not update any files in the working directory. */
+	GIT_CHECKOUT_DEFAULT            = (1 << 0),
+
+	/** When a file exists and is modified, replace it with new version. */
+	GIT_CHECKOUT_OVERWRITE_MODIFIED = (1 << 1),
+
+	/** When a file does not exist in the working directory, create it. */
+	GIT_CHECKOUT_CREATE_MISSING     = (1 << 2),
 
-/* Use zeros to indicate default settings */
+	/** If an untracked file in found in the working dir, delete it. */
+	GIT_CHECKOUT_REMOVE_UNTRACKED   = (1 << 3),
+} git_checkout_strategy_t;
+
+/**
+ * Checkout options structure
+ *
+ * Use zeros to indicate default settings.
+ */
 typedef struct git_checkout_opts {
-	unsigned int checkout_strategy; /* default: GIT_CHECKOUT_DEFAULT */
-	int disable_filters;
-	int dir_mode; /* default is 0755 */
-	int file_mode; /* default is 0644 */
-	int file_open_flags; /* default is O_CREAT | O_TRUNC | O_WRONLY */
+	unsigned int checkout_strategy; /** default: GIT_CHECKOUT_DEFAULT */
+	int disable_filters; /** don't apply filters like CRLF conversion */
+	int dir_mode;		 /** default is 0755 */
+	int file_mode;		 /** default is 0644 or 0755 as dictated by blob */
+	int file_open_flags; /** default is O_CREAT | O_TRUNC | O_WRONLY */
 
-	/* Optional callback to notify the consumer of files that
+	/** Optional callback to notify the consumer of files that
 	 * haven't be checked out because a modified version of them
 	 * exist in the working directory.
 	 *
@@ -51,7 +68,7 @@ typedef struct git_checkout_opts {
 
 	void *notify_payload;
 
-	/* when not NULL, arrays of fnmatch pattern specifying 
+	/** When not NULL, array of fnmatch patterns specifying
 	 * which paths should be taken into account
 	 */
 	git_strarray paths; 
diff --git a/include/git2/diff.h b/include/git2/diff.h
index 121c403..1932db0 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -34,21 +34,58 @@ GIT_BEGIN_DECL
  * in via the `flags` value in the `git_diff_options`.
  */
 enum {
+	/** Normal diff, the default */
 	GIT_DIFF_NORMAL = 0,
+	/** Reverse the sides of the diff */
 	GIT_DIFF_REVERSE = (1 << 0),
+	/** Treat all files as text, disabling binary attributes & detection */
 	GIT_DIFF_FORCE_TEXT = (1 << 1),
+	/** Ignore all whitespace */
 	GIT_DIFF_IGNORE_WHITESPACE = (1 << 2),
+	/** Ignore changes in amount of whitespace */
 	GIT_DIFF_IGNORE_WHITESPACE_CHANGE = (1 << 3),
+	/** Ignore whitespace at end of line */
 	GIT_DIFF_IGNORE_WHITESPACE_EOL = (1 << 4),
+	/** Exclude submodules from the diff completely */
 	GIT_DIFF_IGNORE_SUBMODULES = (1 << 5),
+	/** Use the "patience diff" algorithm (currently unimplemented) */
 	GIT_DIFF_PATIENCE = (1 << 6),
+	/** Include ignored files in the diff list */
 	GIT_DIFF_INCLUDE_IGNORED = (1 << 7),
+	/** Include untracked files in the diff list */
 	GIT_DIFF_INCLUDE_UNTRACKED = (1 << 8),
+	/** Include unmodified files in the diff list */
 	GIT_DIFF_INCLUDE_UNMODIFIED = (1 << 9),
+	/** Even with the GIT_DIFF_INCLUDE_UNTRACKED flag, when an untracked
+	 *  directory is found, only a single entry for the directory is added
+	 *  to the diff list; with this flag, all files under the directory will
+	 *  be included, too.
+	 */
 	GIT_DIFF_RECURSE_UNTRACKED_DIRS = (1 << 10),
+	/** If the pathspec is set in the diff options, this flags means to
+	 *  apply it as an exact match instead of as an fnmatch pattern.
+	 */
 	GIT_DIFF_DISABLE_PATHSPEC_MATCH = (1 << 11),
+	/** Use case insensitive filename comparisons */
 	GIT_DIFF_DELTAS_ARE_ICASE = (1 << 12),
+	/** When generating patch text, include the content of untracked files */
 	GIT_DIFF_INCLUDE_UNTRACKED_CONTENT = (1 << 13),
+	/** Disable updating of the `binary` flag in delta records.  This is
+	 *  useful when iterating over a diff if you don't need hunk and data
+	 *  callbacks and want to avoid having to load file completely.
+	 */
+	GIT_DIFF_SKIP_BINARY_CHECK = (1 << 14),
+	/** Normally, a type change between files will be converted into a
+	 *  DELETED record for the old and an ADDED record for the new; this
+	 *  options enabled the generation of TYPECHANGE delta records.
+	 */
+	GIT_DIFF_INCLUDE_TYPECHANGE = (1 << 15),
+	/** Even with GIT_DIFF_INCLUDE_TYPECHANGE, blob->tree changes still
+	 *  generally show as a DELETED blob.  This flag tries to correctly
+	 *  label blob->tree transitions as TYPECHANGE records with new_file's
+	 *  mode set to tree.  Note: the tree SHA will not be available.
+	 */
+	GIT_DIFF_INCLUDE_TYPECHANGE_TREES  = (1 << 16),
 };
 
 /**
@@ -85,24 +122,16 @@ typedef struct git_diff_list git_diff_list;
  * Flags that can be set for the file on side of a diff.
  *
  * Most of the flags are just for internal consumption by libgit2,
- * but some of them may be interesting to external users.  They are:
- *
- * - VALID_OID  - the `oid` value is computed and correct
- * - FREE_PATH  - the `path` string is separated allocated memory
- * - BINARY     - this file should be considered binary data
- * - NOT_BINARY - this file should be considered text data
- * - FREE_DATA  - the internal file data is kept in allocated memory
- * - UNMAP_DATA - the internal file data is kept in mmap'ed memory
- * - NO_DATA    - this side of the diff should not be loaded
+ * but some of them may be interesting to external users.
  */
 enum {
-	GIT_DIFF_FILE_VALID_OID  = (1 << 0),
-	GIT_DIFF_FILE_FREE_PATH  = (1 << 1),
-	GIT_DIFF_FILE_BINARY     = (1 << 2),
-	GIT_DIFF_FILE_NOT_BINARY = (1 << 3),
-	GIT_DIFF_FILE_FREE_DATA  = (1 << 4),
-	GIT_DIFF_FILE_UNMAP_DATA = (1 << 5),
-	GIT_DIFF_FILE_NO_DATA    = (1 << 6),
+	GIT_DIFF_FILE_VALID_OID  = (1 << 0), /** `oid` value is known correct */
+	GIT_DIFF_FILE_FREE_PATH  = (1 << 1), /** `path` is allocated memory */
+	GIT_DIFF_FILE_BINARY     = (1 << 2), /** should be considered binary data */
+	GIT_DIFF_FILE_NOT_BINARY = (1 << 3), /** should be considered text data */
+	GIT_DIFF_FILE_FREE_DATA  = (1 << 4), /** internal file data is allocated */
+	GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), /** internal file data is mmap'ed */
+	GIT_DIFF_FILE_NO_DATA    = (1 << 6), /** file data should not be loaded */
 };
 
 /**
@@ -116,7 +145,8 @@ typedef enum {
 	GIT_DELTA_RENAMED = 4,
 	GIT_DELTA_COPIED = 5,
 	GIT_DELTA_IGNORED = 6,
-	GIT_DELTA_UNTRACKED = 7
+	GIT_DELTA_UNTRACKED = 7,
+	GIT_DELTA_TYPECHANGE = 8,
 } git_delta_t;
 
 /**
diff --git a/include/git2/status.h b/include/git2/status.h
index 0dd9859..979e6e4 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -19,19 +19,22 @@
  */
 GIT_BEGIN_DECL
 
-enum {
-	GIT_STATUS_CURRENT	= 0,
+typedef enum {
+	GIT_STATUS_CURRENT = 0,
 
-	GIT_STATUS_INDEX_NEW = (1 << 0),
-	GIT_STATUS_INDEX_MODIFIED = (1 << 1),
-	GIT_STATUS_INDEX_DELETED = (1 << 2),
+	GIT_STATUS_INDEX_NEW        = (1u << 0),
+	GIT_STATUS_INDEX_MODIFIED   = (1u << 1),
+	GIT_STATUS_INDEX_DELETED    = (1u << 2),
+	GIT_STATUS_INDEX_RENAMED    = (1u << 3),
+	GIT_STATUS_INDEX_TYPECHANGE = (1u << 4),
 
-	GIT_STATUS_WT_NEW = (1 << 3),
-	GIT_STATUS_WT_MODIFIED = (1 << 4),
-	GIT_STATUS_WT_DELETED = (1 << 5),
+	GIT_STATUS_WT_NEW           = (1u << 7),
+	GIT_STATUS_WT_MODIFIED      = (1u << 8),
+	GIT_STATUS_WT_DELETED       = (1u << 9),
+	GIT_STATUS_WT_TYPECHANGE    = (1u << 10),
 
-	GIT_STATUS_IGNORED = (1 << 6),
-};
+	GIT_STATUS_IGNORED          = (1u << 14),
+} git_status_t;
 
 /**
  * Gather file statuses and run a callback for each one.
diff --git a/include/git2/tree.h b/include/git2/tree.h
index e526141..2ee1f4a 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -100,7 +100,7 @@ GIT_EXTERN(git_tree_entry *) git_tree_entry_dup(const git_tree_entry *entry);
  * @param tree a previously loaded tree.
  * @return object identity for the tree.
  */
-GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree);
+GIT_EXTERN(const git_oid *) git_tree_id(const git_tree *tree);
 
 /**
  * Get the number of entries listed in a tree
@@ -108,7 +108,7 @@ GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree);
  * @param tree a previously loaded tree.
  * @return the number of entries in the tree
  */
-GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree);
+GIT_EXTERN(unsigned int) git_tree_entrycount(const git_tree *tree);
 
 /**
  * Lookup a tree entry by its filename
diff --git a/src/checkout.c b/src/checkout.c
index e429d28..4782f77 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -30,6 +30,9 @@ struct checkout_diff_data
 	git_indexer_stats *stats;
 	git_repository *owner;
 	bool can_symlink;
+	bool found_submodules;
+	bool create_submodules;
+	int error;
 };
 
 static int buffer_to_file(
@@ -39,18 +42,27 @@ static int buffer_to_file(
 	int file_open_flags,
 	mode_t file_mode)
 {
-	int fd, error_write, error_close;
+	int fd, error, error_close;
 
-	if (git_futils_mkpath2file(path, dir_mode) < 0)
-		return -1;
+	if ((error = git_futils_mkpath2file(path, dir_mode)) < 0)
+		return error;
 
 	if ((fd = p_open(path, file_open_flags, file_mode)) < 0)
-		return -1;
+		return fd;
+
+	error = p_write(fd, git_buf_cstr(buffer), git_buf_len(buffer));
 
-	error_write = p_write(fd, git_buf_cstr(buffer), git_buf_len(buffer));
 	error_close = p_close(fd);
 
-	return error_write ? error_write : error_close;
+	if (!error)
+		error = error_close;
+
+	if (!error &&
+		(file_mode & 0100) != 0 &&
+		(error = p_chmod(path, file_mode)) < 0)
+		giterr_set(GITERR_OS, "Failed to set permissions on '%s'", path);
+
+	return error;
 }
 
 static int blob_content_to_file(
@@ -84,7 +96,7 @@ static int blob_content_to_file(
 		return nb_filters;
 
 	if (nb_filters > 0)	 {
-		if (git_blob__getbuf(&unfiltered, blob) < 0)
+		if ((error = git_blob__getbuf(&unfiltered, blob)) < 0)
 			goto cleanup;
 
 		if ((error = git_filters_apply(&filtered, &unfiltered, &filters)) < 0)
@@ -111,8 +123,8 @@ static int blob_content_to_link(git_blob *blob, const char *path, bool can_symli
 	git_buf linktarget = GIT_BUF_INIT;
 	int error;
 
-	if (git_blob__getbuf(&linktarget, blob) < 0)
-		return -1;
+	if ((error = git_blob__getbuf(&linktarget, blob)) < 0)
+		return error;
 
 	if (can_symlink)
 		error = p_symlink(git_buf_cstr(&linktarget), path);
@@ -124,110 +136,126 @@ static int blob_content_to_link(git_blob *blob, const char *path, bool can_symli
 	return error;
 }
 
+static int checkout_submodule(
+	struct checkout_diff_data *data,
+	const git_diff_file *file)
+{
+	if (git_futils_mkdir(
+			file->path, git_repository_workdir(data->owner),
+			data->checkout_opts->dir_mode, GIT_MKDIR_PATH) < 0)
+		return -1;
+
+	/* TODO: two cases:
+	 * 1 - submodule already checked out, but we need to move the HEAD
+	 *     to the new OID, or
+	 * 2 - submodule not checked out and we should recursively check it out
+	 *
+	 * Checkout will not execute a pull request on the submodule, but a
+	 * clone command should probably be able to.  Do we need a submodule
+	 * callback option?
+	 */
+
+	return 0;
+}
+
 static int checkout_blob(
-	git_repository *repo,
-	const git_oid *blob_oid,
-	const char *path,
-	mode_t filemode,
-	bool can_symlink,
-	git_checkout_opts *opts)
+	struct checkout_diff_data *data,
+	const git_diff_file *file)
 {
 	git_blob *blob;
 	int error;
 
-	if (git_blob_lookup(&blob, repo, blob_oid) < 0)
-		return -1; /* Add an error message */
+	git_buf_truncate(data->path, data->workdir_len);
+	if (git_buf_joinpath(data->path, git_buf_cstr(data->path), file->path) < 0)
+		return -1;
+
+	if ((error = git_blob_lookup(&blob, data->owner, &file->oid)) < 0)
+		return error;
 
-	if (S_ISLNK(filemode))
-		error = blob_content_to_link(blob, path, can_symlink);
+	if (S_ISLNK(file->mode))
+		error = blob_content_to_link(
+			blob, git_buf_cstr(data->path), data->can_symlink);
 	else
-		error = blob_content_to_file(blob, path, filemode, opts);
+		error = blob_content_to_file(
+			blob, git_buf_cstr(data->path), file->mode, data->checkout_opts);
 
 	git_blob_free(blob);
 
 	return error;
 }
 
-static int checkout_diff_fn(
-	void *cb_data,
-	const git_diff_delta *delta,
-	float progress)
+static int checkout_remove_the_old(
+	void *cb_data, const git_diff_delta *delta, float progress)
 {
-	struct checkout_diff_data *data;
-	int error = -1;
-	git_checkout_opts *opts;
-
-	data = (struct checkout_diff_data *)cb_data;
-
-	data->stats->processed = (unsigned int)(data->stats->total * progress);
+	struct checkout_diff_data *data = cb_data;
+	git_checkout_opts *opts = data->checkout_opts;
+
+	GIT_UNUSED(progress);
+	data->stats->processed++;
+
+	if ((delta->status == GIT_DELTA_UNTRACKED &&
+		 (opts->checkout_strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0) ||
+		(delta->status == GIT_DELTA_TYPECHANGE &&
+		 (opts->checkout_strategy & GIT_CHECKOUT_OVERWRITE_MODIFIED) != 0))
+	{
+		data->error = git_futils_rmdir_r(
+			delta->new_file.path,
+			git_repository_workdir(data->owner),
+			GIT_DIRREMOVAL_FILES_AND_DIRS);
+	}
 
-	git_buf_truncate(data->path, data->workdir_len);
-	if (git_buf_joinpath(data->path, git_buf_cstr(data->path), delta->new_file.path) < 0)
-		return -1;
+	return data->error;
+}
 
-	opts = data->checkout_opts;
-
-	switch (delta->status) {
-	case GIT_DELTA_UNTRACKED:
-		if (!(opts->checkout_strategy & GIT_CHECKOUT_REMOVE_UNTRACKED))
-			return 0;
-
-		if (!git__suffixcmp(delta->new_file.path, "/"))
-			error = git_futils_rmdir_r(git_buf_cstr(data->path), GIT_DIRREMOVAL_FILES_AND_DIRS);
-		else
-			error = p_unlink(git_buf_cstr(data->path));
-		break;
-
-	case GIT_DELTA_MODIFIED:
-		if (!(opts->checkout_strategy & GIT_CHECKOUT_OVERWRITE_MODIFIED)) {
-
-			if ((opts->skipped_notify_cb != NULL)
-				&& (opts->skipped_notify_cb(
-					delta->new_file.path,
-					&delta->old_file.oid,
-					delta->old_file.mode,
-					opts->notify_payload))) {
-						giterr_clear();
-						return GIT_EUSER;
-			}
-
-			return 0;
+static int checkout_create_the_new(
+	void *cb_data, const git_diff_delta *delta, float progress)
+{
+	int error = 0;
+	struct checkout_diff_data *data = cb_data;
+	git_checkout_opts *opts = data->checkout_opts;
+	bool do_checkout = false, do_notify = false;
+
+	GIT_UNUSED(progress);
+	data->stats->processed++;
+
+	if (delta->status == GIT_DELTA_MODIFIED ||
+		delta->status == GIT_DELTA_TYPECHANGE)
+	{
+		if ((opts->checkout_strategy & GIT_CHECKOUT_OVERWRITE_MODIFIED) != 0)
+			do_checkout = true;
+		else if (opts->skipped_notify_cb != NULL)
+			do_notify = !data->create_submodules;
+	}
+	else if (delta->status == GIT_DELTA_DELETED &&
+			 (opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING) != 0)
+		do_checkout = true;
+
+	if (do_notify) {
+		if (opts->skipped_notify_cb(
+			delta->old_file.path, &delta->old_file.oid,
+			delta->old_file.mode, opts->notify_payload))
+		{
+			giterr_clear();
+			error = GIT_EUSER;
 		}
+	}
 
-		if (checkout_blob(
-				data->owner,
-				&delta->old_file.oid,
-				git_buf_cstr(data->path),
-				delta->old_file.mode,
-				data->can_symlink,
-				opts) < 0)
-			goto cleanup;
-
-		break;
-
-	case GIT_DELTA_DELETED:
-		if (!(opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING))
-			return 0;
+	if (do_checkout) {
+		bool is_submodule = S_ISGITLINK(delta->old_file.mode);
 
-		if (checkout_blob(
-				data->owner,
-				&delta->old_file.oid,
-				git_buf_cstr(data->path),
-				delta->old_file.mode,
-				data->can_symlink,
-				opts) < 0)
-			goto cleanup;
+		if (is_submodule)
+			data->found_submodules = true;
 
-		break;
+		if (!is_submodule && !data->create_submodules)
+			error = checkout_blob(data, &delta->old_file);
 
-	default:
-		giterr_set(GITERR_INVALID, "Unexpected status (%d) for path '%s'.", delta->status, delta->new_file.path);
-		goto cleanup;
+		else if (is_submodule && data->create_submodules)
+			error = checkout_submodule(data, &delta->old_file);
 	}
 
-	error = 0;
+	if (error)
+		data->error = error;
 
-cleanup:
 	return error;
 }
 
@@ -279,7 +307,6 @@ int git_checkout_index(
 	git_checkout_opts *opts,
 	git_indexer_stats *stats)
 {
-	git_index *index = NULL;
 	git_diff_list *diff = NULL;
 	git_indexer_stats dummy_stats;
 
@@ -293,10 +320,13 @@ int git_checkout_index(
 
 	assert(repo);
 
-	if ((git_repository__ensure_not_bare(repo, "checkout")) < 0)
-		return GIT_EBAREREPO;
+	if ((error = git_repository__ensure_not_bare(repo, "checkout")) < 0)
+		return error;
 
-	diff_opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+	diff_opts.flags =
+		GIT_DIFF_INCLUDE_UNTRACKED |
+		GIT_DIFF_INCLUDE_TYPECHANGE |
+		GIT_DIFF_SKIP_BINARY_CHECK;
 
 	if (opts && opts->paths.count > 0)
 		diff_opts.pathspec = opts->paths;
@@ -313,11 +343,8 @@ int git_checkout_index(
 		stats = &dummy_stats;
 
 	stats->processed = 0;
-
-	if ((git_repository_index(&index, repo)) < 0)
-		goto cleanup;
-
-	stats->total = git_index_entrycount(index);
+	/* total based on 3 passes, but it might be 2 if no submodules */
+	stats->total = (unsigned int)git_diff_num_deltas(diff) * 3;
 
 	memset(&data, 0, sizeof(data));
 
@@ -330,12 +357,36 @@ int git_checkout_index(
 	if ((error = retrieve_symlink_capabilities(repo, &data.can_symlink)) < 0)
 		goto cleanup;
 
-	error = git_diff_foreach(diff, &data, checkout_diff_fn, NULL, NULL);
+	/* Checkout is best performed with three passes through the diff.
+	 *
+	 * 1. First do removes, because we iterate in alphabetical order, thus
+	 *    a new untracked directory will end up sorted *after* a blob that
+	 *    should be checked out with the same name.
+	 * 2. Then checkout all blobs.
+	 * 3. Then checkout all submodules in case a new .gitmodules blob was
+	 *    checked out during pass #2.
+	 */
+
+	if (!(error = git_diff_foreach(
+			diff, &data, checkout_remove_the_old, NULL, NULL)) &&
+		!(error = git_diff_foreach(
+			diff, &data, checkout_create_the_new, NULL, NULL)) &&
+		data.found_submodules)
+	{
+		data.create_submodules = true;
+		error = git_diff_foreach(
+			diff, &data, checkout_create_the_new, NULL, NULL);
+	}
+
+	stats->processed = stats->total;
 
 cleanup:
-	git_index_free(index);
+	if (error == GIT_EUSER)
+		error = (data.error != 0) ? data.error : -1;
+
 	git_diff_list_free(diff);
 	git_buf_free(&workdir);
+
 	return error;
 }
 
diff --git a/src/clone.c b/src/clone.c
index 82042a4..85e69ad 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -330,7 +330,7 @@ static int clone_internal(
 		if ((retcode = setup_remotes_and_fetch(repo, origin_url, fetch_stats)) < 0) {
 			/* Failed to fetch; clean up */
 			git_repository_free(repo);
-			git_futils_rmdir_r(path, GIT_DIRREMOVAL_FILES_AND_DIRS);
+			git_futils_rmdir_r(path, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
 		} else {
 			*out = repo;
 			retcode = 0;
diff --git a/src/diff.c b/src/diff.c
index 8ab8af3..7f500b8 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -291,6 +291,36 @@ static int diff_delta__from_two(
 	return 0;
 }
 
+static git_diff_delta *diff_delta__last_for_item(
+	git_diff_list *diff,
+	const git_index_entry *item)
+{
+	git_diff_delta *delta = git_vector_last(&diff->deltas);
+	if (!delta)
+		return NULL;
+
+	switch (delta->status) {
+	case GIT_DELTA_UNMODIFIED:
+	case GIT_DELTA_DELETED:
+		if (git_oid_cmp(&delta->old_file.oid, &item->oid) == 0)
+			return delta;
+		break;
+	case GIT_DELTA_ADDED:
+		if (git_oid_cmp(&delta->new_file.oid, &item->oid) == 0)
+			return delta;
+		break;
+	case GIT_DELTA_MODIFIED:
+		if (git_oid_cmp(&delta->old_file.oid, &item->oid) == 0 ||
+			git_oid_cmp(&delta->new_file.oid, &item->oid) == 0)
+			return delta;
+		break;
+	default:
+		break;
+	}
+
+	return NULL;
+}
+
 static char *diff_strdup_prefix(git_pool *pool, const char *prefix)
 {
 	size_t len = strlen(prefix);
@@ -368,6 +398,10 @@ static git_diff_list *git_diff_list_alloc(
 		diff->opts.new_prefix = swap;
 	}
 
+	/* INCLUDE_TYPECHANGE_TREES implies INCLUDE_TYPECHANGE */
+	if (diff->opts.flags & GIT_DIFF_INCLUDE_TYPECHANGE_TREES)
+		diff->opts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE;
+
 	/* only copy pathspec if it is "interesting" so we can test
 	 * diff->pathspec.length > 0 to know if it is worth calling
 	 * fnmatch as we iterate.
@@ -508,6 +542,7 @@ static int maybe_modified(
 	git_delta_t status = GIT_DELTA_MODIFIED;
 	unsigned int omode = oitem->mode;
 	unsigned int nmode = nitem->mode;
+	bool new_is_workdir = (new_iter->type == GIT_ITERATOR_WORKDIR);
 
 	GIT_UNUSED(old_iter);
 
@@ -515,15 +550,14 @@ static int maybe_modified(
 		return 0;
 
 	/* on platforms with no symlinks, preserve mode of existing symlinks */
-	if (S_ISLNK(omode) && S_ISREG(nmode) &&
-		!(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS) &&
-		new_iter->type == GIT_ITERATOR_WORKDIR)
+	if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir &&
+		!(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS))
 		nmode = omode;
 
 	/* on platforms with no execmode, just preserve old mode */
 	if (!(diff->diffcaps & GIT_DIFFCAPS_TRUST_MODE_BITS) &&
 		(nmode & MODE_BITS_MASK) != (omode & MODE_BITS_MASK) &&
-		new_iter->type == GIT_ITERATOR_WORKDIR)
+		new_is_workdir)
 		nmode = (nmode & ~MODE_BITS_MASK) | (omode & MODE_BITS_MASK);
 
 	/* support "assume unchanged" (poorly, b/c we still stat everything) */
@@ -537,10 +571,14 @@ static int maybe_modified(
 
 	/* if basic type of file changed, then split into delete and add */
 	else if (GIT_MODE_TYPE(omode) != GIT_MODE_TYPE(nmode)) {
-		if (diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem) < 0 ||
-			diff_delta__from_one(diff, GIT_DELTA_ADDED, nitem) < 0)
-			return -1;
-		return 0;
+		if ((diff->opts.flags & GIT_DIFF_INCLUDE_TYPECHANGE) != 0)
+			status = GIT_DELTA_TYPECHANGE;
+		else {
+			if (diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem) < 0 ||
+				diff_delta__from_one(diff, GIT_DELTA_ADDED, nitem) < 0)
+				return -1;
+			return 0;
+		}
 	}
 
 	/* if oids and modes match, then file is unmodified */
@@ -551,9 +589,7 @@ static int maybe_modified(
 	/* if we have an unknown OID and a workdir iterator, then check some
 	 * circumstances that can accelerate things or need special handling
 	 */
-	else if (git_oid_iszero(&nitem->oid) &&
-			 new_iter->type == GIT_ITERATOR_WORKDIR)
-	{
+	else if (git_oid_iszero(&nitem->oid) && new_is_workdir) {
 		/* TODO: add check against index file st_mtime to avoid racy-git */
 
 		/* if the stat data looks exactly alike, then assume the same */
@@ -588,7 +624,7 @@ static int maybe_modified(
 				/* grab OID while we are here */
 				if (git_oid_iszero(&nitem->oid)) {
 					const git_oid *sm_oid = git_submodule_wd_oid(sub);
-					if (sub != NULL) {
+					if (sm_oid != NULL) {
 						git_oid_cpy(&noid, sm_oid);
 						use_noid = &noid;
 					}
@@ -600,7 +636,7 @@ static int maybe_modified(
 	/* if we got here and decided that the files are modified, but we
 	 * haven't calculated the OID of the new item, then calculate it now
 	 */
-	if (status == GIT_DELTA_MODIFIED && git_oid_iszero(&nitem->oid)) {
+	if (status != GIT_DELTA_UNMODIFIED && git_oid_iszero(&nitem->oid)) {
 		if (oid_for_workdir_item(diff->repo, nitem, &noid) < 0)
 			return -1;
 		else if (omode == nmode && git_oid_equal(&oitem->oid, &noid))
@@ -630,6 +666,24 @@ static int git_index_entry_cmp_icase(const void *a, const void *b)
 	return strcasecmp(entry_a->path, entry_b->path);
 }
 
+static bool entry_is_prefixed(
+	const git_index_entry *item,
+	git_iterator *prefix_iterator,
+	const git_index_entry *prefix_item)
+{
+	size_t pathlen;
+
+	if (!prefix_item ||
+		ITERATOR_PREFIXCMP(*prefix_iterator, prefix_item->path, item->path))
+		return false;
+
+	pathlen = strlen(item->path);
+
+	return (item->path[pathlen - 1] == '/' ||
+			prefix_item->path[pathlen] == '\0' ||
+			prefix_item->path[pathlen] == '/');
+}
+
 static int diff_from_iterators(
 	git_repository *repo,
 	const git_diff_options *opts, /**< can be NULL for defaults */
@@ -679,8 +733,24 @@ static int diff_from_iterators(
 
 		/* create DELETED records for old items not matched in new */
 		if (oitem && (!nitem || entry_compare(oitem, nitem) < 0)) {
-			if (diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem) < 0 ||
-				git_iterator_advance(old_iter, &oitem) < 0)
+			if (diff_delta__from_one(diff, GIT_DELTA_DELETED, oitem) < 0)
+				goto fail;
+
+			/* if we are generating TYPECHANGE records then check for that
+			 * instead of just generating a DELETE record
+			 */
+			if ((diff->opts.flags & GIT_DIFF_INCLUDE_TYPECHANGE_TREES) != 0 &&
+				entry_is_prefixed(oitem, new_iter, nitem))
+			{
+				/* this entry has become a tree! convert to TYPECHANGE */
+				git_diff_delta *last = diff_delta__last_for_item(diff, oitem);
+				if (last) {
+					last->status = GIT_DELTA_TYPECHANGE;
+					last->new_file.mode = GIT_FILEMODE_TREE;
+				}
+			}
+
+			if (git_iterator_advance(old_iter, &oitem) < 0)
 				goto fail;
 		}
 
@@ -702,8 +772,7 @@ static int diff_from_iterators(
 				 * directories and it is not under an ignored directory.
 				 */
 				bool contains_tracked =
-					(oitem &&
-					 !ITERATOR_PREFIXCMP(*old_iter, oitem->path, nitem->path));
+					entry_is_prefixed(nitem, old_iter, oitem);
 				bool recurse_untracked =
 					(delta_type == GIT_DELTA_UNTRACKED &&
 					 (diff->opts.flags & GIT_DIFF_RECURSE_UNTRACKED_DIRS) != 0);
@@ -759,8 +828,25 @@ static int diff_from_iterators(
 			else if (new_iter->type != GIT_ITERATOR_WORKDIR)
 				delta_type = GIT_DELTA_ADDED;
 
-			if (diff_delta__from_one(diff, delta_type, nitem) < 0 ||
-				git_iterator_advance(new_iter, &nitem) < 0)
+			if (diff_delta__from_one(diff, delta_type, nitem) < 0)
+				goto fail;
+
+			/* if we are generating TYPECHANGE records then check for that
+			 * instead of just generating an ADD/UNTRACKED record
+			 */
+			if (delta_type != GIT_DELTA_IGNORED &&
+				(diff->opts.flags & GIT_DIFF_INCLUDE_TYPECHANGE_TREES) != 0 &&
+				entry_is_prefixed(nitem, old_iter, oitem))
+			{
+				/* this entry was a tree! convert to TYPECHANGE */
+				git_diff_delta *last = diff_delta__last_for_item(diff, oitem);
+				if (last) {
+					last->status = GIT_DELTA_TYPECHANGE;
+					last->old_file.mode = GIT_FILEMODE_TREE;
+				}
+			}
+
+			if (git_iterator_advance(new_iter, &nitem) < 0)
 				goto fail;
 		}
 
diff --git a/src/diff.h b/src/diff.h
index 15745b2..c6a26ae 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -28,17 +28,12 @@ enum {
 	GIT_DIFFCAPS_USE_DEV          = (1 << 4), /* use st_dev? */
 };
 
-typedef struct {
-	git_refcount   rc;
-	git_diff_delta delta;
-} git_diff_delta_refcounted;
-
 struct git_diff_list {
 	git_refcount     rc;
 	git_repository   *repo;
 	git_diff_options opts;
 	git_vector       pathspec;
-	git_vector       deltas;    /* vector of git_diff_delta_refcounted */
+	git_vector       deltas;    /* vector of git_diff_delta */
 	git_pool pool;
 	git_iterator_type_t old_src;
 	git_iterator_type_t new_src;
diff --git a/src/diff_output.c b/src/diff_output.c
index 10fbd39..5f0d13c 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -533,6 +533,11 @@ static int diff_patch_load(
 	if (delta->binary == 1)
 		goto cleanup;
 
+	if (!ctxt->hunk_cb &&
+		!ctxt->data_cb &&
+		(ctxt->opts->flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0)
+		goto cleanup;
+
 	switch (delta->status) {
 	case GIT_DELTA_ADDED:
 		delta->old_file.flags |= GIT_DIFF_FILE_NO_DATA;
@@ -698,8 +703,10 @@ static int diff_patch_generate(
 	if ((patch->flags & GIT_DIFF_PATCH_DIFFABLE) == 0)
 		return 0;
 
-	if (ctxt)
-		patch->ctxt = ctxt;
+	if (!ctxt->file_cb && !ctxt->hunk_cb)
+		return 0;
+
+	patch->ctxt = ctxt;
 
 	memset(&xdiff_callback, 0, sizeof(xdiff_callback));
 	xdiff_callback.outf = diff_patch_cb;
@@ -1360,7 +1367,9 @@ int git_diff_get_patch(
 	if (delta_ptr)
 		*delta_ptr = delta;
 
-	if (!patch_ptr && delta->binary != -1)
+	if (!patch_ptr &&
+		(delta->binary != -1 ||
+		 (diff->opts.flags & GIT_DIFF_SKIP_BINARY_CHECK) != 0))
 		return 0;
 
 	diff_context_init(
diff --git a/src/fileops.c b/src/fileops.c
index 6abab88..3f9e987 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -326,10 +326,6 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path)
 {
 	git_directory_removal_type removal_type = *(git_directory_removal_type *)opaque;
 
-	assert(removal_type == GIT_DIRREMOVAL_EMPTY_HIERARCHY
-		|| removal_type == GIT_DIRREMOVAL_FILES_AND_DIRS
-		|| removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS);
-
 	if (git_path_isdir(path->ptr) == true) {
 		if (git_path_direach(path, _rmdir_recurs_foreach, opaque) < 0)
 			return -1;
@@ -362,15 +358,24 @@ static int _rmdir_recurs_foreach(void *opaque, git_buf *path)
 	return 0;
 }
 
-int git_futils_rmdir_r(const char *path, git_directory_removal_type removal_type)
+int git_futils_rmdir_r(
+	const char *path, const char *base, git_directory_removal_type removal_type)
 {
 	int error;
-	git_buf p = GIT_BUF_INIT;
+	git_buf fullpath = GIT_BUF_INIT;
+
+	assert(removal_type == GIT_DIRREMOVAL_EMPTY_HIERARCHY
+		|| removal_type == GIT_DIRREMOVAL_FILES_AND_DIRS
+		|| removal_type == GIT_DIRREMOVAL_ONLY_EMPTY_DIRS);
+
+	/* build path and find "root" where we should start calling mkdir */
+	if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
+		return -1;
+
+	error = _rmdir_recurs_foreach(&removal_type, &fullpath);
+
+	git_buf_free(&fullpath);
 
-	error = git_buf_sets(&p, path);
-	if (!error)
-		error = _rmdir_recurs_foreach(&removal_type, &p);
-	git_buf_free(&p);
 	return error;
 }
 
diff --git a/src/fileops.h b/src/fileops.h
index d2944f4..19f7ffd 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -107,15 +107,17 @@ typedef enum {
  * Remove path and any files and directories beneath it.
  *
  * @param path Path to to top level directory to process.
- *
+ * @param base Root for relative path.
  * @param removal_type GIT_DIRREMOVAL_EMPTY_HIERARCHY to remove a hierarchy
- * of empty directories (will fail if any file is found), GIT_DIRREMOVAL_FILES_AND_DIRS
- * to remove a hierarchy of files and folders, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS to only remove
- * empty directories (no failure on file encounter).
+ *                     of empty directories (will fail if any file is found),
+ *                     GIT_DIRREMOVAL_FILES_AND_DIRS to remove a hierarchy of
+ *                     files and folders,
+ *                     GIT_DIRREMOVAL_ONLY_EMPTY_DIRS to only remove empty
+ *                     directories (no failure on file encounter).
  *
  * @return 0 on success; -1 on error.
  */
-extern int git_futils_rmdir_r(const char *path, git_directory_removal_type removal_type);
+extern int git_futils_rmdir_r(const char *path, const char *base, git_directory_removal_type removal_type);
 
 /**
  * Create and open a temporary file with a `_git2_` suffix.
diff --git a/src/iterator.c b/src/iterator.c
index 267687e..df6da9a 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -82,7 +82,7 @@ int git_iterator_for_nothing(git_iterator **iter)
 
 typedef struct tree_iterator_frame tree_iterator_frame;
 struct tree_iterator_frame {
-	tree_iterator_frame *next;
+	tree_iterator_frame *next, *prev;
 	git_tree *tree;
 	char *start;
 	unsigned int index;
@@ -91,7 +91,7 @@ struct tree_iterator_frame {
 typedef struct {
 	git_iterator base;
 	git_repository *repo;
-	tree_iterator_frame *stack;
+	tree_iterator_frame *stack, *tail;
 	git_index_entry entry;
 	git_buf path;
 	bool path_has_filename;
@@ -119,8 +119,10 @@ static void tree_iterator__pop_frame(tree_iterator *ti)
 {
 	tree_iterator_frame *tf = ti->stack;
 	ti->stack = tf->next;
-	if (ti->stack != NULL) /* don't free the initial tree */
-		git_tree_free(tf->tree);
+	if (ti->stack != NULL) {
+		git_tree_free(tf->tree); /* don't free the initial tree */
+		ti->stack->prev = NULL;  /* disconnect prev */
+	}
 	git__free(tf);
 }
 
@@ -221,6 +223,7 @@ static int tree_iterator__expand_tree(tree_iterator *ti)
 
 		tf->next  = ti->stack;
 		ti->stack = tf;
+		tf->next->prev = tf;
 
 		te = tree_iterator__tree_entry(ti);
 	}
@@ -312,7 +315,7 @@ int git_iterator_for_tree_range(
 	ITERATOR_BASE_INIT(ti, tree, TREE);
 
 	ti->repo  = repo;
-	ti->stack = tree_iterator__alloc_frame(tree, ti->base.start);
+	ti->stack = ti->tail = tree_iterator__alloc_frame(tree, ti->base.start);
 
 	if ((error = tree_iterator__expand_tree(ti)) < 0)
 		git_iterator_free((git_iterator *)ti);
@@ -864,6 +867,45 @@ int git_iterator_current_tree_entry(
 	return 0;
 }
 
+int git_iterator_current_parent_tree(
+	git_iterator *iter,
+	const char *parent_path,
+	const git_tree **tree_ptr)
+{
+	tree_iterator *ti = (tree_iterator *)iter;
+	tree_iterator_frame *tf;
+	const char *scan = parent_path;
+
+	if (iter->type != GIT_ITERATOR_TREE || ti->stack == NULL)
+		goto notfound;
+
+	for (tf = ti->tail; tf != NULL; tf = tf->prev) {
+		const git_tree_entry *te;
+
+		if (!*scan) {
+			*tree_ptr = tf->tree;
+			return 0;
+		}
+
+		te = git_tree_entry_byindex(tf->tree, tf->index);
+
+		if (strncmp(scan, te->filename, te->filename_len) != 0)
+			goto notfound;
+
+		scan += te->filename_len;
+
+		if (*scan) {
+			if (*scan != '/')
+				goto notfound;
+			scan++;
+		}
+	}
+
+notfound:
+	*tree_ptr = NULL;
+	return 0;
+}
+
 int git_iterator_current_is_ignored(git_iterator *iter)
 {
 	return (iter->type != GIT_ITERATOR_WORKDIR) ? 0 :
diff --git a/src/iterator.h b/src/iterator.h
index 29c8985..d7df501 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -142,6 +142,9 @@ GIT_INLINE(git_iterator_type_t) git_iterator_type(git_iterator *iter)
 extern int git_iterator_current_tree_entry(
 	git_iterator *iter, const git_tree_entry **tree_entry);
 
+extern int git_iterator_current_parent_tree(
+	git_iterator *iter, const char *parent_path, const git_tree **tree_ptr);
+
 extern int git_iterator_current_is_ignored(git_iterator *iter);
 
 /**
diff --git a/src/reflog.c b/src/reflog.c
index 80e40b9..a1ea7a2 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -372,7 +372,7 @@ int git_reflog_rename(git_reference *ref, const char *new_name)
 		goto cleanup;
 
 	if (git_path_isdir(git_buf_cstr(&new_path)) && 
-		(git_futils_rmdir_r(git_buf_cstr(&new_path), GIT_DIRREMOVAL_ONLY_EMPTY_DIRS) < 0))
+		(git_futils_rmdir_r(git_buf_cstr(&new_path), NULL, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS) < 0))
 		goto cleanup;
 
 	if (git_futils_mkpath2file(git_buf_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0)
diff --git a/src/refs.c b/src/refs.c
index 740d99e..833f2fc 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -276,14 +276,15 @@ static int loose_write(git_reference *ref)
 	if (git_buf_joinpath(&ref_path, ref->owner->path_repository, ref->name) < 0)
 		return -1;
 
-	/* Remove a possibly existing empty directory hierarchy 
+	/* Remove a possibly existing empty directory hierarchy
 	 * which name would collide with the reference name
 	 */
-	if (git_path_isdir(git_buf_cstr(&ref_path)) && 
-		(git_futils_rmdir_r(git_buf_cstr(&ref_path), GIT_DIRREMOVAL_ONLY_EMPTY_DIRS) < 0)) {
-			git_buf_free(&ref_path);
-			return -1;
-		}
+	if (git_path_isdir(git_buf_cstr(&ref_path)) &&
+		git_futils_rmdir_r(git_buf_cstr(&ref_path), NULL,
+			GIT_DIRREMOVAL_ONLY_EMPTY_DIRS) < 0) {
+		git_buf_free(&ref_path);
+		return -1;
+	}
 
 	if (git_filebuf_open(&file, ref_path.ptr, GIT_FILEBUF_FORCE) < 0) {
 		git_buf_free(&ref_path);
diff --git a/src/status.c b/src/status.c
index a37653d..f57100d 100644
--- a/src/status.c
+++ b/src/status.c
@@ -25,7 +25,6 @@ static unsigned int index_delta2status(git_delta_t index_status)
 	switch (index_status) {
 	case GIT_DELTA_ADDED:
 	case GIT_DELTA_COPIED:
-	case GIT_DELTA_RENAMED:
 		st = GIT_STATUS_INDEX_NEW;
 		break;
 	case GIT_DELTA_DELETED:
@@ -34,6 +33,12 @@ static unsigned int index_delta2status(git_delta_t index_status)
 	case GIT_DELTA_MODIFIED:
 		st = GIT_STATUS_INDEX_MODIFIED;
 		break;
+	case GIT_DELTA_RENAMED:
+		st = GIT_STATUS_INDEX_RENAMED;
+		break;
+	case GIT_DELTA_TYPECHANGE:
+		st = GIT_STATUS_INDEX_TYPECHANGE;
+		break;
 	default:
 		break;
 	}
@@ -47,8 +52,8 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
 
 	switch (workdir_status) {
 	case GIT_DELTA_ADDED:
-	case GIT_DELTA_COPIED:
 	case GIT_DELTA_RENAMED:
+	case GIT_DELTA_COPIED:
 	case GIT_DELTA_UNTRACKED:
 		st = GIT_STATUS_WT_NEW;
 		break;
@@ -61,6 +66,9 @@ static unsigned int workdir_delta2status(git_delta_t workdir_status)
 	case GIT_DELTA_IGNORED:
 		st = GIT_STATUS_IGNORED;
 		break;
+	case GIT_DELTA_TYPECHANGE:
+		st = GIT_STATUS_WT_TYPECHANGE;
+		break;
 	default:
 		break;
 	}
@@ -96,6 +104,8 @@ int git_status_foreach_ext(
 	memset(&diffopt, 0, sizeof(diffopt));
 	memcpy(&diffopt.pathspec, &opts->pathspec, sizeof(diffopt.pathspec));
 
+	diffopt.flags = GIT_DIFF_INCLUDE_TYPECHANGE;
+
 	if ((opts->flags & GIT_STATUS_OPT_INCLUDE_UNTRACKED) != 0)
 		diffopt.flags = diffopt.flags | GIT_DIFF_INCLUDE_UNTRACKED;
 	if ((opts->flags & GIT_STATUS_OPT_INCLUDE_IGNORED) != 0)
diff --git a/src/tree.c b/src/tree.c
index 83aa303..8d3f266 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -180,9 +180,9 @@ void git_tree__free(git_tree *tree)
 	git__free(tree);
 }
 
-const git_oid *git_tree_id(git_tree *c)
+const git_oid *git_tree_id(const git_tree *c)
 {
-	return git_object_id((git_object *)c);
+	return git_object_id((const git_object *)c);
 }
 
 git_filemode_t git_tree_entry_filemode(const git_tree_entry *entry)
@@ -286,7 +286,7 @@ int git_tree__prefix_position(git_tree *tree, const char *path)
 	return at_pos;
 }
 
-unsigned int git_tree_entrycount(git_tree *tree)
+unsigned int git_tree_entrycount(const git_tree *tree)
 {
 	assert(tree);
 	return (unsigned int)tree->entries.length;
diff --git a/tests-clar/checkout/typechange.c b/tests-clar/checkout/typechange.c
new file mode 100644
index 0000000..f013617
--- /dev/null
+++ b/tests-clar/checkout/typechange.c
@@ -0,0 +1,72 @@
+#include "clar_libgit2.h"
+#include "git2/checkout.h"
+#include "path.h"
+#include "posix.h"
+
+static git_repository *g_repo = NULL;
+
+static const char *g_typechange_oids[] = {
+	"79b9f23e85f55ea36a472a902e875bc1121a94cb",
+	"9bdb75b73836a99e3dbeea640a81de81031fdc29",
+	"0e7ed140b514b8cae23254cb8656fe1674403aff",
+	"9d0235c7a7edc0889a18f97a42ee6db9fe688447",
+	"9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a",
+	"1b63caae4a5ca96f78e8dfefc376c6a39a142475",
+	"6eae26c90e8ccc4d16208972119c40635489c6f0",
+	NULL
+};
+
+static bool g_typechange_empty[] = {
+	true, false, false, false, false, false, true, true
+};
+
+void test_checkout_typechange__initialize(void)
+{
+	g_repo = cl_git_sandbox_init("typechanges");
+
+	cl_fixture_sandbox("submod2_target");
+	p_rename("submod2_target/.gitted", "submod2_target/.git");
+}
+
+void test_checkout_typechange__cleanup(void)
+{
+	cl_git_sandbox_cleanup();
+	cl_fixture_cleanup("submod2_target");
+}
+
+void test_checkout_typechange__checkout_typechanges(void)
+{
+	int i;
+	git_object *obj;
+	git_checkout_opts opts = {0};
+
+	opts.checkout_strategy =
+		GIT_CHECKOUT_REMOVE_UNTRACKED |
+		GIT_CHECKOUT_CREATE_MISSING |
+		GIT_CHECKOUT_OVERWRITE_MODIFIED;
+
+	for (i = 0; g_typechange_oids[i] != NULL; ++i) {
+		cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));
+		/* fprintf(stderr, "checking out '%s'\n", g_typechange_oids[i]); */
+
+		cl_git_pass(git_checkout_tree(g_repo, obj, &opts, NULL));
+
+		git_object_free(obj);
+
+		if (!g_typechange_empty[i]) {
+			cl_assert(git_path_isdir("typechanges"));
+			cl_assert(git_path_exists("typechanges/a"));
+			cl_assert(git_path_exists("typechanges/b"));
+			cl_assert(git_path_exists("typechanges/c"));
+			cl_assert(git_path_exists("typechanges/d"));
+			cl_assert(git_path_exists("typechanges/e"));
+		} else {
+			cl_assert(git_path_isdir("typechanges"));
+			cl_assert(!git_path_exists("typechanges/a"));
+			cl_assert(!git_path_exists("typechanges/b"));
+			cl_assert(!git_path_exists("typechanges/c"));
+			cl_assert(!git_path_exists("typechanges/d"));
+			cl_assert(!git_path_exists("typechanges/e"));
+		}
+	}
+}
diff --git a/tests-clar/core/copy.c b/tests-clar/core/copy.c
index 2fdfed8..d0b21f6 100644
--- a/tests-clar/core/copy.c
+++ b/tests-clar/core/copy.c
@@ -41,7 +41,7 @@ void test_core_copy__file_in_dir(void)
 	cl_assert(S_ISREG(st.st_mode));
 	cl_assert(strlen(content) == (size_t)st.st_size);
 
-	cl_git_pass(git_futils_rmdir_r("an_dir", GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	cl_assert(!git_path_isdir("an_dir"));
 }
 
@@ -95,7 +95,7 @@ void test_core_copy__tree(void)
 	cl_assert(S_ISLNK(st.st_mode));
 #endif
 
-	cl_git_pass(git_futils_rmdir_r("t1", GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r("t1", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	cl_assert(!git_path_isdir("t1"));
 
 	/* copy with empty dirs, no links, yes dotfiles, no overwrite */
@@ -119,8 +119,8 @@ void test_core_copy__tree(void)
 	cl_git_fail(git_path_lstat("t2/c/d/l1", &st));
 #endif
 
-	cl_git_pass(git_futils_rmdir_r("t2", GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r("t2", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	cl_assert(!git_path_isdir("t2"));
 
-	cl_git_pass(git_futils_rmdir_r("src", GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r("src", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 }
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c
index 08ba241..e5dc665 100644
--- a/tests-clar/core/mkdir.c
+++ b/tests-clar/core/mkdir.c
@@ -6,11 +6,11 @@
 static void cleanup_basic_dirs(void *ref)
 {
 	GIT_UNUSED(ref);
-	git_futils_rmdir_r("d0", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
-	git_futils_rmdir_r("d1", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
-	git_futils_rmdir_r("d2", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
-	git_futils_rmdir_r("d3", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
-	git_futils_rmdir_r("d4", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("d0", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("d1", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("d2", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("d3", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("d4", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
 }
 
 void test_core_mkdir__basic(void)
@@ -56,7 +56,7 @@ void test_core_mkdir__basic(void)
 static void cleanup_basedir(void *ref)
 {
 	GIT_UNUSED(ref);
-	git_futils_rmdir_r("base", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("base", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
 }
 
 void test_core_mkdir__with_base(void)
@@ -108,7 +108,7 @@ static void cleanup_chmod_root(void *ref)
 		git__free(mode);
 	}
 
-	git_futils_rmdir_r("r", GIT_DIRREMOVAL_EMPTY_HIERARCHY);
+	git_futils_rmdir_r("r", NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY);
 }
 
 static void check_mode(mode_t expected, mode_t actual)
diff --git a/tests-clar/core/rmdir.c b/tests-clar/core/rmdir.c
index 530f1f9..9ada8f4 100644
--- a/tests-clar/core/rmdir.c
+++ b/tests-clar/core/rmdir.c
@@ -30,7 +30,7 @@ void test_core_rmdir__initialize(void)
 /* make sure empty dir can be deleted recusively */
 void test_core_rmdir__delete_recursive(void)
 {
-	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
 }
 
 /* make sure non-empty dir cannot be deleted recusively */
@@ -42,10 +42,10 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
 
 	cl_git_mkfile(git_buf_cstr(&file), "dummy");
 
-	cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+	cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
 
 	cl_must_pass(p_unlink(file.ptr));
-	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
+	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_DIRREMOVAL_EMPTY_HIERARCHY));
 
 	git_buf_free(&file);
 }
@@ -58,10 +58,10 @@ void test_core_rmdir__can_skip__non_empty_dir(void)
 
 	cl_git_mkfile(git_buf_cstr(&file), "dummy");
 
-	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS));
+	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_DIRREMOVAL_ONLY_EMPTY_DIRS));
 	cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
 
-	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	cl_assert(git_path_exists(empty_tmp_dir) == false);
 
 	git_buf_free(&file);
diff --git a/tests-clar/diff/iterator.c b/tests-clar/diff/iterator.c
index cca6450..c2ab994 100644
--- a/tests-clar/diff/iterator.c
+++ b/tests-clar/diff/iterator.c
@@ -1,6 +1,7 @@
 #include "clar_libgit2.h"
 #include "diff_helpers.h"
 #include "iterator.h"
+#include "tree.h"
 
 void test_diff_iterator__initialize(void)
 {
@@ -237,6 +238,103 @@ void test_diff_iterator__tree_range_empty_2(void)
 		NULL, ".aaa_empty_before", 0, NULL);
 }
 
+static void check_tree_entry(
+	git_iterator *i,
+	const char *oid,
+	const char *oid_p,
+	const char *oid_pp,
+	const char *oid_ppp)
+{
+	const git_index_entry *ie;
+	const git_tree_entry *te;
+	const git_tree *tree;
+	git_buf path = GIT_BUF_INIT;
+
+	cl_git_pass(git_iterator_current_tree_entry(i, &te));
+	cl_assert(te);
+	cl_assert(git_oid_streq(&te->oid, oid) == 0);
+
+	cl_git_pass(git_iterator_current(i, &ie));
+	cl_git_pass(git_buf_sets(&path, ie->path));
+
+	if (oid_p) {
+		git_buf_rtruncate_at_char(&path, '/');
+		cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+		cl_assert(tree);
+		cl_assert(git_oid_streq(git_tree_id(tree), oid_p) == 0);
+	}
+
+	if (oid_pp) {
+		git_buf_rtruncate_at_char(&path, '/');
+		cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+		cl_assert(tree);
+		cl_assert(git_oid_streq(git_tree_id(tree), oid_pp) == 0);
+	}
+
+	if (oid_ppp) {
+		git_buf_rtruncate_at_char(&path, '/');
+		cl_git_pass(git_iterator_current_parent_tree(i, path.ptr, &tree));
+		cl_assert(tree);
+		cl_assert(git_oid_streq(git_tree_id(tree), oid_ppp) == 0);
+	}
+
+	git_buf_free(&path);
+}
+
+void test_diff_iterator__tree_special_functions(void)
+{
+	git_tree *t;
+	git_iterator *i;
+	const git_index_entry *entry;
+	git_repository *repo = cl_git_sandbox_init("attr");
+	int cases = 0;
+	const char *rootoid = "ce39a97a7fb1fa90bcf5e711249c1e507476ae0e";
+
+	t = resolve_commit_oid_to_tree(
+		repo, "24fa9a9fc4e202313e24b648087495441dab432b");
+	cl_assert(t != NULL);
+
+	cl_git_pass(git_iterator_for_tree_range(&i, repo, t, NULL, NULL));
+	cl_git_pass(git_iterator_current(i, &entry));
+
+	while (entry != NULL) {
+		if (strcmp(entry->path, "sub/file") == 0) {
+			cases++;
+			check_tree_entry(
+				i, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
+				"ecb97df2a174987475ac816e3847fc8e9f6c596b",
+				rootoid, NULL);
+		}
+		else if (strcmp(entry->path, "sub/sub/subsub.txt") == 0) {
+			cases++;
+			check_tree_entry(
+				i, "9e5bdc47d6a80f2be0ea3049ad74231b94609242",
+				"4e49ba8c5b6c32ff28cd9dcb60be34df50fcc485",
+				"ecb97df2a174987475ac816e3847fc8e9f6c596b", rootoid);
+		}
+		else if (strcmp(entry->path, "subdir/.gitattributes") == 0) {
+			cases++;
+			check_tree_entry(
+				i, "99eae476896f4907224978b88e5ecaa6c5bb67a9",
+				"9fb40b6675dde60b5697afceae91b66d908c02d9",
+				rootoid, NULL);
+		}
+		else if (strcmp(entry->path, "subdir2/subdir2_test1") == 0) {
+			cases++;
+			check_tree_entry(
+				i, "dccada462d3df8ac6de596fb8c896aba9344f941",
+				"2929de282ce999e95183aedac6451d3384559c4b",
+				rootoid, NULL);
+		}
+
+		cl_git_pass(git_iterator_advance(i, &entry));
+	}
+
+	cl_assert_equal_i(4, cases);
+	git_iterator_free(i);
+	git_tree_free(t);
+}
+
 /* -- INDEX ITERATOR TESTS -- */
 
 static void index_iterator_test(
diff --git a/tests-clar/object/blob/write.c b/tests-clar/object/blob/write.c
index 722c7b9..87a9e20 100644
--- a/tests-clar/object/blob/write.c
+++ b/tests-clar/object/blob/write.c
@@ -49,7 +49,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolut
 	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
 
 	git_buf_free(&full_path);
-	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 }
 
 void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
@@ -65,5 +65,5 @@ void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_fi
 	assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_fromdisk);
 
 	git_buf_free(&full_path);
-	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 }
diff --git a/tests-clar/repo/discover.c b/tests-clar/repo/discover.c
index b3d639b..b5afab7 100644
--- a/tests-clar/repo/discover.c
+++ b/tests-clar/repo/discover.c
@@ -135,7 +135,7 @@ void test_repo_discover__0(void)
 	ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path);
 	ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path);
 
-	cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	git_repository_free(repo);
 	git_buf_free(&ceiling_dirs_buf);
 }
diff --git a/tests-clar/repo/open.c b/tests-clar/repo/open.c
index c70ec83..ef912fa 100644
--- a/tests-clar/repo/open.c
+++ b/tests-clar/repo/open.c
@@ -7,7 +7,7 @@ void test_repo_open__cleanup(void)
 	cl_git_sandbox_cleanup();
 
 	if (git_path_isdir("alternate"))
-		git_futils_rmdir_r("alternate", GIT_DIRREMOVAL_FILES_AND_DIRS);
+		git_futils_rmdir_r("alternate", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
 }
 
 void test_repo_open__bare_empty_repo(void)
@@ -202,8 +202,8 @@ void test_repo_open__bad_gitlinks(void)
 		cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
 	}
 
-	git_futils_rmdir_r("invalid", GIT_DIRREMOVAL_FILES_AND_DIRS);
-	git_futils_rmdir_r("invalid2", GIT_DIRREMOVAL_FILES_AND_DIRS);
+	git_futils_rmdir_r("invalid", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
+	git_futils_rmdir_r("invalid2", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS);
 }
 
 #ifdef GIT_WIN32
diff --git a/tests-clar/resources/typechanges/.gitted/HEAD b/tests-clar/resources/typechanges/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/config b/tests-clar/resources/typechanges/.gitted/config
new file mode 100644
index 0000000..4cc6e1d
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/config
@@ -0,0 +1,12 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
+[submodule "e"]
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[submodule "d"]
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[submodule "b"]
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
diff --git a/tests-clar/resources/typechanges/.gitted/description b/tests-clar/resources/typechanges/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/index b/tests-clar/resources/typechanges/.gitted/index
new file mode 100644
index 0000000..4f6d12a
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/index differ
diff --git a/tests-clar/resources/typechanges/.gitted/info/exclude b/tests-clar/resources/typechanges/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.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/typechanges/.gitted/modules/b/HEAD b/tests-clar/resources/typechanges/.gitted/modules/b/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/config b/tests-clar/resources/typechanges/.gitted/modules/b/config
new file mode 100644
index 0000000..f57cd4a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/config
@@ -0,0 +1,13 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	worktree = ../../../b
+	ignorecase = true
+[remote "origin"]
+	fetch = +refs/heads/*:refs/remotes/origin/*
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+	remote = origin
+	merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/description b/tests-clar/resources/typechanges/.gitted/modules/b/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/index b/tests-clar/resources/typechanges/.gitted/modules/b/index
new file mode 100644
index 0000000..c16a026
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/index differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/b/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/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/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 0000000..f4b7094
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 0000000..56c845e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 0000000..bd179b5
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 0000000..ccf49bd
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/41/bd4bc3df978de695f67ace64c560913da11653 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 0000000..5302906
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 0000000..38c791e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/5e/4963595a9774b90524d35a807169049de8ccad differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 0000000..a26d299
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+xQ
+!Evoy*_@g#hOh^9wSòf1*[Ic ԤpkΑ\S߇l@.^QpF(:D5zr~	en8
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 0000000..83d1ba4
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/73/ba924a80437097795ae839e66e187c55d3babf differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 0000000..6d27af8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-10Fa0p(N-ӡғq]>ks*?	|m“i@mV'`).-1x
+uxt(+
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 0000000..1745884
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x

0)?=
NlOkj8&r
+qJW7B<fK8#Q1C-"e̫>'@
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 0000000..83cc29f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 0000000..55bda40
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/b/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs
new file mode 100644
index 0000000..5a4ebc4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled 
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master
new file mode 100644
index 0000000..e12c44d
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD
new file mode 100644
index 0000000..6efe28f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/b/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/HEAD b/tests-clar/resources/typechanges/.gitted/modules/d/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/config b/tests-clar/resources/typechanges/.gitted/modules/d/config
new file mode 100644
index 0000000..42e1bdd
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/config
@@ -0,0 +1,13 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	worktree = ../../../d
+	ignorecase = true
+[remote "origin"]
+	fetch = +refs/heads/*:refs/remotes/origin/*
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+	remote = origin
+	merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/description b/tests-clar/resources/typechanges/.gitted/modules/d/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/index b/tests-clar/resources/typechanges/.gitted/modules/d/index
new file mode 100644
index 0000000..86d0266
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/index differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/d/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/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/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 0000000..f4b7094
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 0000000..56c845e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 0000000..bd179b5
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 0000000..ccf49bd
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/41/bd4bc3df978de695f67ace64c560913da11653 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 0000000..5302906
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 0000000..38c791e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/5e/4963595a9774b90524d35a807169049de8ccad differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 0000000..a26d299
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+xQ
+!Evoy*_@g#hOh^9wSòf1*[Ic ԤpkΑ\S߇l@.^QpF(:D5zr~	en8
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 0000000..83d1ba4
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/73/ba924a80437097795ae839e66e187c55d3babf differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 0000000..6d27af8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-10Fa0p(N-ӡғq]>ks*?	|m“i@mV'`).-1x
+uxt(+
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 0000000..1745884
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x

0)?=
NlOkj8&r
+qJW7B<fK8#Q1C-"e̫>'@
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 0000000..83cc29f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 0000000..55bda40
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/d/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs
new file mode 100644
index 0000000..5a4ebc4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled 
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master
new file mode 100644
index 0000000..e12c44d
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD
new file mode 100644
index 0000000..6efe28f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/d/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/HEAD b/tests-clar/resources/typechanges/.gitted/modules/e/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/config b/tests-clar/resources/typechanges/.gitted/modules/e/config
new file mode 100644
index 0000000..89b3b9b
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/config
@@ -0,0 +1,13 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	worktree = ../../../e
+	ignorecase = true
+[remote "origin"]
+	fetch = +refs/heads/*:refs/remotes/origin/*
+	url = /Users/rb/src/libgit2/tests-clar/resources/submod2_target/.git
+[branch "master"]
+	remote = origin
+	merge = refs/heads/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/description b/tests-clar/resources/typechanges/.gitted/modules/e/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/index b/tests-clar/resources/typechanges/.gitted/modules/e/index
new file mode 100644
index 0000000..cd6e2da
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/index differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/info/exclude b/tests-clar/resources/typechanges/.gitted/modules/e/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/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/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1
new file mode 100644
index 0000000..f4b7094
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/06/362fe2fdb7010d0e447b4fb450d405420479a1 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484
new file mode 100644
index 0000000..56c845e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/0e/6a3ca48bd47cfe67681acf39aa0b10a0b92484 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5
new file mode 100644
index 0000000..bd179b5
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/17/d0ece6e96460a06592d9d9d000de37ba4232c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653
new file mode 100644
index 0000000..ccf49bd
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/41/bd4bc3df978de695f67ace64c560913da11653 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0
new file mode 100644
index 0000000..5302906
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/48/0095882d281ed676fe5b863569520e54a7d5c0 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad b/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad
new file mode 100644
index 0000000..38c791e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/5e/4963595a9774b90524d35a807169049de8ccad differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e b/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
new file mode 100644
index 0000000..a26d299
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/6b/31c659545507c381e9cd34ec508f16c04e149e
@@ -0,0 +1,2 @@
+xQ
+!Evoy*_@g#hOh^9wSòf1*[Ic ԤpkΑ\S߇l@.^QpF(:D5zr~	en8
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf b/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf
new file mode 100644
index 0000000..83d1ba4
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/73/ba924a80437097795ae839e66e187c55d3babf differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
new file mode 100644
index 0000000..6d27af8
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/0d7397f5e8f8f477fb55b7af3accc2154b2d4a
@@ -0,0 +1,2 @@
+x-10Fa0p(N-ӡғq]>ks*?	|m“i@mV'`).-1x
+uxt(+
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b
new file mode 100644
index 0000000..1745884
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/objects/78/9efbdadaa4a582778d4584385495559ea0994b
@@ -0,0 +1,2 @@
+x

0)?=
NlOkj8&r
+qJW7B<fK8#Q1C-"e̫>'@
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e b/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e
new file mode 100644
index 0000000..83cc29f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/88/34b635dd468a83cb012f6feace968c1c9f5d6e differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 b/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5
new file mode 100644
index 0000000..55bda40
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/modules/e/objects/d0/5f2cd5cc77addf68ed6f50d622c9a4f732e6c5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs b/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs
new file mode 100644
index 0000000..5a4ebc4
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled 
+480095882d281ed676fe5b863569520e54a7d5c0 refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master b/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master
new file mode 100644
index 0000000..e12c44d
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/refs/heads/master
@@ -0,0 +1 @@
+480095882d281ed676fe5b863569520e54a7d5c0
diff --git a/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD b/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD
new file mode 100644
index 0000000..6efe28f
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/modules/e/refs/remotes/origin/HEAD
@@ -0,0 +1 @@
+ref: refs/remotes/origin/master
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8 b/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8
new file mode 100644
index 0000000..f2d02f4
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/0d/78578795b7ca49fd8df6c4b6d27c5c02d991d8 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff b/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff
new file mode 100644
index 0000000..527964c
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/0e/7ed140b514b8cae23254cb8656fe1674403aff differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586 b/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586
new file mode 100644
index 0000000..2694e4f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/0f/f461da9689266f482d8f6654a4400b4e33c586 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97 b/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97
new file mode 100644
index 0000000..032a960
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/18/aa7e45bbe4c3cc24a0b079696c59d36675af97 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475 b/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475
new file mode 100644
index 0000000..d32622e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/1b/63caae4a5ca96f78e8dfefc376c6a39a142475 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02 b/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02
new file mode 100644
index 0000000..42d5f92
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/1e/abe82aa3b2365a394f6108f24435df6e193d02 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95 b/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95
new file mode 100644
index 0000000..0a8f32e
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/42/061c01a1c70097d1e4579f29a5adf40abdec95 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592 b/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592
new file mode 100644
index 0000000..52af51f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/46/2838cee476a87e7cff32196b66fa18ed756592 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5 b/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5
new file mode 100644
index 0000000..afafa89
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/63/499e4ea8e096b831515ceb1d5a7593e4d87ae5 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e b/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e
new file mode 100644
index 0000000..9e518fc
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/68/1af94e10eaf262f3ab7cb9b8fd5f4158ba4d3e differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb b/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb
new file mode 100644
index 0000000..a245727
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/6a/9008602b811e69a9b7a2d83496f39a794fdeeb differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0 b/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0
new file mode 100644
index 0000000..ea35cd3
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/6e/ae26c90e8ccc4d16208972119c40635489c6f0 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0 b/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0
new file mode 100644
index 0000000..c548175
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/6f/39eabbb8a7541515e0d35971078bccb502e7e0 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4 b/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4
new file mode 100644
index 0000000..9fdd8f2
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/71/54d3083461536dfc71ad5542f3e65e723a06c4 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729 b/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729
new file mode 100644
index 0000000..d43630f
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/75/56c1d893a4c0ca85ac8ac51de47ff399758729 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2 b/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2
new file mode 100644
index 0000000..355ce4b
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/76/fef844064c26d5e06c2508240dae661e7231b2 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb b/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb
new file mode 100644
index 0000000..2b07ad2
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/79/b9f23e85f55ea36a472a902e875bc1121a94cb
@@ -0,0 +1,2 @@
+xA E]sfJbq`I@
+yH;ZeBr6LPY%8&v4Jm֢^*qpJµ;Z
Ơ3ZD1)"%%38_
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad b/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad
new file mode 100644
index 0000000..6d2da6c
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/85/28da0ea65eacf1f74f9ed6696adbac547963ad differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea b/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea
new file mode 100644
index 0000000..3dc333b
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/8b/3726b365824ad5a07c537247f4bc73ed7d37ea differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3 b/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3
new file mode 100644
index 0000000..02ad0e9
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/93/3e28c1c8a68838a763d250bdf0b2c6068289c3 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a b/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a
new file mode 100644
index 0000000..d06b06a
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/96/2710fe5b4e453e9e827945b3487c525968ec4a differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f b/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f
new file mode 100644
index 0000000..5f9ffd4
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/96/6cf1b3598e195b31b2cde3784f9a19f0728a6f differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7 b/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7
new file mode 100644
index 0000000..ac17def
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/99/e8bab9ece009f0fba7eb41f850f4c12bedb9b7 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a b/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a
new file mode 100644
index 0000000..7ab83ae
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/objects/9b/19edf33a03a0c59cdfc113bfa5c06179bf9b1a
@@ -0,0 +1,5 @@
+xI
+1E]LT
AJЃ7WpyӶ,ZѩUf cXcR	C43Y2"NN:HɈo6,sjf#kG
+cys
+MGm2B
+.K)k֑w8CC
\ No newline at end of file
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29 b/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29
new file mode 100644
index 0000000..aed4d81
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/9b/db75b73836a99e3dbeea640a81de81031fdc29 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447 b/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447
new file mode 100644
index 0000000..3e02a41
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/9d/0235c7a7edc0889a18f97a42ee6db9fe688447 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d b/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d
new file mode 100644
index 0000000..fb24100
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/9e/ffc457877f109b2a4319e14bee613a15f2a00d differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707 b/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707
new file mode 100644
index 0000000..b6b7db7
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/a0/a9bad6f6f40325198f938a0e3ae981622d7707 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d b/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d
new file mode 100644
index 0000000..e133405
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/b1/977dc4e573b812d4619754c98138c56999dc0d differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095 b/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095
new file mode 100644
index 0000000..65f1f53
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/d7/5992dd02391e128dac332dcc78d649dd9ab095 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c b/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c
new file mode 100644
index 0000000..355faa6
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/da/e2709d638df52212b1f43ff61797ebfedfcc7c differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad b/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad
new file mode 100644
index 0000000..c68fdcf
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/e1/152adcb9adf37ec551ada9ba377ab53aec3bad differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b b/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b
new file mode 100644
index 0000000..c9229ba
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/e4/ed436a9eb0f198cda722886a5f8d6d6c836b7b differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
new file mode 100644
index 0000000..7112238
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e b/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e
new file mode 100644
index 0000000..3962ba6
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/f2/0b79342712e0b2315647cd8227a573fd3bc46e differ
diff --git a/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d b/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d
new file mode 100644
index 0000000..e3663da
Binary files /dev/null and b/tests-clar/resources/typechanges/.gitted/objects/fd/e0147e3b59f381635a3b016e3fe6dacb70779d differ
diff --git a/tests-clar/resources/typechanges/.gitted/refs/heads/master b/tests-clar/resources/typechanges/.gitted/refs/heads/master
new file mode 100644
index 0000000..546481a
--- /dev/null
+++ b/tests-clar/resources/typechanges/.gitted/refs/heads/master
@@ -0,0 +1 @@
+6eae26c90e8ccc4d16208972119c40635489c6f0
diff --git a/tests-clar/resources/typechanges/README.md b/tests-clar/resources/typechanges/README.md
new file mode 100644
index 0000000..1f5a95a
--- /dev/null
+++ b/tests-clar/resources/typechanges/README.md
@@ -0,0 +1,43 @@
+This is a test repo for libgit2 where tree entries have type changes
+
+Types
+-----
+
+The key types that could be found in tree entries are:
+
+1. GIT_FILEMODE_NEW             = 0000000 (i.e. file does not exist)
+2. GIT_FILEMODE_TREE            = 0040000
+3. GIT_FILEMODE_BLOB            = 0100644
+4. GIT_FILEMODE_BLOB_EXECUTABLE = 0100755
+5. GIT_FILEMODE_LINK            = 0120000
+6. GIT_FILEMODE_COMMIT          = 0160000
+
+I will try to have every type of transition somewhere in the history
+of this repo.
+
+Commits
+-------
+
+* `a(1--1) b(1--1) c(1--1) d(1--1) e(1--1)`
+  **Initial commit**<br>
+  `79b9f23e85f55ea36a472a902e875bc1121a94cb`
+* `a(1->2) b(1->3) c(1->4) d(1->5) e(1->6)`
+  **Create content**<br>
+  `9bdb75b73836a99e3dbeea640a81de81031fdc29`
+* `a(2->3) b(3->4) c(4->5) d(5->6) e(6->2)`
+  **Changes #1**<br>
+  `0e7ed140b514b8cae23254cb8656fe1674403aff`
+* `a(3->5) b(4->6) c(5->2) d(6->3) e(2->4)`
+  **Changes #2**<br>
+  `9d0235c7a7edc0889a18f97a42ee6db9fe688447`
+* `a(5->3) b(6->4) c(2->5) d(3->6) e(4->2)`
+  **Changes #3**<br>
+  `9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a`
+* `a(3->2) b(4->3) c(5->4) d(6->5) e(2->6)`
+  **Changes #4**<br>
+  `1b63caae4a5ca96f78e8dfefc376c6a39a142475`<br>
+  Matches **Changes #1** except README.md
+* `a(2->1) b(3->1) c(4->1) d(5->1) e(6->1)`
+  **Changes #5**<br>
+  `6eae26c90e8ccc4d16208972119c40635489c6f0`<br>
+  Matches **Initial commit** except README.md and .gitmodules
diff --git a/tests-clar/resources/typechanges/gitmodules b/tests-clar/resources/typechanges/gitmodules
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests-clar/resources/typechanges/gitmodules
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 0ceba7f..4f03643 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -71,7 +71,7 @@ static int remove_file_cb(void *data, git_buf *file)
 		return 0;
 
 	if (git_path_isdir(filename))
-		cl_git_pass(git_futils_rmdir_r(filename, GIT_DIRREMOVAL_FILES_AND_DIRS));
+		cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	else
 		cl_git_pass(p_unlink(git_buf_cstr(file)));
 
@@ -314,7 +314,7 @@ void test_status_worktree__issue_592_3(void)
 	repo = cl_git_sandbox_init("issue_592");
 
 	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "c"));
-	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 
 	cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt"));
 
@@ -344,7 +344,7 @@ void test_status_worktree__issue_592_5(void)
 	repo = cl_git_sandbox_init("issue_592");
 
 	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(repo), "t"));
-	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 	cl_git_pass(p_mkdir(git_buf_cstr(&path), 0777));
 
 	cl_git_pass(git_status_foreach(repo, cb_status__check_592, NULL));
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index d3a3923..63073ce 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -50,7 +50,7 @@ void test_submodule_status__ignore_none(void)
 	git_buf path = GIT_BUF_INIT;
 
 	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), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 
 	cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule"));
 
@@ -135,7 +135,7 @@ void test_submodule_status__ignore_untracked(void)
 	git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_UNTRACKED;
 
 	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), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
 
@@ -195,7 +195,7 @@ void test_submodule_status__ignore_dirty(void)
 	git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_DIRTY;
 
 	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), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));
 
@@ -255,7 +255,7 @@ void test_submodule_status__ignore_all(void)
 	git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_ALL;
 
 	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), GIT_DIRREMOVAL_FILES_AND_DIRS));
+	cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
 
 	cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign));