# # # add_dir "tests/automate_get_options" # # add_file "tests/automate_get_options/__driver__.lua" # content [441807940397c9106b117ba8ce6caf273e0b7f1c] # # patch "cmd_automate.cc" # from [aa644eac27e978e1f51203db320206272a98f8a1] # to [90a3539d4bc74610db7f415c5f4a3d6254cb97ed] # # patch "monotone.texi" # from [8890aec73293d365d12251bbb7691b62091e44d5] # to [5e71a0221f6dded67c20a89fcd3f7518dc85df00] # # patch "tests/automate_cert/__driver__.lua" # from [21c1631cb67da926ed7fdc1995db5dae2130bb05] # to [a7f8e71581aa02eb61dcde8d6030eaa2a91aca8f] # # patch "tests/automate_heads/__driver__.lua" # from [7b00f82a3172485381d6845352d14c1eacc29b3e] # to [3e517ef05655a049ac5c0c121942e1e66cc1e209] # # patch "tests/automate_keys/__driver__.lua" # from [42ad71325d1df9437aa6623996367bbeaa28fe93] # to [31fa511454527e8a340fa29dbcb7a1e4c8cc8cda] # # patch "tests/automate_show_conflicts_defaults/__driver__.lua" # from [bb8f4e10d941d1580cb84f70d16c0241b39ec6b1] # to [e89d6a7bdb7752205b89c8ac32d112030b254e48] # ============================================================ --- tests/automate_get_options/__driver__.lua 441807940397c9106b117ba8ce6caf273e0b7f1c +++ tests/automate_get_options/__driver__.lua 441807940397c9106b117ba8ce6caf273e0b7f1c @@ -0,0 +1,20 @@ + +mtn_setup() + +-- We don't check options with paths in them; on Windows, sometimes +-- the paths have '\' for directory separators, sometimes '/', and we +-- don't have a way to predict which or fix them. +check(mtn("automate", "get_option", "branch"), 0, true, false) +canonicalize("stdout") +check("testbranch\n" == readfile("stdout")) + +check(mtn("automate", "get_option", "key"), 0, true, false) +canonicalize("stdout") +check("address@hidden" == readfile("stdout")) + +-- Ensure that 'get_options' gets the workspace options even when run via stdio +check(mtn_ws_opts("automate", "stdio"), 0, true, false, "l10:get_option6:branche") +canonicalize("stdout") +check("0:0:l:11:testbranch\n" == readfile("stdout")) + +-- end of file ============================================================ --- cmd_automate.cc aa644eac27e978e1f51203db320206272a98f8a1 +++ cmd_automate.cc 90a3539d4bc74610db7f415c5f4a3d6254cb97ed @@ -18,6 +18,7 @@ #include "lua.hh" #include "lua_hooks.hh" #include "database.hh" +#include "work.hh" using std::istream; using std::make_pair; @@ -40,6 +41,10 @@ namespace commands { string const & desc, options::options_type const & opts) : command(name, "", CMD_REF(automate), false, false, params, abstract, + // We set use_workspace_options true, because all automate + // commands need a database, and they expect to get the database + // name from the workspace options, even if they don't need a + // workspace for anything else. desc, true, opts, false) { } @@ -399,6 +404,16 @@ CMD_AUTOMATE(stdio, "", automate const * acmd = reinterpret_cast< automate const * >(cmd); opts = options::opts::globals() | acmd->opts(); + + if (cmd->use_workspace_options()) + { + // Re-read the ws options file, rather than just copying + // the options from the previous apts.opts object, because + // the file may have changed due to user activity. + workspace::check_ws_format(); + workspace::get_ws_options(app.opts); + } + opts.instantiate(&app.opts).from_key_value_pairs(params); acmd->exec_from_automate(app, id, args, os); } ============================================================ --- monotone.texi 8890aec73293d365d12251bbb7691b62091e44d5 +++ monotone.texi 5e71a0221f6dded67c20a89fcd3f7518dc85df00 @@ -8528,7 +8528,7 @@ @section Automation @end table address@hidden mtn automate show_conflicts address@hidden right_rev}] address@hidden mtn automate show_conflicts address@hidden BRANCH}] address@hidden right_rev}] @table @strong @item Arguments: @@ -8536,7 +8536,9 @@ @section Automation Optional left and right revision ids. If no revs are given, they default to the first two heads that would -be chosen by the @command{merge} command. +be chosen by the @command{merge} command for the current branch. If no +workspace is present, the branch may be given by the @var{--branch} +option. @item Added in: ============================================================ --- tests/automate_cert/__driver__.lua 21c1631cb67da926ed7fdc1995db5dae2130bb05 +++ tests/automate_cert/__driver__.lua a7f8e71581aa02eb61dcde8d6030eaa2a91aca8f @@ -18,6 +18,11 @@ check(samefile("expected", "stdout")) canonicalize("stdout") check(samefile("expected", "stdout")) +-- check that 'cert' gets keydir from workspace options when run via stdio +check(mtn_ws_opts("automate", "stdio"), 0, true, true, "l4:cert40:" .. base .. "9:testcert23:fooe") +check("0:0:l:0:" == readfile("stdout")) +check(samefile("empty", "stderr")) + -- check edge cases: -- wrong number of arguments: check(mtn("automate", "cert", base, "asdf"), 1, false, false) ============================================================ --- tests/automate_heads/__driver__.lua 7b00f82a3172485381d6845352d14c1eacc29b3e +++ tests/automate_heads/__driver__.lua 3e517ef05655a049ac5c0c121942e1e66cc1e209 @@ -25,3 +25,11 @@ check(samefile("empty", "stdout")) writefile("empty") check(samefile("empty", "stdout")) +-- In mtn 0.40 and earlier, this was broken, because automate stdio +-- did not re-read the workspace options for each command, so the +-- branch was null. +check(mtn("automate", "stdio"), 0, true, false, "l5:headse") +canonicalize("stdout") +check(("0:0:l:164:" .. readfile("wanted_heads")) == readfile("stdout")) + +-- end of file ============================================================ --- tests/automate_keys/__driver__.lua 42ad71325d1df9437aa6623996367bbeaa28fe93 +++ tests/automate_keys/__driver__.lua 31fa511454527e8a340fa29dbcb7a1e4c8cc8cda @@ -1,41 +1,56 @@ check(mtn("ci", "-m", "foobar"), 0, fals mtn_setup() addfile("testfile", "foo bar") check(mtn("ci", "-m", "foobar"), 0, false, false) -remove("_MTN/options") -check(nodb_mtn("genkey", "address@hidden"), + +-- Run some commands outside a workspace so they don't get the db from +-- the workspace options. +outside_ws_dir = make_temp_dir() + +check(indir(outside_ws_dir, nodb_mtn("genkey", "address@hidden")), 0, false, false, string.rep("address@hidden", 2)) -remove("_MTN/options") + check(mtn("genkey", "address@hidden"), 0, false, false, string.rep("address@hidden", 2)) -remove("_MTN/options") -check(nodb_mtn("dropkey", "address@hidden"), 0, false, false) +check(indir(outside_ws_dir, nodb_mtn("dropkey", "address@hidden")), 0, false, false) + -- we now have address@hidden in the keystore, address@hidden in both keystore -- and database, and address@hidden in only the database -check(mtn("automate", "keys"), 0, true, false) -parsed = parse_basic_io(readfile("stdout")) -locs = {} -for _,line in pairs(parsed) do - if line.name == "name" then - key = line.values[1] - locs[key] = {db = false, ks = false, pub = false, priv = false} - end - if string.find(line.name, "location") then - for _,v in pairs(line.values) do - if v == "keystore" then locs[key].ks = true end - if v == "database" then locs[key].db = true end +function check_keys(dat) + parsed = parse_basic_io(dat) + locs = {} + for _,line in pairs(parsed) do + if line.name == "name" then + key = line.values[1] + locs[key] = {db = false, ks = false, pub = false, priv = false} end + if string.find(line.name, "location") then + for _,v in pairs(line.values) do + if v == "keystore" then locs[key].ks = true end + if v == "database" then locs[key].db = true end + end + end + if string.find(line.name, "private") then locs[key].priv = true end + if string.find(line.name, "public") then locs[key].pub = true end end - if string.find(line.name, "private") then locs[key].priv = true end - if string.find(line.name, "public") then locs[key].pub = true end + check(locs["address@hidden"].db == false) + check(locs["address@hidden"].ks == true) + check(locs["address@hidden"].priv == false) + check(locs["address@hidden"].pub == true) + check(locs["address@hidden"].db == true) + check(locs["address@hidden"].ks == true) + check(locs["address@hidden"].pub == true) + check(locs["address@hidden"].priv == true) end + +check(mtn("automate", "keys"), 0, true, false) +check_keys(readfile("stdout")) + +-- Ensure that 'keys' gets the keydir from workspace options even when +-- run via stdio +check(mtn_ws_opts("automate", "stdio"), 0, true, false, "l4:keyse") +check_keys(string.sub (readfile("stdout"), 12)) + +-- end of file -check(locs["address@hidden"].db == false) -check(locs["address@hidden"].ks == true) -check(locs["address@hidden"].priv == false) -check(locs["address@hidden"].pub == true) -check(locs["address@hidden"].db == true) -check(locs["address@hidden"].ks == true) -check(locs["address@hidden"].pub == true) -check(locs["address@hidden"].priv == true) ============================================================ --- tests/automate_show_conflicts_defaults/__driver__.lua bb8f4e10d941d1580cb84f70d16c0241b39ec6b1 +++ tests/automate_show_conflicts_defaults/__driver__.lua e89d6a7bdb7752205b89c8ac32d112030b254e48 @@ -50,8 +50,17 @@ check_basic_io_line (3, parsed[3], "ance check_basic_io_line (2, parsed[2], "right", chuck_1) check_basic_io_line (3, parsed[3], "ancestor", base_2) +-- In mtn 0.40 and earlier, this was broken, because automate stdio +-- did not re-read the workspace options for each command, so the +-- branch was null. +check(mtn("automate", "stdio"), 0, true, false, "l14:show_conflictse") +parsed = parse_basic_io(string.sub (readfile("stdout"), 11)) +check_basic_io_line (1, parsed[1], "left", beth_1) +check_basic_io_line (2, parsed[2], "right", chuck_1) +check_basic_io_line (3, parsed[3], "ancestor", base_2) + -- Check that 'automate show_conflicts' works outside workspace when options are specified -non_ws_dir = make_temp_dir() +non_ws_dir = make_temp_dir() check(indir(non_ws_dir, mtn_outside_ws("automate", "show_conflicts", "--branch=testbranch")), 0, true, false) parsed = parse_basic_io(readfile("stdout"))