Commit 6c21358a89efe5d4b8c5ab26dd707500653ba911

Vicent Martí 2012-10-30T11:51:58

Merge pull request #1029 from ethomson/index_refactor Index changes

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
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
diff --git a/examples/general.c b/examples/general.c
index e001a68..d9467f5 100644
--- a/examples/general.c
+++ b/examples/general.c
@@ -371,7 +371,7 @@ int main (int argc, char** argv)
   // All these properties are exported publicly in the `git_index_entry` struct
   ecount = git_index_entrycount(index);
   for (i = 0; i < ecount; ++i) {
-    git_index_entry *e = git_index_get(index, i);
+    git_index_entry *e = git_index_get_byindex(index, i);
 
     printf("path: %s\n", e->path);
     printf("mtime: %d\n", (int)e->mtime.seconds);
diff --git a/examples/showindex.c b/examples/showindex.c
index 7f2130b..d26fbae 100644
--- a/examples/showindex.c
+++ b/examples/showindex.c
@@ -19,12 +19,13 @@ int main (int argc, char** argv)
 
   ecount = git_index_entrycount(index);
   for (i = 0; i < ecount; ++i) {
-    git_index_entry *e = git_index_get(index, i);
+    git_index_entry *e = git_index_get_byindex(index, i);
 
     oid = e->oid;
     git_oid_fmt(out, &oid);
 
     printf("File Path: %s\n", e->path);
+	printf("    Stage: %d\n", git_index_entry_stage(e));
     printf(" Blob SHA: %s\n", out);
     printf("File Size: %d\n", (int)e->file_size);
     printf("   Device: %d\n", (int)e->dev);
diff --git a/include/git2/index.h b/include/git2/index.h
index e8af362..1d91663 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -84,12 +84,12 @@ typedef struct git_index_entry {
 	char *path;
 } git_index_entry;
 
-/** Representation of an unmerged file entry in the index. */
-typedef struct git_index_entry_unmerged {
+/** Representation of a resolve undo entry in the index. */
+typedef struct git_index_reuc_entry {
 	unsigned int mode[3];
 	git_oid oid[3];
 	char *path;
-} git_index_entry_unmerged;
+} git_index_reuc_entry;
 
 /** Capabilities of system that affect index actions. */
 enum {
@@ -99,6 +99,12 @@ enum {
 	GIT_INDEXCAP_FROM_OWNER  = ~0u
 };
 
+/** @name Index File Functions
+ *
+ * These functions work on the index file itself.
+ */
+/**@{*/
+
 /**
  * Create a new bare Git index object as a memory representation
  * of the Git index file in 'index_path', without a repository
@@ -120,20 +126,19 @@ enum {
 GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path);
 
 /**
- * Clear the contents (all the entries) of an index object.
- * This clears the index object in memory; changes must be manually
- * written to disk for them to take effect.
+ * Free an existing index object.
  *
  * @param index an existing index object
  */
-GIT_EXTERN(void) git_index_clear(git_index *index);
+GIT_EXTERN(void) git_index_free(git_index *index);
 
 /**
- * Free an existing index object.
+ * Get the repository this index relates to
  *
- * @param index an existing index object
+ * @param index The index
+ * @return A pointer to the repository
  */
-GIT_EXTERN(void) git_index_free(git_index *index);
+GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
 
 /**
  * Read index capabilities flags.
@@ -175,44 +180,92 @@ GIT_EXTERN(int) git_index_read(git_index *index);
 GIT_EXTERN(int) git_index_write(git_index *index);
 
 /**
- * Find the first index of any entries which point to given
- * path in the Git index.
+ * Read a tree into the index file with stats
+ *
+ * The current index contents will be replaced by the specified tree.
  *
  * @param index an existing index object
- * @param path path to search
- * @return an index >= 0 if found, -1 otherwise
+ * @param tree tree to read
+ * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
+GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
+
+/**@}*/
+
+/** @name Raw Index Entry Functions
+ *
+ * These functions work on index entries, and allow for raw manipulation
+ * of the entries.
+ */
+/**@{*/
+
+/* Index entry manipulation */
 
 /**
- * Remove all entries with equal path except last added
+ * Get the count of entries currently in the index
  *
  * @param index an existing index object
+ * @return integer of count of current entries
  */
-GIT_EXTERN(void) git_index_uniq(git_index *index);
+GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index);
 
 /**
- * Add or update an index entry from a file in disk
+ * Clear the contents (all the entries) of an index object.
+ * This clears the index object in memory; changes must be manually
+ * written to disk for them to take effect.
  *
- * The file `path` must be relative to the repository's
- * working folder and must be readable.
+ * @param index an existing index object
+ */
+GIT_EXTERN(void) git_index_clear(git_index *index);
+
+/**
+ * Get a pointer to one of the entries in the index
  *
- * This method will fail in bare index instances.
+ * The values of this entry can be modified (except the path)
+ * and the changes will be written back to disk on the next
+ * write() call.
  *
- * This forces the file to be added to the index, not looking
- * at gitignore rules.  Those rules can be evaluated through
- * the git_status APIs (in status.h) before calling this.
+ * The entry should not be freed by the caller.
  *
  * @param index an existing index object
- * @param path filename to add
- * @param stage stage for the entry
+ * @param n the position of the entry
+ * @return a pointer to the entry; NULL if out of bounds
+ */
+GIT_EXTERN(git_index_entry *) git_index_get_byindex(git_index *index, size_t n);
+
+/**
+ * Get a pointer to one of the entries in the index
+ *
+ * The values of this entry can be modified (except the path)
+ * and the changes will be written back to disk on the next
+ * write() call.
+ *
+ * The entry should not be freed by the caller.
+ *
+ * @param index an existing index object
+ * @param path path to search
+ * @param stage stage to search
+ * @return a pointer to the entry; NULL if it was not found
+ */
+GIT_EXTERN(git_index_entry *) git_index_get_bypath(git_index *index, const char *path, int stage);
+
+/**
+ * Remove an entry from the index
+ *
+ * @param index an existing index object
+ * @param path path to search
+ * @param stage stage to search
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
+GIT_EXTERN(int) git_index_remove(git_index *index, const char *path, int stage);
 
 /**
  * Add or update an index entry from an in-memory struct
  *
+ * If a previous index entry exists that has the same path and stage
+ * as the given 'source_entry', it will be replaced.  Otherwise, the
+ * 'source_entry' will be added.
+ *
  * A full copy (including the 'path' string) of the given
  * 'source_entry' will be inserted on the index.
  *
@@ -220,140 +273,207 @@ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage);
  * @param source_entry new entry object
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry);
+GIT_EXTERN(int) git_index_add(git_index *index, const git_index_entry *source_entry);
 
 /**
- * Add (append) an index entry from a file in disk
+ * Return the stage number from a git index entry
+ *
+ * This entry is calculated from the entry's flag
+ * attribute like this:
+ *
+ *	(entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
  *
- * A new entry will always be inserted into the index;
- * if the index already contains an entry for such
- * path, the old entry will **not** be replaced.
+ * @param entry The entry
+ * @returns the stage number
+ */
+GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
+
+/**@}*/
+
+/** @name Workdir Index Entry Functions
+ *
+ * These functions work on index entries specifically in the working
+ * directory (ie, stage 0).
+ */
+/**@{*/
+
+/**
+ * Add or update an index entry from a file in disk
  *
  * The file `path` must be relative to the repository's
  * working folder and must be readable.
  *
  * This method will fail in bare index instances.
  *
+ * This forces the file to be added to the index, not looking
+ * at gitignore rules.  Those rules can be evaluated through
+ * the git_status APIs (in status.h) before calling this.
+ *
+ * If this file currently is the result of a merge conflict, this
+ * file will no longer be marked as conflicting.  The data about
+ * the conflict will be moved to the "resolve undo" (REUC) section.
+ *
  * @param index an existing index object
  * @param path filename to add
- * @param stage stage for the entry
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage);
+GIT_EXTERN(int) git_index_add_from_workdir(git_index *index, const char *path);
 
 /**
- * Add (append) an index entry from an in-memory struct
+ * Find the first index of any entries which point to given
+ * path in the Git index.
  *
- * A new entry will always be inserted into the index;
- * if the index already contains an entry for the path
- * in the `entry` struct, the old entry will **not** be
- * replaced.
+ * @param index an existing index object
+ * @param path path to search
+ * @return an index >= 0 if found, -1 otherwise
+ */
+GIT_EXTERN(int) git_index_find(git_index *index, const char *path);
+
+/**@}*/
+
+/** @name Conflict Index Entry Functions
  *
- * A full copy (including the 'path' string) of the given
- * 'source_entry' will be inserted on the index.
+ * These functions work on conflict index entries specifically (ie, stages 1-3)
+ */
+/**@{*/
+
+/**
+ * Add or update index entries to represent a conflict
+ *
+ * The entries are the entries from the tree included in the merge.  Any
+ * entry may be null to indicate that that file was not present in the
+ * trees during the merge.  For example, ancestor_entry may be NULL to
+ * indicate that a file was added in both branches and must be resolved.
  *
  * @param index an existing index object
- * @param source_entry new entry object
+ * @param ancestor_entry the entry data for the ancestor of the conflict
+ * @param our_entry the entry data for our side of the merge conflict
+ * @param their_entry the entry data for their side of the merge conflict
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry);
+GIT_EXTERN(int) git_index_conflict_add(git_index *index,
+	const git_index_entry *ancestor_entry,
+	const git_index_entry *our_entry,
+	const git_index_entry *their_entry);
 
 /**
- * Remove an entry from the index
+ * Get the index entries that represent a conflict of a single file.
  *
+ * The values of this entry can be modified (except the paths)
+ * and the changes will be written back to disk on the next
+ * write() call.
+ *
+ * @param ancestor_out Pointer to store the ancestor entry
+ * @param our_out Pointer to store the our entry
+ * @param their_out Pointer to store the their entry
  * @param index an existing index object
- * @param position position of the entry to remove
- * @return 0 or an error code
+ * @param path path to search
  */
-GIT_EXTERN(int) git_index_remove(git_index *index, int position);
-
+GIT_EXTERN(int) git_index_conflict_get(git_index_entry **ancestor_out, git_index_entry **our_out, git_index_entry **their_out, git_index *index, const char *path);
 
 /**
- * Get a pointer to one of the entries in the index
- *
- * This entry can be modified, and the changes will be written
- * back to disk on the next write() call.
+ * Removes the index entries that represent a conflict of a single file.
  *
- * The entry should not be freed by the caller.
+ * @param index an existing index object
+ * @param path to search
+ */
+GIT_EXTERN(int) git_index_conflict_remove(git_index *index, const char *path);
+
+/**
+ * Remove all conflicts in the index (entries with a stage greater than 0.)
  *
  * @param index an existing index object
- * @param n the position of the entry
- * @return a pointer to the entry; NULL if out of bounds
  */
-GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, size_t n);
+GIT_EXTERN(void) git_index_conflict_cleanup(git_index *index);
+
+/**@}*/
+
+/** @name Resolve Undo (REUC) index entry manipulation.
+ *
+ * These functions work on the Resolve Undo index extension and contains
+ * data about the original files that led to a merge conflict.
+ */
+/**@{*/
 
 /**
- * Get the count of entries currently in the index
+ * Get the count of resolve undo entries currently in the index.
  *
  * @param index an existing index object
- * @return integer of count of current entries
+ * @return integer of count of current resolve undo entries
  */
-GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index);
+GIT_EXTERN(unsigned int) git_index_reuc_entrycount(git_index *index);
 
 /**
- * Get the count of unmerged entries currently in the index
+ * Finds the resolve undo entry that points to the given path in the Git
+ * index.
  *
  * @param index an existing index object
- * @return integer of count of current unmerged entries
+ * @param path path to search
+ * @return an index >= 0 if found, -1 otherwise
  */
