# # # add_dir "tests/clone_aborts_on_branch_pattern_in_uri" # # add_file "tests/clone_aborts_on_branch_pattern_in_uri/__driver__.lua" # content [960b48a9f83ceb2caad655e07abf084cc5ad4f0a] # # patch "cmd_netsync.cc" # from [eb61a48e4c05f2c31da827806bdd57dfbdd5d62c] # to [690110538deabf8a42879e745a5f17cf04efb48f] # # patch "monotone.texi" # from [a24e9157bb1f02847392167d9f7c74fe4de2e2f2] # to [6acffc50c2b73aa09a645270466d690b66c9886b] # # patch "tests/clone_creates_right__MTN_options/__driver__.lua" # from [a3896a6b76da7a062893f1ed8c21c6116a4be780] # to [12e86831366aa0f5573d1ec511872b6f9034aeb2] # ============================================================ --- tests/clone_aborts_on_branch_pattern_in_uri/__driver__.lua 960b48a9f83ceb2caad655e07abf084cc5ad4f0a +++ tests/clone_aborts_on_branch_pattern_in_uri/__driver__.lua 960b48a9f83ceb2caad655e07abf084cc5ad4f0a @@ -0,0 +1,22 @@ +skip_if(ostype == "Windows") -- file: not supported on native Win32 + +mtn_setup() + +addfile("foo", "blah blah") +commit("mybranch") + +copy("test.db", "test-clone.db") +testURI="file://" .. test.root .. "/test-clone.db?mybranch*" + +check(nodb_mtn("clone", testURI), 1, false, true) +check(qgrep("you must specify an unambiguous branch to clone", "stderr")) + +-- the branch option is invalid in non-URI mode +check(nodb_mtn("clone", "some-server", "mybranch", "--branch=mybranch"), 1, false, true) +check(qgrep("the --branch option is only valid with an URI to clone", "stderr")) + +-- finally, this should succeed +check(nodb_mtn("clone", testURI, "--branch=mybranch"), 0, false, false) +check(exists("mybranch")) +check(readfile("foo") == readfile("mybranch/foo")) + ============================================================ --- cmd_netsync.cc eb61a48e4c05f2c31da827806bdd57dfbdd5d62c +++ cmd_netsync.cc 690110538deabf8a42879e745a5f17cf04efb48f @@ -412,14 +412,14 @@ CMD_AUTOMATE(sync, N_("[URL]\n[ADDRESS[: client_voice, source_and_sink_role, info); } -CMD(clone, "clone", "", CMD_REF(network), - N_("URL [DIRECTORY]\nHOST[:PORTNUMBER] BRANCH [DIRECTORY]"), - N_("Checks out a revision from a remote database into a directory"), - N_("If a revision is given, that's the one that will be checked out. " - "Otherwise, it will be the head of the branch supplied. " - "If no directory is given, the branch name will be used as directory"), - options::opts::max_netsync_version | options::opts::min_netsync_version | - options::opts::revision) +CMD_NO_WORKSPACE(clone, "clone", "", CMD_REF(network), + N_("URL [DIRECTORY]\nHOST[:PORTNUMBER] BRANCH [DIRECTORY]"), + N_("Checks out a revision from a remote database into a directory"), + N_("If a revision is given, that's the one that will be checked out. " + "Otherwise, it will be the head of the branch supplied. " + "If no directory is given, the branch name will be used as directory"), + options::opts::max_netsync_version | options::opts::min_netsync_version | + options::opts::revision | options::opts::branch) { bool url_arg = (args.size() == 1 || args.size() == 2) && @@ -433,6 +433,9 @@ CMD(clone, "clone", "", CMD_REF(network) if (!(no_ambigious_revision && (url_arg || host_branch_arg))) throw usage(execid); + E(url_arg || (host_branch_arg && !app.opts.branch_given), origin::user, + F("the --branch option is only valid with an URI to clone")); + // we create the database before anything else, but we // do not clean newly created databases up if the clone fails // (and I think this is correct, because if the pull fails later @@ -476,11 +479,16 @@ CMD(clone, "clone", "", CMD_REF(network) workspace_arg = idx(args, 2); } - globish include_pattern = info->client.get_include_pattern(); - E(!include_pattern().empty() && !include_pattern.contains_meta_chars(), - origin::user, F("you must specify an unambiguous branch to clone")); - branch_name branchname(include_pattern(), origin::user); + if (app.opts.branch().empty()) + { + globish include_pattern = info->client.get_include_pattern(); + E(!include_pattern().empty() && !include_pattern.contains_meta_chars(), + origin::user, F("you must specify an unambiguous branch to clone")); + app.opts.branch = branch_name(include_pattern(), origin::user); + } + I(!app.opts.branch().empty()); + app.opts.use_transport_auth = app.lua.hook_use_transport_auth(info->client.get_uri()); @@ -494,7 +502,7 @@ CMD(clone, "clone", "", CMD_REF(network) if (workspace_arg().empty()) { // No checkout dir specified, use branch name for dir. - workspace_dir = system_path(branchname(), origin::user); + workspace_dir = system_path(app.opts.branch(), origin::user); } else { @@ -525,12 +533,7 @@ CMD(clone, "clone", "", CMD_REF(network) // db URIs will work system_path start_dir(get_current_working_dir(), origin::system); - // this is actually stupid, but app.opts.branch must be set here - // otherwise it will not be written into _MTN/options, in case - // a revision is chosen which has multiple branch certs - app.opts.branch = branchname; workspace::create_workspace(app.opts, app.lua, workspace_dir); - app.opts.branch = branch_name(); if (!keys.have_signing_key()) P(F("doing anonymous pull; use -kKEYNAME if you need authentication")); @@ -549,18 +552,18 @@ CMD(clone, "clone", "", CMD_REF(network) if (app.opts.revision_selectors.empty()) { set heads; - project.get_branch_heads(branchname, heads, + project.get_branch_heads(app.opts.branch, heads, app.opts.ignore_suspend_certs); E(!heads.empty(), origin::user, - F("branch '%s' is empty") % branchname); + F("branch '%s' is empty") % app.opts.branch); if (heads.size() > 1) { - P(F("branch %s has multiple heads:") % branchname); + P(F("branch %s has multiple heads:") % app.opts.branch); for (set::const_iterator i = heads.begin(); i != heads.end(); ++i) P(i18n_format(" %s") % describe_revision(app.opts, app.lua, project, *i)); P(F("choose one with '%s clone -r SERVER BRANCH'") % prog_name); - E(false, origin::user, F("branch %s has multiple heads") % branchname); + E(false, origin::user, F("branch %s has multiple heads") % app.opts.branch); } ident = *(heads.begin()); } @@ -569,10 +572,10 @@ CMD(clone, "clone", "", CMD_REF(network) // use specified revision complete(app.opts, app.lua, project, idx(app.opts.revision_selectors, 0)(), ident); - E(project.revision_is_in_branch(ident, branchname), + E(project.revision_is_in_branch(ident, app.opts.branch), origin::user, F("revision %s is not a member of branch %s") - % ident % branchname); + % ident % app.opts.branch); } roster_t empty_roster, current_roster; ============================================================ --- monotone.texi a24e9157bb1f02847392167d9f7c74fe4de2e2f2 +++ monotone.texi 6acffc50c2b73aa09a645270466d690b66c9886b @@ -4909,19 +4909,23 @@ @section Tree @emph{must} provide a @var{branchname}; monotone will attempt to infer @var{id} as the unique head of @var{branchname} if it exists. address@hidden mtn clone @var{uri} address@hidden address@hidden @item mtn clone @var{address}[:@var{port}] @var{branchname} address@hidden The clone command is a helper command that performs the roles of a number of other commands all at once. Firstly, it constructs a new database. If no database is given, the configured default -database is created or re-used (see the hook address@hidden in the @ref{Lua Reference} for -more details). Then it populates this database by @command{pull}ing any data -in the branch @var{branchname} from the remote database, @var{address}. +database is created or re-used (see the hook @code{get_default_database_alias} +in the @ref{Lua Reference} for more details). Then it populates this database +by @command{pull}ing any data which match the branch pattern in the @var{uri} +or the given @var{branchname} argument from the remote database. Finally, it copies the files out of the newly created database into a local directory, just as @command{checkout} would. If no @var{directory} is given, the @var{branchname} is used as directory. address@hidden notice:} The @var{address}[:@var{port}] @var{branchname} +call syntax is deprecated and subject of removal in future versions of monotone! + @item mtn disapprove @var{id} This command records a disapproval of the changes between @var{id}'s ============================================================ --- tests/clone_creates_right__MTN_options/__driver__.lua a3896a6b76da7a062893f1ed8c21c6116a4be780 +++ tests/clone_creates_right__MTN_options/__driver__.lua 12e86831366aa0f5573d1ec511872b6f9034aeb2 @@ -26,7 +26,7 @@ check(nodb_mtn("clone", testURI, "--revi -- checkout fails if the specified revision is not a member of the specified branch testURI="file://" .. test.root .. "/test-clone.db?foobar" check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir5"), 1, false, false) -check(mtn("cert", rev, "branch", "foobar"), 0, false, false) +check(nodb_mtn("cert", rev, "branch", "foobar", "-d", "test-clone.db"), 0, false, false) check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir6"), 0, false, false) @@ -34,7 +34,7 @@ for i = 1,2 do local dir = "test_dir"..i L("dir = ", dir, "\n") check(exists(dir.."/_MTN/options")) - check(qgrep("test.db", dir.."/_MTN/options")) + check(qgrep("default.mtn", dir.."/_MTN/options")) check(qgrep("testbranch", dir.."/_MTN/options")) end