# # # add_file "tests/t_pivot_root.at" # content [d703b845e5a967d573b4744386581a5a7a43ffaf] # # patch "file_io.cc" # from [5a5151f72c1d0749834fe99ab0a2664fab90d5b2] # to [5c909c814c445b3b919552e3dda19971ebe26e85] # # patch "paths.cc" # from [7c27cc4b68ddf1b7e376ad6a662bce78d1312155] # to [adac07604037f266d4ddd7b5bfb104cac9bfeebf] # # patch "testsuite.at" # from [c8be08d87b48f90c833c326e708aaa06423b1b75] # to [8a981da4d2462e00f62a92ef193f42fab6a7127b] # # patch "work.cc" # from [ec826e134f977cb874c12554706aa3316c9a1ed8] # to [ba9464a90c0448961f157eb54702441c649812d3] # ============================================================ --- tests/t_pivot_root.at d703b845e5a967d573b4744386581a5a7a43ffaf +++ tests/t_pivot_root.at d703b845e5a967d573b4744386581a5a7a43ffaf @@ -0,0 +1,36 @@ +AT_SETUP([pivot_root]) +MONOTONE_SETUP + +# possible problems: +# -- the new root doesn't exist +# -- the new root has an MT in it +# -- the directory the old root is supposed to end up in doesn't exist +# -- the directory the old root is supposed to end up in is not a directory +# -- the directory the old root is supposed to end up in already +# contains something with the given name +# then make sure --execute puts things in the right place... + +AT_CHECK(mkdir workspace) +AT_CHECK(cd workspace/ && MONOTONE setup . -b testbranch, [], [ignore], [ignore]) + +AT_CHECK(mkdir workspace/dir1) +AT_CHECK(mkdir workspace/dir1/dir2) +AT_DATA(workspace/dir1/file1, [blah blah +]) +AT_CHECK(mkdir workspace/dir3) +AT_CHECK(mkdir workspace/dir3/MT) +AT_CHECK(cd workspace/ && MONOTONE add ., [], [ignore], [ignore]) + +AT_CHECK(cd workspace/ && MONOTONE commit -m foo, [], [ignore], [ignore]) + +AT_CHECK(cd workspace/ && MONOTONE pivot_root nosuchdir foo, [1], [ignore], [ignore]) +AT_CHECK(cd workspace/ && MONOTONE pivot_root dir3 old_root, [1], [ignore], [ignore]) +AT_CHECK(cd workspace/ && MONOTONE pivot_root dir1 nosuchdir/old_root, [1], [ignore], [ignore]) +AT_CHECK(cd workspace/ && MONOTONE pivot_root dir1 file1/old_root, [1], [ignore], [ignore]) +AT_CHECK(cd workspace/ && MONOTONE pivot_root dir1 dir2, [1], [ignore], [ignore]) + +AT_CHECK(cd workspace/ && MONOTONE ls changed, [], [], []) + +AT_CHECK(cd workspace/ && MONOTONE pivot_root --execute dir1 old_root, [], [ignore], [ignore]) + +AT_CLEANUP ============================================================ --- file_io.cc 5a5151f72c1d0749834fe99ab0a2664fab90d5b2 +++ file_io.cc 5c909c814c445b3b919552e3dda19971ebe26e85 @@ -354,8 +354,8 @@ files.clear(); dirs.clear(); fs::directory_iterator ei; - for(fs::directory_iterator di(path.as_external()); - di != ei; ++di) + for (fs::directory_iterator di(path.as_external()); + di != ei; ++di) { fs::path entry = *di; if (!fs::exists(entry) ============================================================ --- paths.cc 7c27cc4b68ddf1b7e376ad6a662bce78d1312155 +++ paths.cc adac07604037f266d4ddd7b5bfb104cac9bfeebf @@ -478,9 +478,9 @@ { I(!sp.empty()); // L(FL("dirname_basename('%s' [%d components],...)\n") % file_path(sp) % sp.size()); - split_path::const_iterator penultimate = sp.begin() + (sp.size()-1); - dirname = split_path(sp.begin(), penultimate); - basename = *penultimate; + dirname = sp; + dirname.pop_back(); + basename = sp.back(); if (dirname.empty()) { // L(FL("basename %d vs. null component %d\n") % basename % the_null_component); ============================================================ --- testsuite.at c8be08d87b48f90c833c326e708aaa06423b1b75 +++ testsuite.at 8a981da4d2462e00f62a92ef193f42fab6a7127b @@ -779,3 +779,4 @@ m4_include(tests/t_log_nofiles_merges.at) m4_include(tests/t_cvsimport_branch.at) m4_include(tests/t_log_to_file.at) +m4_include(tests/t_pivot_root.at) ============================================================ --- work.cc ec826e134f977cb874c12554706aa3316c9a1ed8 +++ work.cc ba9464a90c0448961f157eb54702441c649812d3 @@ -375,7 +375,7 @@ split_path current_path_to_put_old_sp, current_path_to_put_old_parent_sp; path_component basename; current_path_to_put_old.split(current_path_to_put_old_sp); - dirname_basename(current_path_to_put_old_sp, current_path_to_put_old_sp, basename); + dirname_basename(current_path_to_put_old_sp, current_path_to_put_old_parent_sp, basename); N(new_roster.has_node(current_path_to_put_old_parent_sp), F("directory '%s' is not versioned or does not exist") % file_path(current_path_to_put_old_parent_sp));