-GIT_EXTERN(unsigned int) git_index_entrycount_unmerged(git_index *index);
+GIT_EXTERN(int) git_index_reuc_find(git_index *index, const char *path);
 
 /**
- * Get an unmerged entry from the index.
+ * Get a resolve undo entry from the index.
  *
  * The returned entry is read-only and should not be modified
  * of freed by the caller.
  *
  * @param index an existing index object
  * @param path path to search
- * @return the unmerged entry; NULL if not found
+ * @return the resolve undo entry; NULL if not found
  */
-GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_bypath(git_index *index, const char *path);
+GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_bypath(git_index *index, const char *path);
 
 /**
- * Get an unmerged entry from the index.
+ * Get a resolve undo entry from the index.
  *
  * The returned entry is read-only and should not be modified
  * of freed by the caller.
  *
  * @param index an existing index object
  * @param n the position of the entry
- * @return a pointer to the unmerged entry; NULL if out of bounds
+ * @return a pointer to the resolve undo entry; NULL if out of bounds
  */
-GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_index *index, size_t n);
+GIT_EXTERN(const git_index_reuc_entry *) git_index_reuc_get_byindex(git_index *index, size_t n);
 
 /**
- * Return the stage number from a git index entry
+ * Adds an resolve undo entry for a file based on the given parameters.
  *
- * This entry is calculated from the entry's flag
- * attribute like this:
+ * The resolve undo entry contains the OIDs of files that were involved
+ * in a merge conflict after the conflict has been resolved.  This allows
+ * conflicts to be re-resolved later.
  *
- *	(entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT
+ * If there exists a resolve undo entry for the given path in the index,
+ * it will be removed.
  *
- * @param entry The entry
- * @returns the stage number
- */
-GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
-
-/**
- * Read a tree into the index file with stats
- *
- * The current index contents will be replaced by the specified tree. The total
- * node count is collected in stats.
+ * This method will fail in bare index instances.
  *
  * @param index an existing index object
- * @param tree tree to read
+ * @param path filename to add
+ * @param ancestor_mode mode of the ancestor file
+ * @param ancestor_oid oid of the ancestor file
+ * @param our_mode mode of our file
+ * @param our_oid oid of our file
+ * @param their_mode mode of their file
+ * @param their_oid oid of their file
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
+GIT_EXTERN(int) git_index_reuc_add(git_index *index, const char *path,
+	int ancestor_mode, git_oid *ancestor_oid,
+	int our_mode, git_oid *our_oid,
+	int their_mode, git_oid *their_oid);
 
 /**
- * Get the repository this index relates to
+ * Remove an resolve undo entry from the index
  *
- * @param index The index
- * @return A pointer to the repository
+ * @param index an existing index object
+ * @param position position of the resolve undo entry to remove
+ * @return 0 or an error code
  */
-GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
+GIT_EXTERN(int) git_index_reuc_remove(git_index *index, int position);
+
+/**@}*/
 
 /** @} */
 GIT_END_DECL
diff --git a/src/attr.c b/src/attr.c
index 025ad3c..f5e09cc 100644
--- a/src/attr.c
+++ b/src/attr.c
@@ -307,7 +307,7 @@ static int load_attr_blob_from_index(
 		(error = git_index_find(index, relfile)) < 0)
 		return error;
 
-	entry = git_index_get(index, error);
+	entry = git_index_get_byindex(index, error);
 
 	if (old_oid && git_oid_cmp(old_oid, &entry->oid) == 0)
 		return GIT_ENOTFOUND;
diff --git a/src/index.c b/src/index.c
index 38e83d0..44dd934 100644
--- a/src/index.c
+++ b/src/index.c
@@ -81,6 +81,11 @@ struct entry_long {
 	char path[1]; /* arbitrary length */
 };
 
+struct entry_srch_key {
+	const char *path;
+	int stage;
+};
+
 /* local declarations */
 static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size);
 static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size);
@@ -90,53 +95,126 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 static int is_index_extended(git_index *index);
 static int write_index(git_index *index, git_filebuf *file);
 
+static int index_find(git_index *index, const char *path, int stage);
+
 static void index_entry_free(git_index_entry *entry);
+static void index_entry_reuc_free(git_index_reuc_entry *reuc);
+
+GIT_INLINE(int) index_entry_stage(const git_index_entry *entry)
+{
+	return (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;
+}
 
 static int index_srch(const void *key, const void *array_member)
 {
+	const struct entry_srch_key *srch_key = key;
 	const git_index_entry *entry = array_member;
+	int ret;
 
-	return strcmp(key, entry->path);
+	ret = strcmp(srch_key->path, entry->path);
+
+	if (ret == 0)
+		ret = srch_key->stage - index_entry_stage(entry);
+
+	return ret;
 }
 
 static int index_isrch(const void *key, const void *array_member)
 {
+	const struct entry_srch_key *srch_key = key;
+	const git_index_entry *entry = array_member;
+	int ret;
+
+	ret = strcasecmp(srch_key->path, entry->path);
+
+	if (ret == 0)
+		ret = srch_key->stage - index_entry_stage(entry);
+
+	return ret;
+}
+
+static int index_cmp_path(const void *a, const void *b)
+{
+	return strcmp((const char *)a, (const char *)b);
+}
+
+static int index_icmp_path(const void *a, const void *b)
+{
+	return strcasecmp((const char *)a, (const char *)b);
+}
+
+static int index_srch_path(const void *path, const void *array_member)
+{
 	const git_index_entry *entry = array_member;
 
-	return strcasecmp(key, entry->path);
+	return strcmp((const char *)path, entry->path);
+}
+
+static int index_isrch_path(const void *path, const void *array_member)
+{
+	const git_index_entry *entry = array_member;
+
+	return strcasecmp((const char *)path, entry->path);
 }
 
 static int index_cmp(const void *a, const void *b)
 {
+	int diff;
 	const git_index_entry *entry_a = a;
 	const git_index_entry *entry_b = b;
 
-	return strcmp(entry_a->path, entry_b->path);
+	diff = strcmp(entry_a->path, entry_b->path);
+
+	if (diff == 0)
+		diff = (index_entry_stage(entry_a) - index_entry_stage(entry_b));
+
+	return diff;
 }
 
 static int index_icmp(const void *a, const void *b)
 {
+	int diff;
 	const git_index_entry *entry_a = a;
 	const git_index_entry *entry_b = b;
 
-	return strcasecmp(entry_a->path, entry_b->path);
+	diff = strcasecmp(entry_a->path, entry_b->path);
+
+	if (diff == 0)
+		diff = (index_entry_stage(entry_a) - index_entry_stage(entry_b));
+
+	return diff;
+}
+
+static int reuc_srch(const void *key, const void *array_member)
+{
+	const git_index_reuc_entry *reuc = array_member;
+
+	return strcmp(key, reuc->path);
 }
 
-static int unmerged_srch(const void *key, const void *array_member)
+static int reuc_isrch(const void *key, const void *array_member)
 {
-	const git_index_entry_unmerged *entry = array_member;
+	const git_index_reuc_entry *reuc = array_member;
 
-	return strcmp(key, entry->path);
+	return strcasecmp(key, reuc->path);
 }
 
-static int unmerged_cmp(const void *a, const void *b)
+static int reuc_cmp(const void *a, const void *b)
 {
-	const git_index_entry_unmerged *info_a = a;
-	const git_index_entry_unmerged *info_b = b;
+	const git_index_reuc_entry *info_a = a;
+	const git_index_reuc_entry *info_b = b;
 
 	return strcmp(info_a->path, info_b->path);
 }
 
+static int reuc_icmp(const void *a, const void *b)
+{
+	const git_index_reuc_entry *info_a = a;
+	const git_index_reuc_entry *info_b = b;
+
+	return strcasecmp(info_a->path, info_b->path);
+}
+
 static unsigned int index_create_mode(unsigned int mode)
 {
 	if (S_ISLNK(mode))
@@ -165,9 +243,16 @@ static unsigned int index_merge_mode(
 static void index_set_ignore_case(git_index *index, bool ignore_case)
 {
 	index->entries._cmp = ignore_case ? index_icmp : index_cmp;
+	index->entries_cmp_path = ignore_case ? index_icmp_path : index_cmp_path;
 	index->entries_search = ignore_case ? index_isrch : index_srch;
+	index->entries_search_path = ignore_case ? index_isrch_path : index_srch_path;
 	index->entries.sorted = 0;
 	git_vector_sort(&index->entries);
+
+	index->reuc._cmp = ignore_case ? reuc_icmp : reuc_cmp;
+	index->reuc_search = ignore_case ? reuc_isrch : reuc_srch;
+	index->reuc.sorted = 0;
+	git_vector_sort(&index->reuc);
 }
 
 int git_index_open(git_index **index_out, const char *index_path)
@@ -185,7 +270,10 @@ int git_index_open(git_index **index_out, const char *index_path)
 	if (git_vector_init(&index->entries, 32, index_cmp) < 0)
 		return -1;
 
+	index->entries_cmp_path = index_cmp_path;
 	index->entries_search = index_srch;
+	index->entries_search_path = index_srch_path;
+	index->reuc_search = reuc_srch;
 
 	/* Check if index file is stored on disk already */
 	if (git_path_exists(index->index_file_path) == true)
@@ -199,6 +287,7 @@ int git_index_open(git_index **index_out, const char *index_path)
 static void index_free(git_index *index)
 {
 	git_index_entry *e;
+	git_index_reuc_entry *reuc;
 	unsigned int i;
 
 	git_index_clear(index);
@@ -206,10 +295,10 @@ static void index_free(git_index *index)
 		index_entry_free(e);
 	}
 	git_vector_free(&index->entries);
-	git_vector_foreach(&index->unmerged, i, e) {
-		index_entry_free(e);
+	git_vector_foreach(&index->reuc, i, reuc) {
+		index_entry_reuc_free(reuc);
 	}
-	git_vector_free(&index->unmerged);
+	git_vector_free(&index->reuc);
 
 	git__free(index->index_file_path);
 	git__free(index);
@@ -236,15 +325,15 @@ void git_index_clear(git_index *index)
 		git__free(e);
 	}
 
-	for (i = 0; i < index->unmerged.length; ++i) {
-		git_index_entry_unmerged *e;
-		e = git_vector_get(&index->unmerged, i);
+	for (i = 0; i < index->reuc.length; ++i) {
+		git_index_reuc_entry *e;
+		e = git_vector_get(&index->reuc, i);
 		git__free(e->path);
 		git__free(e);
 	}
 
 	git_vector_clear(&index->entries);
-	git_vector_clear(&index->unmerged);
+	git_vector_clear(&index->reuc);
 	index->last_modified = 0;
 
 	git_tree_cache_free(index->tree);
@@ -340,6 +429,7 @@ int git_index_write(git_index *index)
 	int error;
 
 	git_vector_sort(&index->entries);
+	git_vector_sort(&index->reuc);
 
 	if ((error = git_filebuf_open(
 			 &file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS)) < 0)
@@ -367,16 +457,25 @@ unsigned int git_index_entrycount(git_index *index)
 	return (unsigned int)index->entries.length;
 }
 
-unsigned int git_index_entrycount_unmerged(git_index *index)
+git_index_entry *git_index_get_byindex(git_index *index, size_t n)
 {
 	assert(index);
-	return (unsigned int)index->unmerged.length;
+	git_vector_sort(&index->entries);
+	return git_vector_get(&index->entries, n);
 }
 
-git_index_entry *git_index_get(git_index *index, size_t n)
+git_index_entry *git_index_get_bypath(git_index *index, const char *path, int stage)
 {
+	int pos;
+
+	assert(index);
+
 	git_vector_sort(&index->entries);
-	return git_vector_get(&index->entries, n);
+
+	if((pos = index_find(index, path, stage)) < 0)
+		return NULL;
+
+	return git_index_get_byindex(index, pos);
 }
 
 void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry)
@@ -393,7 +492,7 @@ void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry)
 	entry->file_size = st->st_size;
 }
 
