# # # add_dir "tests/automate_update" # # add_file "tests/automate_update/__driver__.lua" # content [737b9713cc9fafa0c9ec535636a9adcea973746b] # # patch "cmd_merging.cc" # from [0bef934b86c12babe6845d04b5e9fbfcf9114182] # to [1b12d445f9a5798743a7a1ff182ab5f5b1449a12] # ============================================================ --- tests/automate_update/__driver__.lua 737b9713cc9fafa0c9ec535636a9adcea973746b +++ tests/automate_update/__driver__.lua 737b9713cc9fafa0c9ec535636a9adcea973746b @@ -0,0 +1,41 @@ +-- Test 'automate update' +include("/common/automate_stdio.lua") + +mtn_setup() + +---------- +-- create a basic file history; add some files, then operate on +-- each of them in some way. + +addfile("dropped", "dropped") +addfile("original", "original") +addfile("unchanged", "unchanged") +addfile("patched", "patched") +commit() +rev1 = base_revision() + +addfile("added", "added") + +writefile("patched", "something has changed") + +check(mtn("rename", "original", "renamed"), 0, false, false) +check(mtn("drop", "dropped"), 0, false, false) +commit() +rev2 = base_revision() + +revert_to(rev1) + +check(mtn("automate", "update"), 0, false, true) +check(qgrep("mtn: updated to base revision", "stderr")) + +revert_to(rev1) + +progress = run_stdio("l6:updatee", 0, 0, 'p') +check(string.find(progress[9], "updated to base revision") ~= nil) + +-- Command error cases + +-- no arguments allowed +run_stdio("l6:update3:fooe", 2) + +-- end of file ============================================================ --- cmd_merging.cc 0bef934b86c12babe6845d04b5e9fbfcf9114182 +++ cmd_merging.cc 1b12d445f9a5798743a7a1ff182ab5f5b1449a12 @@ -1,5 +1,5 @@ // Copyright (C) 2002 Graydon Hoare -// 2008 Stephen Leake +// 2008, 2010 Stephen Leake // // This program is made available under the GNU GPL version 2.0 or // greater. See the accompanying file COPYING for details. @@ -175,21 +175,9 @@ pick_branch_for_update(options & opts, d return switched_branch; } -CMD(update, "update", "", CMD_REF(workspace), "", - N_("Updates the workspace"), - N_("This command modifies your workspace to be based off of a " - "different revision, preserving uncommitted changes as it does so. " - "If a revision is given, update the workspace to that revision. " - "If not, update the workspace to the head of the branch."), - options::opts::branch | options::opts::revision | - options::opts::move_conflicting_paths) +static void update (app_state & app, + args_vector const & args) { - if (!args.empty()) - throw usage(execid); - - if (app.opts.revision_selectors.size() > 1) - throw usage(execid); - database db(app); workspace work(app); project_t project(db); @@ -349,6 +337,39 @@ CMD(update, "update", "", CMD_REF(worksp P(F("updated to base revision %s") % chosen_rid); } +CMD(update, "update", "", CMD_REF(workspace), "", + N_("Updates the workspace"), + N_("This command modifies your workspace to be based off of a " + "different revision, preserving uncommitted changes as it does so. " + "If a revision is given, update the workspace to that revision. " + "If not, update the workspace to the head of the branch."), + options::opts::branch | options::opts::revision | + options::opts::move_conflicting_paths) +{ + if (!args.empty()) + throw usage(execid); + + if (app.opts.revision_selectors.size() > 1) + throw usage(execid); + + update (app, args); +} + +CMD_AUTOMATE(update, "", + N_("Updates the workspace"), + "", + options::opts::branch | options::opts::revision | + options::opts::move_conflicting_paths) +{ + E(args.empty(), origin::user, + F("update takes no command arguments")); + + E(app.opts.revision_selectors.size() <= 1, origin::user, + F("at most one revision selector may be specified")); + + update (app, args); +} + // Subroutine of CMD(merge) and CMD(explicit_merge). Merge LEFT with RIGHT, // placing results onto BRANCH. Note that interactive_merge_and_store may // bomb out, and therefore so may this.