# # # add_dir "tests/sync_use_ws_opts" # # add_file "tests/sync_use_ws_opts/__driver__.lua" # content [900a68a87633809becb988b49dc9bcbcb7b6437a] # # patch "cmd_netsync.cc" # from [3fc803802fa21cc1e8e35faa705c749fa284c841] # to [a4cc78ff8b6ca44b17c1f1e6514a5e1e9984f598] # # patch "lua-testsuite.lua" # from [d2db92ea969f6b5a4a7cd2d6a0dc6c528b41bbfa] # to [3c0e59374e0318967367a44c32f179fd9e3d63fb] # # patch "tests/commit_use_workspace_keydir/__driver__.lua" # from [3b080116b803ded67686ffc6b16d21920156d249] # to [8498a70d3c7d9d7c5c0e93ef159c97fbdb4484d4] # # patch "tests/common/netsync.lua" # from [a33cf9951874259a390ad9ac0d9348893de4bac3] # to [3e28b68bf122aefa0f55f5d3dfb80338f55bba2b] # ============================================================ --- tests/sync_use_ws_opts/__driver__.lua 900a68a87633809becb988b49dc9bcbcb7b6437a +++ tests/sync_use_ws_opts/__driver__.lua 900a68a87633809becb988b49dc9bcbcb7b6437a @@ -0,0 +1,37 @@ +-- Test that sync uses _MTN/options properly +-- It ignored 'keydir' in 0.39, and did not set 'key' in development for 0.40 + +include("/common/netsync.lua") + +-- 'mtn_setup' sets 'key' in _MTN/options; we don't want that. +check(getstd("test_keys")) +check(getstd("test_hooks.lua")) +check(getstd("min_hooks.lua")) + +check(mtn("db", "init"), 0, false, false) +check(mtn("read", "test_keys"), 0, false, false) +remove("test_keys") + +check(mtn_ws_opts("--db=test.db", "--keydir=keys", "setup", "--branch=testbranch", "."), 0, false, false) + +netsync.setup() +srv = netsync.start(2) + +-- This should find the single key in the keydir specified by +-- _MTN/options +check(mtn_ws_opts("sync", "--set-default", srv.address, "testbranch"), 0, false, false) + +-- Add a key so sync can't tell which to use +check(mtn_ws_opts("genkey", "address@hidden"), 0, false, false, string.rep("address@hidden", 2)) +check(mtn_ws_opts("sync"), 1, false, false) + +-- Set the key in _MTN/options +check(mtn_ws_opts("sync", "--set-default", "address@hidden"), 0, false, false) + +-- use it +check(mtn_ws_opts("sync"), 0, false, false) + +srv:stop() + +-- end of file + ============================================================ --- cmd_netsync.cc 3fc803802fa21cc1e8e35faa705c749fa284c841 +++ cmd_netsync.cc a4cc78ff8b6ca44b17c1f1e6514a5e1e9984f598 @@ -223,11 +223,18 @@ CMD(sync, "sync", "", CMD_REF(network), extract_address(app.opts, db, args, addr); extract_patterns(app.opts, db, args, include_pattern, exclude_pattern); find_key_if_needed(app.opts, app.lua, db, keys, - addr, include_pattern, exclude_pattern, false); + addr, include_pattern, exclude_pattern, true); std::list uris; uris.push_back(addr); + if (app.opts.set_default && workspace::found) + { + // Write workspace options, including key; this is the simplest way to + // fix a "found multiple keys" error reported by sync. + workspace work(app, true); + } + run_netsync_protocol(app.opts, app.lua, project, keys, client_voice, source_and_sink_role, uris, include_pattern, exclude_pattern); ============================================================ --- lua-testsuite.lua d2db92ea969f6b5a4a7cd2d6a0dc6c528b41bbfa +++ lua-testsuite.lua 3c0e59374e0318967367a44c32f179fd9e3d63fb @@ -9,10 +9,23 @@ function safe_mtn(...) err("'mtn' environment variable not set") end end - return {monotone_path, "--norc", "--root=" .. test.root, + return {monotone_path, "--ssh-sign=no", "--norc", "--root=" .. test.root, "--confdir="..test.root, unpack(arg)} end +function mtn_ws_opts(...) + -- Return a mtn command string that uses options from _MTN/options, + -- root from current directory - as close to a normal user command + -- line as possible. + if monotone_path == nil then + monotone_path = os.getenv("mtn") + if monotone_path == nil then + err("'mtn' environment variable not set") + end + end + return {monotone_path, "--ssh-sign=no", "--norc", "--rcfile", test.root .. "/test_hooks.lua", unpack(arg)} +end + -- function preexecute(x) -- return {"valgrind", "--tool=memcheck", unpack(x)} -- end @@ -77,7 +90,7 @@ function mtn_setup() check(getstd("test_keys")) check(getstd("test_hooks.lua")) check(getstd("min_hooks.lua")) - + check(mtn("db", "init"), 0, false, false) check(mtn("read", "test_keys"), 0, false, false) check(mtn("setup", "--branch=testbranch", "."), 0, false, false) @@ -153,7 +166,7 @@ function revert_to(rev, branch, mt) for path in io.lines("paths-new") do len = string.len(path) - 1 - + if (string.match(path, "^ file \"")) then path = string.sub(path, 10, len) elseif (string.match(path, "^dir \"")) then @@ -166,10 +179,10 @@ function revert_to(rev, branch, mt) remove(path) end end - + for path in io.lines("paths-old") do len = string.len(path) - 1 - + if (string.match(path, "^ file \"")) then path = string.sub(path, 10, len) elseif (string.match(path, "^dir \"")) then @@ -182,7 +195,7 @@ function revert_to(rev, branch, mt) remove(path) end end - + if branch == nil then check(mt("checkout", "--revision", rev, "."), 0, false, true) else @@ -209,7 +222,7 @@ function check_same_db_contents(db1, db2 function check_same_db_contents(db1, db2) check_same_stdout(mtn("--db", db1, "ls", "keys"), mtn("--db", db2, "ls", "keys")) - + check(mtn("--db", db1, "complete", "revision", ""), 0, true, false) rename("stdout", "revs") check(mtn("--db", db2, "complete", "revision", ""), 0, true, false) @@ -223,7 +236,7 @@ function check_same_db_contents(db1, db2 check_same_stdout(mtn("--db", db1, "automate", "get_manifest_of", rev), mtn("--db", db2, "automate", "get_manifest_of", rev)) end - + check(mtn("--db", db1, "complete", "file", ""), 0, true, false) rename("stdout", "files") check(mtn("--db", db2, "complete", "file", ""), 0, true, false) ============================================================ --- tests/commit_use_workspace_keydir/__driver__.lua 3b080116b803ded67686ffc6b16d21920156d249 +++ tests/commit_use_workspace_keydir/__driver__.lua 8498a70d3c7d9d7c5c0e93ef159c97fbdb4484d4 @@ -15,7 +15,7 @@ function mtn_default_keydir(...) end return {monotone_path, "--norc", "--root=" .. test.root, "--db", "test.db", "--rcfile", test.root .. "/test_hooks.lua", - "address@hidden", "--debug", unpack(arg)} + "address@hidden", unpack(arg)} end addfile("randomfile", "random stuff") ============================================================ --- tests/common/netsync.lua a33cf9951874259a390ad9ac0d9348893de4bac3 +++ tests/common/netsync.lua 3e28b68bf122aefa0f55f5d3dfb80338f55bba2b @@ -111,6 +111,9 @@ function netsync.internal.run(oper, pat, function netsync.internal.run(oper, pat, opts) local srv = netsync.start(opts) if type(opts) == "table" then + if type(pat) ~= "table" then + err("first argument to netsync."..oper.." should be a table when second argument is present") + end for k, v in pairs(opts) do table.insert(pat, v) end