-static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path, int stage)
+static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path)
 {
 	git_index_entry *entry = NULL;
 	struct stat st;
@@ -402,8 +501,6 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
 	git_buf full_path = GIT_BUF_INIT;
 	int error;
 
-	assert(stage >= 0 && stage <= 3);
-
 	if (INDEX_OWNER(index) == NULL ||
 		(workdir = git_repository_workdir(INDEX_OWNER(index))) == NULL)
 	{
@@ -436,7 +533,6 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
 	git_index__init_entry_from_stat(&st, entry);
 
 	entry->oid = oid;
-	entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT);
 	entry->path = git__strdup(rel_path);
 	GITERR_CHECK_ALLOC(entry->path);
 
@@ -444,6 +540,46 @@ static int index_entry_init(git_index_entry **entry_out, git_index *index, const
 	return 0;
 }
 
+static int index_entry_reuc_init(git_index_reuc_entry **reuc_out,
+	const char *path,
+	int ancestor_mode, git_oid *ancestor_oid,
+	int our_mode, git_oid *our_oid, int their_mode, git_oid *their_oid)
+{
+	git_index_reuc_entry *reuc = NULL;
+
+	assert(reuc_out && path);
+
+	*reuc_out = NULL;
+
+	reuc = git__calloc(1, sizeof(git_index_reuc_entry));
+	GITERR_CHECK_ALLOC(reuc);
+
+	reuc->path = git__strdup(path);
+	if (reuc->path == NULL)
+		return -1;
+
+	reuc->mode[0] = ancestor_mode;
+	git_oid_cpy(&reuc->oid[0], ancestor_oid);
+
+	reuc->mode[1] = our_mode;
+	git_oid_cpy(&reuc->oid[1], our_oid);
+
+	reuc->mode[2] = their_mode;
+	git_oid_cpy(&reuc->oid[2], their_oid);
+
+	*reuc_out = reuc;
+	return 0;
+}
+
+static void index_entry_reuc_free(git_index_reuc_entry *reuc)
+{
+	if (!reuc)
+		return;
+
+	git__free(reuc->path);
+	git__free(reuc);
+}
+
 static git_index_entry *index_entry_dup(const git_index_entry *source_entry)
 {
 	git_index_entry *entry;
@@ -486,10 +622,10 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
 	if (path_length < GIT_IDXENTRY_NAMEMASK)
 		entry->flags |= path_length & GIT_IDXENTRY_NAMEMASK;
 	else
-		entry->flags |= GIT_IDXENTRY_NAMEMASK;;
+		entry->flags |= GIT_IDXENTRY_NAMEMASK;
 
 	/* look if an entry with this path already exists */
-	if ((position = git_index_find(index, entry->path)) >= 0) {
+	if ((position = index_find(index, entry->path, index_entry_stage(entry))) >= 0) {
 		existing = (git_index_entry **)&index->entries.contents[position];
 
 		/* update filemode to existing values if stat is not trusted */
@@ -510,34 +646,56 @@ static int index_insert(git_index *index, git_index_entry *entry, int replace)
 	return 0;
 }
 
-static int index_add(git_index *index, const char *path, int stage, int replace)
+static int index_conflict_to_reuc(git_index *index, const char *path)
 {
-	git_index_entry *entry = NULL;
+	git_index_entry *conflict_entries[3];
+	int ancestor_mode, our_mode, their_mode;
+	git_oid *ancestor_oid, *our_oid, *their_oid;
 	int ret;
 
-	if ((ret = index_entry_init(&entry, index, path, stage)) < 0 ||
-		(ret = index_insert(index, entry, replace)) < 0)
-	{
-		index_entry_free(entry);
+	if ((ret = git_index_conflict_get(&conflict_entries[0],
+		&conflict_entries[1], &conflict_entries[2], index, path)) < 0)
 		return ret;
-	}
 
-	git_tree_cache_invalidate_path(index->tree, entry->path);
-	return 0;
-}
+	ancestor_mode = conflict_entries[0] == NULL ? 0 : conflict_entries[0]->mode;
+	our_mode = conflict_entries[1] == NULL ? 0 : conflict_entries[1]->mode;
+	their_mode = conflict_entries[2] == NULL ? 0 : conflict_entries[2]->mode;
 
-int git_index_add(git_index *index, const char *path, int stage)
-{
-	return index_add(index, path, stage, 1);
+	ancestor_oid = conflict_entries[0] == NULL ? NULL : &conflict_entries[0]->oid;
+	our_oid = conflict_entries[1] == NULL ? NULL : &conflict_entries[1]->oid;
+	their_oid = conflict_entries[2] == NULL ? NULL : &conflict_entries[2]->oid;
+
+	if ((ret = git_index_reuc_add(index, path, ancestor_mode, ancestor_oid,
+		our_mode, our_oid, their_mode, their_oid)) >= 0)
+		ret = git_index_conflict_remove(index, path);
+
+	return ret;
 }
 
-int git_index_append(git_index *index, const char *path, int stage)
+int git_index_add_from_workdir(git_index *index, const char *path)
 {
-	return index_add(index, path, stage, 0);
+	git_index_entry *entry = NULL;
+	int ret;
+
+	assert(index && path);
+
+	if ((ret = index_entry_init(&entry, index, path)) < 0 ||
+		(ret = index_insert(index, entry, 1)) < 0)
+		goto on_error;
+
+	/* Adding implies conflict was resolved, move conflict entries to REUC */
+	if ((ret = index_conflict_to_reuc(index, path)) < 0 && ret != GIT_ENOTFOUND)
+		goto on_error;
+
+	git_tree_cache_invalidate_path(index->tree, entry->path);
+	return 0;
+
+on_error:
+	index_entry_free(entry);
+	return ret;
 }
 
-static int index_add2(
-	git_index *index, const git_index_entry *source_entry, int replace)
+int git_index_add(git_index *index, const git_index_entry *source_entry)
 {
 	git_index_entry *entry = NULL;
 	int ret;
@@ -546,7 +704,7 @@ static int index_add2(
 	if (entry == NULL)
 		return -1;
 
-	if ((ret = index_insert(index, entry, replace)) < 0) {
+	if ((ret = index_insert(index, entry, 1)) < 0) {
 		index_entry_free(entry);
 		return ret;
 	}
@@ -555,23 +713,17 @@ static int index_add2(
 	return 0;
 }
 
-int git_index_add2(git_index *index, const git_index_entry *source_entry)
-{
-	return index_add2(index, source_entry, 1);
-}
-
-int git_index_append2(git_index *index, const git_index_entry *source_entry)
-{
-	return index_add2(index, source_entry, 0);
-}
-
-int git_index_remove(git_index *index, int position)
+int git_index_remove(git_index *index, const char *path, int stage)
 {
+	int position;
 	int error;
 	git_index_entry *entry;
 
 	git_vector_sort(&index->entries);
 
+	if ((position = index_find(index, path, stage)) < 0)
+		return position;
+
 	entry = git_vector_get(&index->entries, position);
 	if (entry != NULL)
 		git_tree_cache_invalidate_path(index->tree, entry->path);
@@ -584,45 +736,277 @@ int git_index_remove(git_index *index, int position)
 	return error;
 }
 
+static int index_find(git_index *index, const char *path, int stage)
+{
+	struct entry_srch_key srch_key;
+
+	assert(path);
+
+	srch_key.path = path;
+	srch_key.stage = stage;
+
+	return git_vector_bsearch2(&index->entries, index->entries_search, &srch_key);
+}
+
 int git_index_find(git_index *index, const char *path)
 {
-	return git_vector_bsearch2(&index->entries, index->entries_search, path);
+	int pos;
+
+	assert(index && path);
+
+	if ((pos = git_vector_bsearch2(&index->entries, index->entries_search_path, path)) < 0)
+		return pos;
+
+	/* Since our binary search only looked at path, we may be in the
+	 * middle of a list of stages. */
+	while (pos > 0) {
+		git_index_entry *prev = git_vector_get(&index->entries, pos-1);
+
+		if (index->entries_cmp_path(prev->path, path) != 0)
+			break;
+
+		--pos;
+	}
+
+	return pos;
 }
 
 unsigned int git_index__prefix_position(git_index *index, const char *path)
 {
+	struct entry_srch_key srch_key;
 	unsigned int pos;
 
-	git_vector_bsearch3(&pos, &index->entries, index->entries_search, path);
+	srch_key.path = path;
+	srch_key.stage = 0;
+
+	git_vector_bsearch3(&pos, &index->entries, index->entries_search, &srch_key);
 
 	return pos;
 }
 
-void git_index_uniq(git_index *index)
+int git_index_conflict_add(git_index *index,
+	const git_index_entry *ancestor_entry,
+	const git_index_entry *our_entry,
+	const git_index_entry *their_entry)
+{
+	git_index_entry *entries[3] = { 0 };
+	size_t i;
+	int ret = 0;
+
+	assert (index);
+
+	if ((ancestor_entry != NULL && (entries[0] = index_entry_dup(ancestor_entry)) == NULL) ||
+		(our_entry != NULL && (entries[1] = index_entry_dup(our_entry)) == NULL) ||
+		(their_entry != NULL && (entries[2] = index_entry_dup(their_entry)) == NULL))
+		return -1;
+
+	for (i = 0; i < 3; i++) {
+		if (entries[i] == NULL)
+			continue;
+
+		/* Make sure stage is correct */
+		entries[i]->flags = (entries[i]->flags & ~GIT_IDXENTRY_STAGEMASK) |
+			((i+1) << GIT_IDXENTRY_STAGESHIFT);
+
+		if ((ret = index_insert(index, entries[i], 1)) < 0)
+			goto on_error;
+	}
+
+    return 0;
+
+on_error:
+	for (i = 0; i < 3; i++) {
+		if (entries[i] != NULL)
+			index_entry_free(entries[i]);
+	}
+
+	return ret;
+}
+
+int git_index_conflict_get(git_index_entry **ancestor_out,
+	git_index_entry **our_out,
+	git_index_entry **their_out,
+	git_index *index, const char *path)
+{
+	int pos, stage;
+	git_index_entry *conflict_entry;
+	int error = GIT_ENOTFOUND;
+
+	assert(ancestor_out && our_out && their_out && index && path);
+
+	*ancestor_out = NULL;
+	*our_out = NULL;
+	*their_out = NULL;
+
+	if ((pos = git_index_find(index, path)) < 0)
+		return pos;
+
+	while ((unsigned int)pos < git_index_entrycount(index)) {
+		conflict_entry = git_vector_get(&index->entries, pos);
+
+		if (index->entries_cmp_path(conflict_entry->path, path) != 0)
+			break;
+
+		stage = index_entry_stage(conflict_entry);
+
+		switch (stage) {
+		case 3:
+			*their_out = conflict_entry;
+			error = 0;
+			break;
+		case 2:
+			*our_out = conflict_entry;
+			error = 0;
+			break;
+		case 1:
+			*ancestor_out = conflict_entry;
+			error = 0;
+			break;
+		default:
+			break;
+		};
+
+		++pos;
+	}
+
+	return error;
+}
+
+int git_index_conflict_remove(git_index *index, const char *path)
+{
+	int pos;
+	git_index_entry *conflict_entry;
+
+	assert(index && path);
+
+	if ((pos = git_index_find(index, path)) < 0)
+		return pos;
+
+	while ((unsigned int)pos < git_index_entrycount(index)) {
+		conflict_entry = git_vector_get(&index->entries, pos);
+
+		if (index->entries_cmp_path(conflict_entry->path, path) != 0)
+			break;
+
+		if (index_entry_stage(conflict_entry) == 0) {
+			pos++;
+			continue;
+		}
+
+		git_vector_remove(&index->entries, (unsigned int)pos);
+	}
+
+	return 0;
+}
+
+static int index_conflicts_match(git_vector *v, size_t idx)
+{
+	git_index_entry *entry = git_vector_get(v, idx);
+
+	if (index_entry_stage(entry) > 0)
+		return 1;
+
+	return 0;
+}
+
+void git_index_conflict_cleanup(git_index *index)
+{
+	assert(index);
+	git_vector_remove_matching(&index->entries, index_conflicts_match);
+}
+
+unsigned int git_index_reuc_entrycount(git_index *index)
+{
+	assert(index);
+	return (unsigned int)index->reuc.length;
+}
+
+static int index_reuc_insert(git_index *index, git_index_reuc_entry *reuc, int replace)
+{
+	git_index_reuc_entry **existing = NULL;
+	int position;
+
+	assert(index && reuc && reuc->path != NULL);
+
+	if ((position = git_index_reuc_find(index, reuc->path)) >= 0)
+		existing = (git_index_reuc_entry **)&index->reuc.contents[position];
+
+	if (!replace || !existing)
+		return git_vector_insert(&index->reuc, reuc);
+
+	/* exists, replace it */
+	git__free((*existing)->path);
+	git__free(*existing);
+	*existing = reuc;
+
+	return 0;
+}
+
+int git_index_reuc_add(git_index *index, const char *path,
+	int ancestor_mode, git_oid *ancestor_oid,
+	int our_mode, git_oid *our_oid,
+	int their_mode, git_oid *their_oid)
+{
+	git_index_reuc_entry *reuc = NULL;
+	int error = 0;
+
+	assert(index && path);
+
+	if ((error = index_entry_reuc_init(&reuc, path, ancestor_mode, ancestor_oid, our_mode, our_oid, their_mode, their_oid)) < 0 ||
+		(error = index_reuc_insert(index, reuc, 1)) < 0)
+	{
+		index_entry_reuc_free(reuc);
+		return error;
+	}
+
+	return error;
+} 
+
+int git_index_reuc_find(git_index *index, const char *path)
 {
-	git_vector_uniq(&index->entries);
+	return git_vector_bsearch2(&index->reuc, index->reuc_search, path);
 }
 
-const git_index_entry_unmerged *git_index_get_unmerged_bypath(
+const git_index_reuc_entry *git_index_reuc_get_bypath(
 	git_index *index, const char *path)
 {
 	int pos;
 	assert(index && path);
 
-	if (!index->unmerged.length)
+	if (!index->reuc.length)
 		return NULL;
 
-	if ((pos = git_vector_bsearch2(&index->unmerged, unmerged_srch, path)) < 0)
+	git_vector_sort(&index->reuc);
+
+	if ((pos = git_index_reuc_find(index, path)) < 0)
 		return NULL;
 
-	return git_vector_get(&index->unmerged, pos);
+	return git_vector_get(&index->reuc, pos);
 }
 
-const git_index_entry_unmerged *git_index_get_unmerged_byindex(
+const git_index_reuc_entry *git_index_reuc_get_byindex(
 	git_index *index, size_t n)
 {
 	assert(index);
-	return git_vector_get(&index->unmerged, n);
+
+	git_vector_sort(&index->reuc);
+	return git_vector_get(&index->reuc, n);
+}
+
+int git_index_reuc_remove(git_index *index, int position)
+{
+	int error;
+	git_index_reuc_entry *reuc;
+
+	git_vector_sort(&index->reuc);
+
+	reuc = git_vector_get(&index->reuc, position);
+	error = git_vector_remove(&index->reuc, (unsigned int)position);
+
+	if (!error)
+		index_entry_reuc_free(reuc);
+
+	return error;
 }
 
 static int index_error_invalid(const char *message)
@@ -631,26 +1015,26 @@ static int index_error_invalid(const char *message)
 	return -1;
 }
 
-static int read_unmerged(git_index *index, const char *buffer, size_t size)
+static int read_reuc(git_index *index, const char *buffer, size_t size)
 {
 	const char *endptr;
 	size_t len;
 	int i;
 
-	if (git_vector_init(&index->unmerged, 16, unmerged_cmp) < 0)
+	if (git_vector_init(&index->reuc, 16, reuc_cmp) < 0)
 		return -1;
 
 	while (size) {
-		git_index_entry_unmerged *lost;
+		git_index_reuc_entry *lost;
 
 		len = strlen(buffer) + 1;
 		if (size <= len)
-			return index_error_invalid("reading unmerged entries");
+			return index_error_invalid("reading reuc entries");
 
-		lost = git__malloc(sizeof(git_index_entry_unmerged));
+		lost = git__malloc(sizeof(git_index_reuc_entry));
 		GITERR_CHECK_ALLOC(lost);
 
-		if (git_vector_insert(&index->unmerged, lost) < 0)
+		if (git_vector_insert(&index->reuc, lost) < 0)
 			return -1;
 
 		/* read NUL-terminated pathname for entry */
@@ -667,13 +1051,13 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
 			if (git__strtol32(&tmp, buffer, &endptr, 8) < 0 ||
 				!endptr || endptr == buffer || *endptr ||
 				(unsigned)tmp > UINT_MAX)
-				return index_error_invalid("reading unmerged entry stage");
+				return index_error_invalid("reading reuc entry stage");
 
 			lost->mode[i] = tmp;
 
 			len = (endptr + 1) - buffer;
 			if (size <= len)
-				return index_error_invalid("reading unmerged entry stage");
+				return index_error_invalid("reading reuc entry stage");
 
 			size -= len;
 			buffer += len;
@@ -684,7 +1068,7 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
 			if (!lost->mode[i])
 				continue;
 			if (size < 20)
-				return index_error_invalid("reading unmerged entry oid");
+				return index_error_invalid("reading reuc entry oid");
 
 			git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer);
 			size -= 20;
@@ -692,6 +1076,9 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
 		}
 	}
 
+	/* entries are guaranteed to be sorted on-disk */
+	index->reuc.sorted = 1;
+
 	return 0;
 }
 
@@ -797,7 +1184,7 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer
 			if (git_tree_cache_read(&index->tree, buffer + 8, dest.extension_size) < 0)
 				return 0;
 		} else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) {
-			if (read_unmerged(index, buffer + 8, dest.extension_size) < 0)
+			if (read_reuc(index, buffer + 8, dest.extension_size) < 0)
 				return 0;
 		}
 		/* else, unsupported extension. We cannot parse this, but we can skip
@@ -996,6 +1383,69 @@ static int write_entries(git_index *index, git_filebuf *file)
 	return error;
 }
 
+static int write_extension(git_filebuf *file, struct index_extension *header, git_buf *data)
+{
+	struct index_extension ondisk;
+	int error = 0;
+
+	memset(&ondisk, 0x0, sizeof(struct index_extension));
+	memcpy(&ondisk, header, 4);
+	ondisk.extension_size = htonl(header->extension_size);
+
+	if ((error = git_filebuf_write(file, &ondisk, sizeof(struct index_extension))) == 0)
+		error = git_filebuf_write(file, data->ptr, data->size);
+
+	return error;
+}
+
+static int create_reuc_extension_data(git_buf *reuc_buf, git_index_reuc_entry *reuc)
+{
+	int i;
+	int error = 0;
+
+	if ((error = git_buf_put(reuc_buf, reuc->path, strlen(reuc->path) + 1)) < 0)
+		return error;
+
+	for (i = 0; i < 3; i++) {
+		if ((error = git_buf_printf(reuc_buf, "%o", reuc->mode[i])) < 0 ||
+			(error = git_buf_put(reuc_buf, "\0", 1)) < 0)
+			return error;
+	}
+
+	for (i = 0; i < 3; i++) {
+		if (reuc->mode[i] && (error = git_buf_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0)
+			return error;
+	}
+
+	return 0;
+}
+
+static int write_reuc_extension(git_index *index, git_filebuf *file)
+{
+	git_buf reuc_buf = GIT_BUF_INIT;
+	git_vector *out = &index->reuc;
+	git_index_reuc_entry *reuc;
+	struct index_extension extension;
+	unsigned int i;
+	int error = 0;
+
+	git_vector_foreach(out, i, reuc) {
+		if ((error = create_reuc_extension_data(&reuc_buf, reuc)) < 0)
+			goto done;
+	}
+
+	memset(&extension, 0x0, sizeof(struct index_extension));
+	memcpy(&extension.signature, INDEX_EXT_UNMERGED_SIG, 4);
+	extension.extension_size = reuc_buf.size;
+
+	error = write_extension(file, &extension, &reuc_buf);
+
+	git_buf_free(&reuc_buf);
+
+done:
+	return error;
+}
+
 static int write_index(git_index *index, git_filebuf *file)
 {
 	git_oid hash_final;
@@ -1018,7 +1468,11 @@ static int write_index(git_index *index, git_filebuf *file)
 	if (write_entries(index, file) < 0)
 		return -1;
 
-	/* TODO: write extensions (tree cache) */
+	/* TODO: write tree cache extension */
+
+	/* write the reuc extension */
+	if (index->reuc.length > 0 && write_reuc_extension(index, file) < 0)
+		return -1;
 
 	/* get out the hash for all the contents we've appended to the file */
 	git_filebuf_hash(&hash_final, file);
@@ -1029,7 +1483,7 @@ static int write_index(git_index *index, git_filebuf *file)
 
 int git_index_entry_stage(const git_index_entry *entry)
 {
-	return (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;
+	return index_entry_stage(entry);
 }
 
 typedef struct read_tree_data {
diff --git a/src/index.h b/src/index.h
index 7dd23ee..0fd59dd 100644
--- a/src/index.h
+++ b/src/index.h
@@ -33,9 +33,12 @@ struct git_index {
 
 	git_tree_cache *tree;
 
-	git_vector unmerged;
+	git_vector reuc;
 
+	git_vector_cmp entries_cmp_path;
 	git_vector_cmp entries_search;
+	git_vector_cmp entries_search_path;
+	git_vector_cmp reuc_search;
 };
 
 extern void git_index__init_entry_from_stat(struct stat *st, git_index_entry *entry);
diff --git a/src/iterator.c b/src/iterator.c
index df6da9a..5fac410 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -336,7 +336,7 @@ static int index_iterator__current(
 	git_iterator *self, const git_index_entry **entry)
 {
 	index_iterator *ii = (index_iterator *)self;
-	git_index_entry *ie = git_index_get(ii->index, ii->current);
+	git_index_entry *ie = git_index_get_byindex(ii->index, ii->current);
 
 	if (ie != NULL &&
 		ii->base.end != NULL &&
diff --git a/src/stash.c b/src/stash.c
index 3011f00..9c9c5dc 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -183,13 +183,13 @@ static int update_index_cb(
 		if (!data->include_ignored)
 			break;
 
-		return git_index_add(data->index, delta->new_file.path, 0);
+		return git_index_add_from_workdir(data->index, delta->new_file.path);
 
 	case GIT_DELTA_UNTRACKED:
 		if (!data->include_untracked)
 			break;
 
-		return git_index_add(data->index, delta->new_file.path, 0);
+		return git_index_add_from_workdir(data->index, delta->new_file.path);
 
 	case GIT_DELTA_ADDED:
 		/* Fall through */
@@ -197,7 +197,7 @@ static int update_index_cb(
 		if (!data->include_changed)
 			break;
 
-		return git_index_add(data->index, delta->new_file.path, 0);
+		return git_index_add_from_workdir(data->index, delta->new_file.path);
 
 	case GIT_DELTA_DELETED:
 		if (!data->include_changed)
@@ -206,7 +206,7 @@ static int update_index_cb(
 		if ((pos = git_index_find(data->index, delta->new_file.path)) < 0)
 			return -1;
 
-		if (git_index_remove(data->index, pos) < 0)
+		if (git_index_remove(data->index, delta->new_file.path, 0) < 0)
 			return -1;
 
 	default:
diff --git a/src/submodule.c b/src/submodule.c
index e3657f9..d69559d 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -332,7 +332,7 @@ int git_submodule_add_finalize(git_submodule *sm)
 	assert(sm);
 
 	if ((error = git_repository_index__weakptr(&index, sm->owner)) < 0 ||
-		(error = git_index_add(index, GIT_MODULES_FILE, 0)) < 0)
+		(error = git_index_add_from_workdir(index, GIT_MODULES_FILE)) < 0)
 		return error;
 
 	return git_submodule_add_to_index(sm, true);
@@ -393,7 +393,7 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
 	git_commit_free(head);
 
 	/* add it */
-	error = git_index_add2(index, &entry);
+	error = git_index_add(index, &entry);
 
 	/* write it, if requested */
 	if (!error && write_index) {
@@ -733,7 +733,7 @@ int git_submodule_reload(git_submodule *submodule)
 
 	pos = git_index_find(index, submodule->path);
 	if (pos >= 0) {
-		git_index_entry *entry = git_index_get(index, pos);
+		git_index_entry *entry = git_index_get_byindex(index, pos);
 
 		if (S_ISGITLINK(entry->mode)) {
 			if ((error = submodule_load_from_index(repo, entry)) < 0)
diff --git a/src/tree.c b/src/tree.c
index 8d3f266..9ecefbb 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -353,7 +353,7 @@ static unsigned int find_next_dir(const char *dirname, git_index *index, unsigne
 
 	dirlen = strlen(dirname);
 	for (i = start; i < entries; ++i) {
-		git_index_entry *entry = git_index_get(index, i);
+		git_index_entry *entry = git_index_get_byindex(index, i);
 		if (strlen(entry->path) < dirlen ||
 		    memcmp(entry->path, dirname, dirlen) ||
 			(dirlen > 0 && entry->path[dirlen] != '/')) {
@@ -415,7 +415,7 @@ static int write_tree(
 	 * need to keep track of the current position.
 	 */
 	for (i = start; i < entries; ++i) {
-		git_index_entry *entry = git_index_get(index, i);
+		git_index_entry *entry = git_index_get_byindex(index, i);
 		char *filename, *next_slash;
 
 	/*
diff --git a/src/vector.c b/src/vector.c
index c6a644c..d9c4c99 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -223,6 +223,20 @@ void git_vector_uniq(git_vector *v)
 	v->length -= j - i - 1;
 }
 
+void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx))
+{
+	unsigned int i, j;
+
+	for (i = 0, j = 0; j < v->length; ++j) {
+		v->contents[i] = v->contents[j];
+
+		if (!match(v, i))
+			i++;
+	}
+
+	v->length = i;
+}
+
 void git_vector_clear(git_vector *v)
 {
 	assert(v);
diff --git a/src/vector.h b/src/vector.h
index 49ba754..32f790c 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -75,5 +75,6 @@ int git_vector_insert_sorted(git_vector *v, void *element,
 int git_vector_remove(git_vector *v, unsigned int idx);
 void git_vector_pop(git_vector *v);
 void git_vector_uniq(git_vector *v);
+void git_vector_remove_matching(git_vector *v, int (*match)(git_vector *v, size_t idx));
 
 #endif
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index 4a317e4..b51d5e3 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -270,12 +270,12 @@ static void assert_proper_normalization(git_index *index, const char *filename, 
 	git_index_entry *entry;
 
 	add_to_workdir(filename, CONTENT);
-	cl_git_pass(git_index_add(index, filename, 0));
+	cl_git_pass(git_index_add_from_workdir(index, filename));
 
 	index_pos = git_index_find(index, filename);
 	cl_assert(index_pos >= 0);
 
-	entry = git_index_get(index, index_pos);
+	entry = git_index_get_byindex(index, index_pos);
 	cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha));
 }
 
diff --git a/tests-clar/core/vector.c b/tests-clar/core/vector.c
index ef3d6c3..b165905 100644
--- a/tests-clar/core/vector.c
+++ b/tests-clar/core/vector.c
@@ -189,3 +189,87 @@ void test_core_vector__5(void)
 
 	git_vector_free(&x);
 }
+
+static int remove_ones(git_vector *v, size_t idx)
+{
+	return (git_vector_get(v, idx) == (void *)0x001);
+}
+
+/* Test removal based on callback */
+void test_core_vector__remove_matching(void)
+{
+	git_vector x;
+	size_t i;
+	void *compare;
+
+	git_vector_init(&x, 1, NULL);
+	git_vector_insert(&x, (void*) 0x001);
+
+	cl_assert(x.length == 1);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 0);
+
+	git_vector_insert(&x, (void*) 0x001);
+	git_vector_insert(&x, (void*) 0x001);
+	git_vector_insert(&x, (void*) 0x001);
+
+	cl_assert(x.length == 3);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 0);
+
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x001);
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x001);
+
+	cl_assert(x.length == 4);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 2);
+
+	git_vector_foreach(&x, i, compare) {
+		cl_assert(compare != (void *)0x001);
+	}
+
+	git_vector_clear(&x);
+
+	git_vector_insert(&x, (void*) 0x001);
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x001);
+
+	cl_assert(x.length == 4);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 2);
+
+	git_vector_foreach(&x, i, compare) {
+		cl_assert(compare != (void *)0x001);
+	}
+
+	git_vector_clear(&x);
+
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x001);
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x001);
+
+	cl_assert(x.length == 4);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 2);
+
+	git_vector_foreach(&x, i, compare) {
+		cl_assert(compare != (void *)0x001);
+	}
+
+	git_vector_clear(&x);
+
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x003);
+	git_vector_insert(&x, (void*) 0x002);
+	git_vector_insert(&x, (void*) 0x003);
+
+	cl_assert(x.length == 4);
+	git_vector_remove_matching(&x, remove_ones);
+	cl_assert(x.length == 4);
+
+	git_vector_free(&x);
+}
diff --git a/tests-clar/index/conflicts.c b/tests-clar/index/conflicts.c
new file mode 100644
index 0000000..59df257
--- /dev/null
+++ b/tests-clar/index/conflicts.c
@@ -0,0 +1,217 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define CONFLICTS_ONE_ANCESTOR_OID "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81"
+#define CONFLICTS_ONE_OUR_OID "6aea5f295304c36144ad6e9247a291b7f8112399"
+#define CONFLICTS_ONE_THEIR_OID "516bd85f78061e09ccc714561d7b504672cb52da"
+
+#define CONFLICTS_TWO_ANCESTOR_OID "84af62840be1b1c47b778a8a249f3ff45155038c"
+#define CONFLICTS_TWO_OUR_OID "8b3f43d2402825c200f835ca1762413e386fd0b2"
+#define CONFLICTS_TWO_THEIR_OID "220bd62631c8cf7a83ef39c6b94595f00517211e"
+
+#define TEST_ANCESTOR_OID "f00ff00ff00ff00ff00ff00ff00ff00ff00ff00f"
+#define TEST_OUR_OID "b44bb44bb44bb44bb44bb44bb44bb44bb44bb44b"
+#define TEST_THEIR_OID "0123456789abcdef0123456789abcdef01234567"
+
+// Fixture setup and teardown
+void test_index_conflicts__initialize(void)
+{
+	repo = cl_git_sandbox_init("mergedrepo");
+	git_repository_index(&repo_index, repo);
+}
+
+void test_index_conflicts__cleanup(void)
+{
+	git_index_free(repo_index);
+	cl_git_sandbox_cleanup();
+}
+
+void test_index_conflicts__add(void)
+{
+	git_index_entry ancestor_entry, our_entry, their_entry;
+
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+	memset(&our_entry, 0x0, sizeof(git_index_entry));
+	memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+	ancestor_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+	our_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&our_entry.oid, TEST_OUR_OID);
+
+	their_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&their_entry.oid, TEST_THEIR_OID);
+
+	cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
+
+	cl_assert(git_index_entrycount(repo_index) == 11);
+}
+
+void test_index_conflicts__add_fixes_incorrect_stage(void)
+{
+	git_index_entry ancestor_entry, our_entry, their_entry;
+	git_index_entry *conflict_entry[3];
+
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+	memset(&our_entry, 0x0, sizeof(git_index_entry));
+	memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+	ancestor_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+	our_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&our_entry.oid, TEST_OUR_OID);
+
+	their_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&their_entry.oid, TEST_THEIR_OID);
+
+	cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
+
+	cl_assert(git_index_entrycount(repo_index) == 11);
+
+	cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt"));
+
+	cl_assert(git_index_entry_stage(conflict_entry[0]) == 1);
+	cl_assert(git_index_entry_stage(conflict_entry[1]) == 2);
+	cl_assert(git_index_entry_stage(conflict_entry[2]) == 3);
+}
+
+void test_index_conflicts__get(void)
+{
+	git_index_entry *conflict_entry[3];
+	git_oid oid;
+
+	cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+		&conflict_entry[2], repo_index, "conflicts-one.txt"));
+
+	cl_assert(strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[0]->oid, &oid) == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[1]->oid, &oid) == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[2]->oid, &oid) == 0);
+
+	cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+		&conflict_entry[2], repo_index, "conflicts-two.txt"));
+
+	cl_assert(strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[0]->oid, &oid) == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[1]->oid, &oid) == 0);
+
+	git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&conflict_entry[2]->oid, &oid) == 0);
+}
+
+void test_index_conflicts__remove(void)
+{
+	git_index_entry *entry;
+	size_t i;
+	
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	cl_git_pass(git_index_conflict_remove(repo_index, "conflicts-one.txt"));
+	cl_assert(git_index_entrycount(repo_index) == 5);
+
+	for (i = 0; i < git_index_entrycount(repo_index); i++) {
+		cl_assert(entry = git_index_get_byindex(repo_index, i));
+		cl_assert(strcmp(entry->path, "conflicts-one.txt") != 0);
+	}
+
+	cl_git_pass(git_index_conflict_remove(repo_index, "conflicts-two.txt"));
+	cl_assert(git_index_entrycount(repo_index) == 2);
+
+	for (i = 0; i < git_index_entrycount(repo_index); i++) {
+		cl_assert(entry = git_index_get_byindex(repo_index, i));
+		cl_assert(strcmp(entry->path, "conflicts-two.txt") != 0);
+	}
+}
+
+void test_index_conflicts__moved_to_reuc(void)
+{
+	git_index_entry *entry;
+	size_t i;
+
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	cl_git_mkfile("./mergedrepo/conflicts-one.txt", "new-file\n");
+
+	cl_git_pass(git_index_add_from_workdir(repo_index, "conflicts-one.txt"));
+
+	cl_assert(git_index_entrycount(repo_index) == 6);
+
+	for (i = 0; i < git_index_entrycount(repo_index); i++) {
+		cl_assert(entry = git_index_get_byindex(repo_index, i));
+
+		if (strcmp(entry->path, "conflicts-one.txt") == 0)
+			cl_assert(git_index_entry_stage(entry) == 0);
+	}
+}
+
+void test_index_conflicts__remove_all_conflicts(void)
+{
+	size_t i;
+	git_index_entry *entry;
+
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	git_index_conflict_cleanup(repo_index);
+
+	cl_assert(git_index_entrycount(repo_index) == 2);
+
+	for (i = 0; i < git_index_entrycount(repo_index); i++) {
+		cl_assert(entry = git_index_get_byindex(repo_index, i));
+		cl_assert(git_index_entry_stage(entry) == 0);
+	}
+}
+
+void test_index_conflicts__partial(void)
+{
+	git_index_entry ancestor_entry, our_entry, their_entry;
+	git_index_entry *conflict_entry[3];
+
+	cl_assert(git_index_entrycount(repo_index) == 8);
+
+	memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
+	memset(&our_entry, 0x0, sizeof(git_index_entry));
+	memset(&their_entry, 0x0, sizeof(git_index_entry));
+
+	ancestor_entry.path = "test-one.txt";
+	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
+	git_oid_fromstr(&ancestor_entry.oid, TEST_ANCESTOR_OID);
+
+	cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, NULL, NULL));
+	cl_assert(git_index_entrycount(repo_index) == 9);
+
+	cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
+		&conflict_entry[2], repo_index, "test-one.txt"));
+
+	cl_assert(git_oid_cmp(&ancestor_entry.oid, &conflict_entry[0]->oid) == 0);
+	cl_assert(conflict_entry[1] == NULL);
+	cl_assert(conflict_entry[2] == NULL);
+}
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 75c94e8..882d417 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -25,7 +25,7 @@ void test_index_filemodes__read(void)
 	cl_assert_equal_i(6, git_index_entrycount(index));
 
 	for (i = 0; i < 6; ++i) {
-		git_index_entry *entry = git_index_get(index, i);
+		git_index_entry *entry = git_index_get_byindex(index, i);
 		cl_assert(entry != NULL);
 		cl_assert(((entry->mode & 0100) ? 1 : 0) == expected[i]);
 	}
