The unified diff between revisions [8846a6b8..] and [ebdccab0..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'cset.cc'

#
#
# patch "cset.cc"
#  from [ac5f2a4848a4c5661496ec4f5af706de1fb6a454]
#    to [5fdac8f01ad19e4a427e40aa4245026b534422f7]
#
============================================================
--- cset.cc	ac5f2a4848a4c5661496ec4f5af706de1fb6a454
+++ cset.cc	5fdac8f01ad19e4a427e40aa4245026b534422f7
@@ -225,6 +225,8 @@ cset::apply_to(editable_tree & t) const
   for (map<pair<split_path, attr_key>, attr_value>::const_iterator i = attrs_set.begin();
        i != attrs_set.end(); ++i)
     t.set_attr(i->first.first, i->first.second, i->second);
+
+  t.commit();
 }

 ////////////////////////////////////////////////////////////////////
@@ -1070,56 +1072,76 @@ invalid_csets_test()
     BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
   }
   {
-    L(FL("TEST: can't rename root (for now)"));
+    L(FL("TEST: can't delete non-empty directory"));
     setup_roster(r, f1, nis);
     cset cs; MM(cs);
-    split_path sp1, sp2;
-    cs.dirs_added.insert(root);
-    cs.nodes_renamed.insert(std::make_pair(root, baz));
+    cs.nodes_deleted.insert(foo);
     BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
   }
   {
-    L(FL("TEST: can't delete non-empty directory"));
-    setup_roster(r, f1, nis);
+    L(FL("TEST: attach node with no root directory present"));
+    // for this test, make sure original roster has no contents
+    r = roster_t();
     cset cs; MM(cs);
-    cs.nodes_deleted.insert(foo);
+    split_path sp;
+    file_path_internal("blah/blah/blah").split(sp);
+    cs.dirs_added.insert(sp);
     BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
   }
   {
-    L(FL("TEST: can't delete root"));
-    // for this test, make sure root has no contents
-    r = roster_t();
+    L(FL("TEST: can't move a directory underneath itself"));
+    setup_roster(r, f1, nis);
     cset cs; MM(cs);
-    cs.nodes_deleted.insert(root);
+    split_path foo_blah;
+    file_path_internal("foo/blah").split(foo_blah);
+    cs.nodes_renamed.insert(std::make_pair(foo, foo_blah));
     BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
   }
+}
+
+void
+root_dir_test()
+{
+  temp_node_id_source nis;
+  roster_t r;
+  MM(r);
+  editable_roster_base tree(r, nis);
+
+  file_id f1(std::string("0000000000000000000000000000000000000001"));
+
+  split_path root, baz;
+  file_path().split(root);
+  file_path_internal("baz").split(baz);
+
   {
-    L(FL("TEST: can't delete and replace root"));
-    // for this test, make sure root has no contents
-    r = roster_t();
+    L(FL("TEST: can rename root"));
+    setup_roster(r, f1, nis);
     cset cs; MM(cs);
-    cs.nodes_deleted.insert(root);
+    split_path sp1, sp2;
     cs.dirs_added.insert(root);
-    BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
+    cs.nodes_renamed.insert(std::make_pair(root, baz));
+    cs.apply_to(tree);
+    r.check_sane(true);
   }
   {
-    L(FL("TEST: attach node with no root directory present"));
+    L(FL("TEST: can delete root (but it makes us insane)"));
     // for this test, make sure root has no contents
     r = roster_t();
+    r.attach_node(r.create_dir_node(nis), root);
     cset cs; MM(cs);
-    split_path sp;
-    file_path_internal("blah/blah/blah").split(sp);
-    cs.dirs_added.insert(sp);
-    BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
+    cs.nodes_deleted.insert(root);
+    cs.apply_to(tree);
+    BOOST_CHECK_THROW(r.check_sane(true), std::logic_error);
   }
   {
-    L(FL("TEST: can't move a directory underneath itself"));
-    setup_roster(r, f1, nis);
+    L(FL("TEST: can delete and replace root"));
+    r = roster_t();
+    r.attach_node(r.create_dir_node(nis), root);
     cset cs; MM(cs);
-    split_path foo_blah;
-    file_path_internal("foo/blah").split(foo_blah);
-    cs.nodes_renamed.insert(std::make_pair(foo, foo_blah));
-    BOOST_CHECK_THROW(cs.apply_to(tree), std::logic_error);
+    cs.nodes_deleted.insert(root);
+    cs.dirs_added.insert(root);
+    cs.apply_to(tree);
+    r.check_sane(true);
   }
 }

@@ -1130,6 +1152,7 @@ add_cset_tests(test_suite * suite)
   suite->add(BOOST_TEST_CASE(&basic_csets_test));
   suite->add(BOOST_TEST_CASE(&invalid_csets_test));
   suite->add(BOOST_TEST_CASE(&cset_written_test));
+  suite->add(BOOST_TEST_CASE(&root_dir_test));
 }

 #endif // BUILD_UNIT_TESTS