# # # add_dir "tests/keep_valid_workspace_options_on_error" # # add_file "tests/keep_valid_workspace_options_on_error/__driver__.lua" # content [d5c4ce1afbb2b0124005b87231f0423468391b82] # # patch "cmd_automate.cc" # from [eaa948261c63f4bf76d6e8c646e8ec7361333474] # to [d3f3f46e6b6830b5d8c9b9f68f1d573dfad59126] # # patch "monotone.cc" # from [d6ffaa534444ebd7fa7845054fc3825a5d6f00d4] # to [a925c994fd30f1efa53648052c8b6e91d63169fd] # # patch "network/automate_session.cc" # from [6a5a30794cca1274cee04eeb4d672fc4c8e4602d] # to [97588a34b995e3e7886345f443bd0fa70d6053cb] # # patch "work.cc" # from [dde5e4d1352d7b6e34823b600930ddcb791a9796] # to [28266a7fbb698d94c998047e52842b220b37756d] # # patch "work.hh" # from [f57aad376673bbda8271fcfd2d92e97241f05700] # to [021031510460f3cdc3762460937d94b575f04154] # ============================================================ --- tests/keep_valid_workspace_options_on_error/__driver__.lua d5c4ce1afbb2b0124005b87231f0423468391b82 +++ tests/keep_valid_workspace_options_on_error/__driver__.lua d5c4ce1afbb2b0124005b87231f0423468391b82 @@ -0,0 +1,22 @@ + +mtn_setup() + +addfile("foo", "bar") +commit() + +check(mtn_ws_opts("status"), 0, false, false) + +check(mtn("db", "init", "-d", "bar.mtn"), 0, false, false) +check(mtn_ws_opts("status"), 0, false, false) + +check(mtn_ws_opts("status", "-d", "bar.mtn"), 1, false, true) +check(qgrep("did you specify the wrong database?", "stderr")) + +check(mtn_ws_opts("status"), 0, false, false) + + +addfile("bar", "foo") +check(mtn_ws_opts("commit", "-m", "foo", "-b", "new-branch"), 0, false, false) + +check(qgrep("new-branch", "_MTN/options")) + ============================================================ --- cmd_automate.cc eaa948261c63f4bf76d6e8c646e8ec7361333474 +++ cmd_automate.cc d3f3f46e6b6830b5d8c9b9f68f1d573dfad59126 @@ -320,16 +320,16 @@ CMD_AUTOMATE_NO_STDIO(stdio, "", try { + // as soon as a command requires a workspace, this is set to true + workspace::used = false; + acmd->exec_from_automate(app, id, args, os); os.end_cmd(0); // usually, if a command succeeds, any of its workspace-relevant // options are saved back to _MTN/options, this shouldn't be // any different here - if (workspace::found) - { - workspace::set_options(app.opts); - } + workspace::maybe_set_options(app.opts); // restore app.opts app.opts = original_opts; @@ -468,15 +468,16 @@ LUAEXT(mtn_automate, ) commands::automate const * acmd = dynamic_cast< commands::automate const * >(cmd); I(acmd); + + // as soon as a command requires a workspace, this is set to true + workspace::used = false; + acmd->exec(*app_p, id, app_p->opts.args, os); // usually, if a command succeeds, any of its workspace-relevant // options are saved back to _MTN/options, this shouldn't be // any different here - if (workspace::found) - { - workspace::set_options(app_p->opts); - } + workspace::maybe_set_options(app_p->opts); // allow further calls app_p->mtn_automate_allowed = true; ============================================================ --- monotone.cc d6ffaa534444ebd7fa7845054fc3825a5d6f00d4 +++ monotone.cc a925c994fd30f1efa53648052c8b6e91d63169fd @@ -282,12 +282,12 @@ cpp_main(int argc, char ** argv) throw usage(commands::command_id()); + // as soon as a command requires a workspace, this is set to true + workspace::used = false; + commands::process(app, cmd, app.opts.args); - if (workspace::found) - { - workspace::set_options(app.opts); - } + workspace::maybe_set_options(app.opts); // The command will raise any problems itself through // exceptions. If we reach this point, it is because it ============================================================ --- network/automate_session.cc 6a5a30794cca1274cee04eeb4d672fc4c8e4602d +++ network/automate_session.cc 97588a34b995e3e7886345f443bd0fa70d6053cb @@ -253,15 +253,15 @@ bool automate_session::do_work(transacti { try { + // as soon as a command requires a workspace, this is set to true + workspace::used = false; + acmd->exec_from_automate(app, id, args, oss); // usually, if a command succeeds, any of its workspace-relevant // options are saved back to _MTN/options, this shouldn't be // any different here - if (workspace::found) - { - workspace::set_options(app.opts); - } + workspace::maybe_set_options(app.opts); // restore app.opts app.opts = original_opts; ============================================================ --- work.cc dde5e4d1352d7b6e34823b600930ddcb791a9796 +++ work.cc 28266a7fbb698d94c998047e52842b220b37756d @@ -117,6 +117,7 @@ bool workspace::found; } bool workspace::found; +bool workspace::used; bool workspace::branch_is_sticky; void @@ -124,6 +125,7 @@ workspace::require_workspace() { E(workspace::found, origin::user, F("workspace required but not found")); + workspace::used = true; } void @@ -131,6 +133,7 @@ workspace::require_workspace(i18n_format { E(workspace::found, origin::user, F("workspace required but not found\n%s") % explanation.str()); + workspace::used = true; } void @@ -545,6 +548,13 @@ workspace::get_database_option(system_pa workspace_key, workspace_keydir); } +void +workspace::maybe_set_options(options const & opts) +{ + if (workspace::found && workspace::used) + set_options(opts, false); +} + // This function should usually be called at the (successful) // execution of a function, because we don't do many checks here, f.e. // if this is a valid sqlite file and if it contains the correct identifier, ============================================================ --- work.hh f57aad376673bbda8271fcfd2d92e97241f05700 +++ work.hh 021031510460f3cdc3762460937d94b575f04154 @@ -93,6 +93,9 @@ struct workspace // function (find_and_go_to_workspace) which cannot presently be moved // from paths.cc. static bool found; + // This is set to true when a workspace object was created and used + // for a particular command + static bool used; private: // This is used by get_options and set_options. The branch option is set @@ -231,6 +234,7 @@ public: static void get_database_option(system_path const & workspace_root, system_path & database_option); static void set_options(options const & opts, bool branch_is_sticky = false); + static void maybe_set_options(options const & opts); static void print_option(utf8 const & opt, std::ostream & output); // the "bisect" infromation file is a file that records current status