@@ -56,35 +56,15 @@ static void add_and_check_mode(
 	int pos;
 	git_index_entry *entry;
 
-	cl_git_pass(git_index_add(index, filename, 0));
+	cl_git_pass(git_index_add_from_workdir(index, filename));
 
 	pos = git_index_find(index, filename);
 	cl_assert(pos >= 0);
 
-	entry = git_index_get(index, pos);
+	entry = git_index_get_byindex(index, pos);
 	cl_assert(entry->mode == expect_mode);
 }
 
-static void append_and_check_mode(
-	git_index *index, const char *filename, unsigned int expect_mode)
-{
-	unsigned int before, after;
-	git_index_entry *entry;
-
-	before = git_index_entrycount(index);
-
-	cl_git_pass(git_index_append(index, filename, 0));
-
-	after = git_index_entrycount(index);
-	cl_assert_equal_i(before + 1, after);
-
-	/* bypass git_index_get since that resorts the index */
-	entry = (git_index_entry *)git_vector_get(&index->entries, after - 1);
-
-	cl_assert_equal_s(entry->path, filename);
-	cl_assert(expect_mode == entry->mode);
-}
-
 void test_index_filemodes__untrusted(void)
 {
 	git_config *cfg;
@@ -114,23 +94,7 @@ void test_index_filemodes__untrusted(void)
 	replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755);
 	add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
 
