# # # add_dir "tests/undrop" # # add_file "tests/undrop/__driver__.lua" # content [b0a16a0eefcc21e57e979bba3d2f9415986fc7a8] # # patch "cmd_ws_commit.cc" # from [10d33763a838c34d36cdacf987678905f77762be] # to [2961dae76ba27d65381b9d863c5f50a27216ad16] # ============================================================ --- tests/undrop/__driver__.lua b0a16a0eefcc21e57e979bba3d2f9415986fc7a8 +++ tests/undrop/__driver__.lua b0a16a0eefcc21e57e979bba3d2f9415986fc7a8 @@ -0,0 +1,43 @@ +-- Test 'undrop' command + +mtn_setup() + +addfile("changed", "base") +commit() + +-- With no changes before 'drop', 'undrop' is just 'revert' +check(mtn("drop", "changed"), 0, false, false) +check(mtn("undrop", "changed"), 0, false, false) +check(readfile("changed")=="base") + +check(mtn("status"), 0, true, false) +check(qgrep("no changes", "stdout")) + +-- With changes before 'drop', 'undrop' is like 'revert --bookkeeponly' +writefile("changed", "modified") +check(mtn("drop", "changed"), 0, false, true) +check(qgrep("file changed changed - it will be dropped but not deleted", "stderr")) +check(mtn("undrop", "changed"), 0, false, false) +check(readfile("changed")=="modified") +check(mtn("status"), 0, true, false) +check(qgrep("patched changed", "stdout")) + +-- one changed, one unchanged file +addfile("unchanged", "base") +writefile("changed", "base") +commit() + +writefile("changed", "modified") +check(mtn("drop", "changed", "unchanged"), 0, false, true) +check(qgrep("file changed changed - it will be dropped but not deleted", "stderr")) +check(qgrep("dropping unchanged from workspace", "stderr")) +check(mtn("undrop", "changed", "unchanged"), 0, false, false) +check(readfile("changed")=="modified") +check(readfile("unchanged")=="base") +check(mtn("status"), 0, true, false) +check(qgrep("patched changed", "stdout")) +check(not qgrep("patched unchanged", "stdout")) + +-- FIXME: test recursive, errors + +-- end of file ============================================================ --- cmd_ws_commit.cc 10d33763a838c34d36cdacf987678905f77762be +++ cmd_ws_commit.cc 2961dae76ba27d65381b9d863c5f50a27216ad16 @@ -1,3 +1,4 @@ +// Copyright (C) 2010 Stephen Leake // Copyright (C) 2002 Graydon Hoare // // This program is made available under the GNU GPL version 2.0 or @@ -193,11 +194,10 @@ get_log_message_interactively(lua_hooks system_to_utf8(log_message_external, log_message); } -CMD(revert, "revert", "", CMD_REF(workspace), N_("[PATH]..."), - N_("Reverts files and/or directories"), - N_("In order to revert the entire workspace, specify \".\" as the " - "file name."), - options::opts::depth | options::opts::exclude | options::opts::missing) +void +revert(app_state & app, + args_vector const & args, + bool undrop) { roster_t old_roster, new_roster; cset preserved; @@ -301,7 +301,7 @@ CMD(revert, "revert", "", CMD_REF(worksp { file_t f = downcast_to_file_t(node); - bool changed = true; + bool revert = true; if (file_exists(path)) { @@ -311,11 +311,15 @@ CMD(revert, "revert", "", CMD_REF(worksp if (ident == f->content) { L(FL("skipping unchanged %s") % path); - changed = false;; + revert = false; } + else + { + revert = not undrop; + } } - if (changed) + if (revert) { P(F("reverting %s") % path); L(FL("reverting %s to [%s]") % path @@ -375,6 +379,24 @@ CMD(revert, "revert", "", CMD_REF(worksp work.maybe_update_inodeprints(db); } +CMD(revert, "revert", "", CMD_REF(workspace), N_("[PATH]..."), + N_("Reverts files and/or directories"), + N_("In order to revert the entire workspace, specify \".\" as the " + "file name."), + options::opts::depth | options::opts::exclude | options::opts::missing) +{ + revert(app, args, false); +} + +CMD(undrop, "undrop", "", CMD_REF(workspace), N_("[PATH]..."), + N_("Reverses a mistaken 'drop'"), + N_("If the file was deleted from the workspace, this is the same as 'revert'. " + "Otherwise, it just removes the 'drop' from the manifest."), + options::opts::recursive) +{ + revert(app, args, true); +} + CMD(disapprove, "disapprove", "", CMD_REF(review), N_("REVISION"), N_("Disapproves a particular revision"), "",