-	/* 5 - append 0644 over existing 0644 -> expect 0644 */
-	replace_file_with_mode("exec_off", "filemodes/exec_off.2", 0644);
-	append_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
-
-	/* 6 - append 0644 over existing 0755 -> expect 0755 */
-	replace_file_with_mode("exec_on", "filemodes/exec_on.2", 0644);
-	append_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
-
-	/* 7 - append 0755 over existing 0644 -> expect 0644 */
-	replace_file_with_mode("exec_off", "filemodes/exec_off.3", 0755);
-	append_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
-
-	/* 8 - append 0755 over existing 0755 -> expect 0755 */
-	replace_file_with_mode("exec_on", "filemodes/exec_on.3", 0755);
-	append_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
-
-	/*  9 - add new 0644 -> expect 0644 */
+	/*  5 - add new 0644 -> expect 0644 */
 	cl_git_write2file("filemodes/new_off", "blah",
 		O_WRONLY | O_CREAT | O_TRUNC, 0644);
 	add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
@@ -139,7 +103,7 @@ void test_index_filemodes__untrusted(void)
 	 * that doesn't support filemodes correctly, so skip it.
 	 */
 	if (can_filemode) {
-		/* 10 - add 0755 -> expect 0755 */
+		/* 6 - add 0755 -> expect 0755 */
 		cl_git_write2file("filemodes/new_on", "blah",
 			O_WRONLY | O_CREAT | O_TRUNC, 0755);
 		add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
@@ -182,28 +146,12 @@ void test_index_filemodes__trusted(void)
 	replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755);
 	add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
 
-	/* 5 - append 0644 over existing 0644 -> expect 0644 */
-	replace_file_with_mode("exec_off", "filemodes/exec_off.2", 0644);
-	append_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB);
-
-	/* 6 - append 0644 over existing 0755 -> expect 0644 */
-	replace_file_with_mode("exec_on", "filemodes/exec_on.2", 0644);
-	append_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB);
-
-	/* 7 - append 0755 over existing 0644 -> expect 0755 */
-	replace_file_with_mode("exec_off", "filemodes/exec_off.3", 0755);
-	append_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB_EXECUTABLE);
-
-	/* 8 - append 0755 over existing 0755 -> expect 0755 */
-	replace_file_with_mode("exec_on", "filemodes/exec_on.3", 0755);
-	append_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
-
-	/*  9 - add new 0644 -> expect 0644 */
+	/*  5 - add new 0644 -> expect 0644 */
 	cl_git_write2file("filemodes/new_off", "blah",
 		O_WRONLY | O_CREAT | O_TRUNC, 0644);
 	add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
 
-	/* 10 - add 0755 -> expect 0755 */
+	/* 6 - add 0755 -> expect 0755 */
 	cl_git_write2file("filemodes/new_on", "blah",
 		O_WRONLY | O_CREAT | O_TRUNC, 0755);
 	add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
diff --git a/tests-clar/index/read_tree.c b/tests-clar/index/read_tree.c
index c657d4f..f63a54b 100644
--- a/tests-clar/index/read_tree.c
+++ b/tests-clar/index/read_tree.c
@@ -24,9 +24,9 @@ void test_index_read_tree__read_write_involution(void)
 	cl_git_mkfile("./read_tree/abc/d", NULL);
 	cl_git_mkfile("./read_tree/abc_d", NULL);
 
-	cl_git_pass(git_index_add(index, "abc-d", 0));
-	cl_git_pass(git_index_add(index, "abc_d", 0));
-	cl_git_pass(git_index_add(index, "abc/d", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "abc-d"));
+	cl_git_pass(git_index_add_from_workdir(index, "abc_d"));
+	cl_git_pass(git_index_add_from_workdir(index, "abc/d"));
 
 	/* write-tree */
 	cl_git_pass(git_tree_create_fromindex(&expected, index));
diff --git a/tests-clar/index/rename.c b/tests-clar/index/rename.c
index eecd257..e16ec00 100644
--- a/tests-clar/index/rename.c
+++ b/tests-clar/index/rename.c
@@ -19,28 +19,28 @@ void test_index_rename__single_file(void)
 	cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
 
 	/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
-	cl_git_pass(git_index_add(index, "lame.name.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "lame.name.txt"));
 	cl_assert(git_index_entrycount(index) == 1);
 
 	cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));
 
 	position = git_index_find(index, "lame.name.txt");
 
-	entry = git_index_get(index, position);
+	entry = git_index_get_byindex(index, position);
 	cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
 
 	/* This removes the entry from the index, but not from the object database */
-	cl_git_pass(git_index_remove(index, position));
+	cl_git_pass(git_index_remove(index, "lame.name.txt", 0));
 	cl_assert(git_index_entrycount(index) == 0);
 
 	p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");
 
-	cl_git_pass(git_index_add(index, "fancy.name.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "fancy.name.txt"));
 	cl_assert(git_index_entrycount(index) == 1);
 
 	position = git_index_find(index, "fancy.name.txt");
 
-	entry = git_index_get(index, position);
+	entry = git_index_get_byindex(index, position);
 	cl_assert(git_oid_cmp(&expected, &entry->oid) == 0);
 
 	git_index_free(index);
diff --git a/tests-clar/index/reuc.c b/tests-clar/index/reuc.c
new file mode 100644
index 0000000..c7c3944
--- /dev/null
+++ b/tests-clar/index/reuc.c
@@ -0,0 +1,236 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+#define ONE_ANCESTOR_OID "478871385b9cd03908c5383acfd568bef023c6b3"
+#define ONE_OUR_OID "4458b8bc9e72b6c8755ae456f60e9844d0538d8c"
+#define ONE_THEIR_OID "8b72416545c7e761b64cecad4f1686eae4078aa8"
+
+#define TWO_ANCESTOR_OID "9d81f82fccc7dcd7de7a1ffead1815294c2e092c"
+#define TWO_OUR_OID "8f3c06cff9a83757cec40c80bc9bf31a2582bde9"
+#define TWO_THEIR_OID "887b153b165d32409c70163e0f734c090f12f673"
+
+// Fixture setup and teardown
+void test_index_reuc__initialize(void)
+{
+	repo = cl_git_sandbox_init("mergedrepo");
+	git_repository_index(&repo_index, repo);
+}
+
+void test_index_reuc__cleanup(void)
+{
+	git_index_free(repo_index);
+	cl_git_sandbox_cleanup();
+}
+
+void test_index_reuc__read_bypath(void)
+{
+	const git_index_reuc_entry *reuc;
+	git_oid oid;
+
+	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "two.txt"));
+
+	cl_assert(strcmp(reuc->path, "two.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+
+	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "one.txt"));
+
+	cl_assert(strcmp(reuc->path, "one.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, ONE_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, ONE_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__ignore_case(void)
+{
+	const git_index_reuc_entry *reuc;
+	git_oid oid;
+	int index_caps;
+
+	index_caps = git_index_caps(repo_index);
+
+	index_caps &= ~GIT_INDEXCAP_IGNORE_CASE;
+	cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+	cl_assert(!git_index_reuc_get_bypath(repo_index, "TWO.txt"));
+
+	index_caps |= GIT_INDEXCAP_IGNORE_CASE;
+	cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+	cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "TWO.txt"));
+
+	cl_assert(strcmp(reuc->path, "two.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__read_byindex(void)
+{
+	const git_index_reuc_entry *reuc;
+	git_oid oid;
+
+	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+	cl_assert(strcmp(reuc->path, "one.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, ONE_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, ONE_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, ONE_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
+
+	cl_assert(strcmp(reuc->path, "two.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__updates_existing(void)
+{
+	const git_index_reuc_entry *reuc;
+	git_oid ancestor_oid, our_oid, their_oid, oid;
+	int index_caps;
+
+	git_index_clear(repo_index);
+
+	index_caps = git_index_caps(repo_index);
+
+	index_caps |= GIT_INDEXCAP_IGNORE_CASE;
+	cl_git_pass(git_index_set_caps(repo_index, index_caps));
+
+	git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
+	git_oid_fromstr(&our_oid, TWO_OUR_OID);
+	git_oid_fromstr(&their_oid, TWO_THEIR_OID);
+
+	cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
+		0100644, &ancestor_oid,
+		0100644, &our_oid,
+		0100644, &their_oid));
+
+	cl_git_pass(git_index_reuc_add(repo_index, "TWO.txt",
+		0100644, &our_oid,
+		0100644, &their_oid,
+		0100644, &ancestor_oid));
+
+	cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));
+
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+	cl_assert(strcmp(reuc->path, "TWO.txt") == 0);
+	git_oid_fromstr(&oid, TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__remove(void)
+{
+	git_oid oid;
+	const git_index_reuc_entry *reuc;
+
+	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+	cl_git_pass(git_index_reuc_remove(repo_index, 0));
+	cl_git_fail(git_index_reuc_remove(repo_index, 1));
+	
+	cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index));
+
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+
+	cl_assert(strcmp(reuc->path, "two.txt") == 0);
+	cl_assert(reuc->mode[0] == 0100644);
+	cl_assert(reuc->mode[1] == 0100644);
+	cl_assert(reuc->mode[2] == 0100644);
+	git_oid_fromstr(&oid, TWO_ANCESTOR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_OUR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0);
+	git_oid_fromstr(&oid, TWO_THEIR_OID);
+	cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0);
+}
+
+void test_index_reuc__write(void)
+{
+	git_oid ancestor_oid, our_oid, their_oid;
+	const git_index_reuc_entry *reuc;
+
+	git_index_clear(repo_index);
+
+	/* Write out of order to ensure sorting is correct */
+	git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
+	git_oid_fromstr(&our_oid, TWO_OUR_OID);
+	git_oid_fromstr(&their_oid, TWO_THEIR_OID);
+
+	cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
+		0100644, &ancestor_oid,
+		0100644, &our_oid,
+		0100644, &their_oid));
+
+	git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID);
+	git_oid_fromstr(&our_oid, ONE_OUR_OID);
+	git_oid_fromstr(&their_oid, ONE_THEIR_OID);
+
+	cl_git_pass(git_index_reuc_add(repo_index, "one.txt",
+		0100644, &ancestor_oid,
+		0100644, &our_oid,
+		0100644, &their_oid));
+
+	cl_git_pass(git_index_write(repo_index));
+
+	cl_git_pass(git_index_read(repo_index));
+	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));
+
+	/* ensure sort order was round-tripped correct */
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
+	cl_assert(strcmp(reuc->path, "one.txt") == 0);
+	
+	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
+	cl_assert(strcmp(reuc->path, "two.txt") == 0);
+}
+
diff --git a/tests-clar/index/stage.c b/tests-clar/index/stage.c
new file mode 100644
index 0000000..ba6f1b8
--- /dev/null
+++ b/tests-clar/index/stage.c
@@ -0,0 +1,60 @@
+#include "clar_libgit2.h"
+#include "index.h"
+#include "git2/repository.h"
+
+static git_repository *repo;
+static git_index *repo_index;
+
+#define TEST_REPO_PATH "mergedrepo"
+#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
+
+// Fixture setup and teardown
+void test_index_stage__initialize(void)
+{
+	repo = cl_git_sandbox_init("mergedrepo");
+	git_repository_index(&repo_index, repo);
+}
+
+void test_index_stage__cleanup(void)
+{
+	git_index_free(repo_index);
+	cl_git_sandbox_cleanup();
+}
+
+
+void test_index_stage__add_always_adds_stage_0(void)
+{
+	int entry_idx;
+	git_index_entry *entry;
+
+    cl_git_mkfile("./mergedrepo/new-file.txt", "new-file\n");
+
+	cl_git_pass(git_index_add_from_workdir(repo_index, "new-file.txt"));
+
+	cl_assert((entry_idx = git_index_find(repo_index, "new-file.txt")) >= 0);
+	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+	cl_assert(git_index_entry_stage(entry) == 0);
+}
+
+void test_index_stage__find_gets_first_stage(void)
+{
+	int entry_idx;
+	git_index_entry *entry;
+
+	cl_assert((entry_idx = git_index_find(repo_index, "one.txt")) >= 0);
+	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+	cl_assert(git_index_entry_stage(entry) == 0);
+
+	cl_assert((entry_idx = git_index_find(repo_index, "two.txt")) >= 0);
+	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+	cl_assert(git_index_entry_stage(entry) == 0);
+
+	cl_assert((entry_idx = git_index_find(repo_index, "conflicts-one.txt")) >= 0);
+	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+	cl_assert(git_index_entry_stage(entry) == 1);
+
+	cl_assert((entry_idx = git_index_find(repo_index, "conflicts-two.txt")) >= 0);
+	cl_assert((entry = git_index_get_byindex(repo_index, entry_idx)) != NULL);
+	cl_assert(git_index_entry_stage(entry) == 1);
+}
+
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index a535d68..cf971e1 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -231,15 +231,19 @@ void test_index_tests__add(void)
    cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
 
    /* Add the new file to the index */
-   cl_git_pass(git_index_add(index, "test.txt", 0));
+   cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
 
    /* Wow... it worked! */
    cl_assert(git_index_entrycount(index) == 1);
-   entry = git_index_get(index, 0);
+   entry = git_index_get_byindex(index, 0);
 
    /* And the built-in hashing mechanism worked as expected */
    cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
 
+   /* Test access by path instead of index */
+   cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+   cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+
    git_index_free(index);
    git_repository_free(repo);
 }
diff --git a/tests-clar/object/commit/commitstagedfile.c b/tests-clar/object/commit/commitstagedfile.c
index 6b6c573..ac38acf 100644
--- a/tests-clar/object/commit/commitstagedfile.c
+++ b/tests-clar/object/commit/commitstagedfile.c
@@ -71,9 +71,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
 	 */
 	cl_git_mkfile("treebuilder/test.txt", "test\n");
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, "test.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "test.txt"));
 
-	entry = git_index_get(index, 0);
+	entry = git_index_get_byindex(index, 0);
 
 	cl_assert(git_oid_cmp(&expected_blob_oid, &entry->oid) == 0);
 
diff --git a/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG b/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG
new file mode 100644
index 0000000..1f7391f
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/COMMIT_EDITMSG
@@ -0,0 +1 @@
+master
diff --git a/tests-clar/resources/mergedrepo/.gitted/HEAD b/tests-clar/resources/mergedrepo/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD b/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD
new file mode 100644
index 0000000..a5bdf6e
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_HEAD
@@ -0,0 +1 @@
+e2809157a7766f272e4cfe26e61ef2678a5357ff
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE b/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_MODE
diff --git a/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG b/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG
new file mode 100644
index 0000000..7c4d1f5
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/MERGE_MSG
@@ -0,0 +1,5 @@
+Merge branch 'branch'
+
+Conflicts:
+	conflicts-one.txt
+	conflicts-two.txt
diff --git a/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD b/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD
new file mode 100644
index 0000000..13d4d67
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/ORIG_HEAD
@@ -0,0 +1 @@
+3a34580a35add43a4cf361e8e9a30060a905c876
diff --git a/tests-clar/resources/mergedrepo/.gitted/config b/tests-clar/resources/mergedrepo/.gitted/config
new file mode 100644
index 0000000..af10792
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/config
@@ -0,0 +1,6 @@
+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = false
+	logallrefupdates = true
+	ignorecase = true
diff --git a/tests-clar/resources/mergedrepo/.gitted/description b/tests-clar/resources/mergedrepo/.gitted/description
new file mode 100644
index 0000000..498b267
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests-clar/resources/mergedrepo/.gitted/index b/tests-clar/resources/mergedrepo/.gitted/index
new file mode 100644
index 0000000..3d29f78
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/index differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/info/exclude b/tests-clar/resources/mergedrepo/.gitted/info/exclude
new file mode 100644
index 0000000..a5196d1
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.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/mergedrepo/.gitted/logs/HEAD b/tests-clar/resources/mergedrepo/.gitted/logs/HEAD
new file mode 100644
index 0000000..a385da6
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/HEAD
@@ -0,0 +1,5 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500	commit (initial): initial
+9a05ccb4e0f948de03128e095f39dae6976751c5 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500	checkout: moving from master to branch
+9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500	commit: branch
+e2809157a7766f272e4cfe26e61ef2678a5357ff 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371873 -0500	checkout: moving from branch to master
+9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf361e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500	commit: master
diff --git a/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch
new file mode 100644
index 0000000..26a5e8d
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/branch
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500	branch: Created from HEAD
+9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500	commit: branch
diff --git a/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master
new file mode 100644
index 0000000..425f7bd
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/logs/refs/heads/master
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500	commit (initial): initial
+9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf361e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500	commit: master
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712 b/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712
new file mode 100644
index 0000000..9232f79
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/03/db1d37504ca0c4f7c26d7776b0e28bdea08712 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91 b/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91
new file mode 100644
index 0000000..3e124d9
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/17/0efc1023e0ed2390150bb4469c8456b63e8f91 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81 b/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81
new file mode 100644
index 0000000..7bb19c8
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/1f/85ca51b8e0aac893a621b61a9c2661d6aa6d81 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e b/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e
new file mode 100644
index 0000000..487bcff
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/22/0bd62631c8cf7a83ef39c6b94595f00517211e differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6 b/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6
new file mode 100644
index 0000000..2eb3954
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/32/d55d59265db86dd690f0a7fc563db43e2bc6a6 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534 b/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534
new file mode 100644
index 0000000..ebe83cc
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/38/e2d82b9065a237904af4b780b4d68da6950534 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876 b/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876
new file mode 100644
index 0000000..0d4095f
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/3a/34580a35add43a4cf361e8e9a30060a905c876
@@ -0,0 +1,2 @@
+xK
+1D]}Dx/O"F2oo<*ZoљuIhhrl"r	YT8'#vm0.¨.:.#+9R^nG~[=VjR"IjD۔7|N`
\ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c b/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c
new file mode 100644
index 0000000..33389c3
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/44/58b8bc9e72b6c8755ae456f60e9844d0538d8c differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3 b/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3
new file mode 100644
index 0000000..5361ea6
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/47/8871385b9cd03908c5383acfd568bef023c6b3 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da b/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da
new file mode 100644
index 0000000..a60da87
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/51/6bd85f78061e09ccc714561d7b504672cb52da differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad b/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad
new file mode 100644
index 0000000..85e84d7
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/53/c1d95a01f4514b162066fc98564500c96c46ad differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399 b/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399
new file mode 100644
index 0000000..b16b521
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/6a/ea5f295304c36144ad6e9247a291b7f8112399 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8 b/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8
new file mode 100644
index 0000000..7c4e85f
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/70/68e30a7f0090ae32db35dfa1e4189d8780fcb8 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4 b/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4
new file mode 100644
index 0000000..65173fc
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/75/938de1e367098b3e9a7b1ec3c4ac4548afffe4 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71 b/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71
new file mode 100644
index 0000000..162fa44
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/7b/26923aaf452b1977eb08617c59475fb3f74b71 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c b/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c
new file mode 100644
index 0000000..77a519f
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/84/af62840be1b1c47b778a8a249f3ff45155038c differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda b/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda
new file mode 100644
index 0000000..f624cd4
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/88/71f7a2ee3addfc4ba39fbd0783c8e738d04cda differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673 b/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673
new file mode 100644
index 0000000..096474c
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/88/7b153b165d32409c70163e0f734c090f12f673 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a b/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a
new file mode 100644
index 0000000..a413bc6
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/8a/ad34cc83733590e74b93d0f7cf00375e2a735a differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2 b/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2
new file mode 100644
index 0000000..3ac8f60
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/8b/3f43d2402825c200f835ca1762413e386fd0b2 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8 b/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8
new file mode 100644
index 0000000..589a5ae
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/8b/72416545c7e761b64cecad4f1686eae4078aa8 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9 b/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9
new file mode 100644
index 0000000..6503985
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/8f/3c06cff9a83757cec40c80bc9bf31a2582bde9 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50 b/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50
new file mode 100644
index 0000000..2eaa808
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/8f/fcc405925511824a2240a6d3686aa7f8c7ac50 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5 b/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5
new file mode 100644
index 0000000..7373a80
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5
@@ -0,0 +1 @@
+x
!Dm@c6q##Ay/	܁:#$ltH:闄*DXhV}
˷n[-K_;Z@JGԈbq3"go@I
\ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c b/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c
new file mode 100644
index 0000000..c5a651f
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/9d/81f82fccc7dcd7de7a1ffead1815294c2e092c differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d b/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d
new file mode 100644
index 0000000..3e14b5d
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/b7/cedb8ad4cbb22b6363f9578cbd749797f7ef0d differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51 b/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51
new file mode 100644
index 0000000..a641adc
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/d0/1885ea594926eae9ba5b54ad76692af5969f51 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff b/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff
new file mode 100644
index 0000000..fa86662
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff
@@ -0,0 +1,3 @@
+xK
+1D]t> xNq1(]{Pe
mٍ.S0[Dcd
+ŅbMԝCgd@>glX].$!0*zu})/E_<ڪO:WځrơqѤh@mt;;5uZyVo\M
\ No newline at end of file
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478 b/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478
new file mode 100644
index 0000000..c9841c6
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/e6/2cac5c88b9928f2695b934c70efa4285324478 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406 b/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406
new file mode 100644
index 0000000..cd587db
Binary files /dev/null and b/tests-clar/resources/mergedrepo/.gitted/objects/f7/2784290c151092abf04ce6b875068547f70406 differ
diff --git a/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch b/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch
new file mode 100644
index 0000000..a5bdf6e
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/refs/heads/branch
@@ -0,0 +1 @@
+e2809157a7766f272e4cfe26e61ef2678a5357ff
diff --git a/tests-clar/resources/mergedrepo/.gitted/refs/heads/master b/tests-clar/resources/mergedrepo/.gitted/refs/heads/master
new file mode 100644
index 0000000..13d4d67
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/.gitted/refs/heads/master
@@ -0,0 +1 @@
+3a34580a35add43a4cf361e8e9a30060a905c876
diff --git a/tests-clar/resources/mergedrepo/conflicts-one.txt b/tests-clar/resources/mergedrepo/conflicts-one.txt
new file mode 100644
index 0000000..8aad34c
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/conflicts-one.txt
@@ -0,0 +1,5 @@
+<<<<<<< HEAD
+This is most certainly a conflict!
+=======
+This is a conflict!!!
+>>>>>>> branch
diff --git a/tests-clar/resources/mergedrepo/conflicts-two.txt b/tests-clar/resources/mergedrepo/conflicts-two.txt
new file mode 100644
index 0000000..e62cac5
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/conflicts-two.txt
@@ -0,0 +1,5 @@
+<<<<<<< HEAD
+This is without question another conflict!
+=======
+This is another conflict!!!
+>>>>>>> branch
diff --git a/tests-clar/resources/mergedrepo/one.txt b/tests-clar/resources/mergedrepo/one.txt
new file mode 100644
index 0000000..75938de
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/one.txt
@@ -0,0 +1,10 @@
+This is file one!
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one.
+This is file one!
diff --git a/tests-clar/resources/mergedrepo/two.txt b/tests-clar/resources/mergedrepo/two.txt
new file mode 100644
index 0000000..7b26923
--- /dev/null
+++ b/tests-clar/resources/mergedrepo/two.txt
@@ -0,0 +1,12 @@
+This is file two!
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two.
+This is file two!
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
index 136a942..5bbc745 100644
--- a/tests-clar/stash/drop.c
+++ b/tests-clar/stash/drop.c
@@ -30,7 +30,7 @@ static void push_three_states(void)
 
 	cl_git_mkfile("stash/zero.txt", "content\n");
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, "zero.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "zero.txt"));
 	commit_staged_files(&oid, index, signature);
 
 	cl_git_mkfile("stash/one.txt", "content\n");
diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c
index 71b0b64..01acf67 100644
--- a/tests-clar/stash/save.c
+++ b/tests-clar/stash/save.c
@@ -246,8 +246,8 @@ void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
 	 * 'what' and 'who' are being committed.
 	 * 'when' remain untracked.
 	 */
-	git_index_add(index, "what", 0);
-	git_index_add(index, "who", 0);
+	git_index_add_from_workdir(index, "what");
+	git_index_add_from_workdir(index, "who");
 	cl_git_pass(git_index_write(index));
 	commit_staged_files(&commit_oid, index, signature);
 	git_index_free(index);
diff --git a/tests-clar/stash/stash_helpers.c b/tests-clar/stash/stash_helpers.c
index 35017ce..0e93ecf 100644
--- a/tests-clar/stash/stash_helpers.c
+++ b/tests-clar/stash/stash_helpers.c
@@ -45,10 +45,10 @@ void setup_stash(git_repository *repo, git_signature *signature)
 
 	cl_git_mkfile("stash/.gitignore", "*.ignore\n");
 
-	cl_git_pass(git_index_add(index, "what", 0));
-	cl_git_pass(git_index_add(index, "how", 0));
-	cl_git_pass(git_index_add(index, "who", 0));
-	cl_git_pass(git_index_add(index, ".gitignore", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "what"));
+	cl_git_pass(git_index_add_from_workdir(index, "how"));
+	cl_git_pass(git_index_add_from_workdir(index, "who"));
+	cl_git_pass(git_index_add_from_workdir(index, ".gitignore"));
 	cl_git_pass(git_index_write(index));
 
 	commit_staged_files(&commit_oid, index, signature);
@@ -57,8 +57,8 @@ void setup_stash(git_repository *repo, git_signature *signature)
 	cl_git_rewritefile("stash/how", "not so small and\n");	/* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
 	cl_git_rewritefile("stash/who", "funky world\n");		/* a0400d4954659306a976567af43125a0b1aa8595 */
 
-	cl_git_pass(git_index_add(index, "what", 0));
-	cl_git_pass(git_index_add(index, "how", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "what"));
+	cl_git_pass(git_index_add_from_workdir(index, "how"));
 	cl_git_pass(git_index_write(index));
 
 	cl_git_rewritefile("stash/what", "see you later\n");	/* bc99dc98b3eba0e9157e94769cd4d49cb49de449 */
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 4ff315f..116286f 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -438,7 +438,7 @@ void test_status_worktree__first_commit_in_progress(void)
 	cl_assert(result.status == GIT_STATUS_WT_NEW);
 
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, "testfile.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "testfile.txt"));
 	cl_git_pass(git_index_write(index));
 
 	memset(&result, 0, sizeof(result));
@@ -570,7 +570,7 @@ void test_status_worktree__bracket_in_filename(void)
 	/* add the file to the index */
 
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, FILE_WITH_BRACKET, 0));
+	cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_BRACKET));
 	cl_git_pass(git_index_write(index));
 
 	memset(&result, 0, sizeof(result));
@@ -648,7 +648,7 @@ void test_status_worktree__space_in_filename(void)
 	/* add the file to the index */
 
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, FILE_WITH_SPACE, 0));
+	cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_SPACE));
 	cl_git_pass(git_index_write(index));
 
 	memset(&result, 0, sizeof(result));
@@ -816,7 +816,7 @@ void test_status_worktree__new_staged_file_must_handle_crlf(void)
 	cl_git_mkfile("getting_started/testfile.txt", "content\r\n");	// Content with CRLF
 
 	cl_git_pass(git_repository_index(&index, repo));
-	cl_git_pass(git_index_add(index, "testfile.txt", 0));
+	cl_git_pass(git_index_add_from_workdir(index, "testfile.txt"));
 	cl_git_pass(git_index_write(index));
 
 	cl_git_pass(git_status_file(&status, repo, "testfile.txt"));
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 63073ce..eec028c 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -105,7 +105,7 @@ void test_submodule_status__ignore_none(void)
 		cl_git_pass(git_repository_index(&index, g_repo));
 		pos = git_index_find(index, "sm_changed_head");
 		cl_assert(pos >= 0);
-		cl_git_pass(git_index_remove(index, pos));
+		cl_git_pass(git_index_remove(index, "sm_changed_head", 0));
 		cl_git_pass(git_index_write(index));
 
 		git_index_free(index);