# # # patch "cmd_ws_commit.cc" # from [1c88be1deb41dc6e49b749d3ff271f28ffac85f2] # to [3485f8cec34038d6424fe4aa54a2ba9ff437867c] # # patch "monotone.texi" # from [72bfac4d09104362e5da2c3c618fd19b27668c44] # to [b4d57a26070c08b4f4dc6404410bf66abfd1eb69] # # patch "tests/branch/__driver__.lua" # from [e2dd24c420248682d89ff1515d9bd390a5390d81] # to [ba8a90c87c324bfdbe73a32e51d82c524278b074] # ============================================================ --- cmd_ws_commit.cc 1c88be1deb41dc6e49b749d3ff271f28ffac85f2 +++ cmd_ws_commit.cc 3485f8cec34038d6424fe4aa54a2ba9ff437867c @@ -692,15 +692,22 @@ CMD(attr, N_("workspace"), N_("set PATH throw usage(name); } -CMD(branch, N_("workspace"), N_("BRANCHNAME"), - N_("changes the branch of the current workspace"), options::opts::none) +CMD(branch, N_("workspace"), N_("[BRANCHNAME]"), + N_("changes the branch of the current workspace or " + "displays the current branch"), options::opts::none) { - if (args.size() != 1) + if (args.size() > 1) throw usage(name); - branch_name branch(idx(args, 0)()); + app.require_workspace(); - app.require_workspace(); + if (args.size() == 0) + { + cout << app.opts.branchname << '\n'; + return; + } + + branch_name branch(idx(args, 0)()); E(branch != app.opts.branchname, F("branch of the current workspace is already set to %s") % branch); ============================================================ --- monotone.texi 72bfac4d09104362e5da2c3c618fd19b27668c44 +++ monotone.texi b4d57a26070c08b4f4dc6404410bf66abfd1eb69 @@ -4363,11 +4363,12 @@ @section Workspace details, and, unless the @option{--bookkeep-only} option is supplied, it will rename the files immediately in the filesystem. address@hidden mtn branch @var{branchname} address@hidden mtn branch address@hidden -This command changes the branch name of your current workspace. It does that -by overwriting any previous branch setting in @file{_MTN/options} so that its -guaranteed that the next commit gets this new branch as cert attached. +This command displays the branch name of the current workspace or changes the +branch name of your current workspace. It does the latter by overwriting any +previous branch setting in @file{_MTN/options} so that its guaranteed that the +next commit gets this new branch as cert attached. Please note that you can't set a branch name which already exists in your database. To rebase your workspace to a different branch, please use the ============================================================ --- tests/branch/__driver__.lua e2dd24c420248682d89ff1515d9bd390a5390d81 +++ tests/branch/__driver__.lua ba8a90c87c324bfdbe73a32e51d82c524278b074 @@ -7,9 +7,13 @@ commit() commit() -- check parameter checking -check(mtn("branch"), 2, false, false) check(mtn("branch", "foo", "bar"), 2, false, false) +-- check if branch w/o parameters returns the current branch +check(mtn("branch"), 0, true, false) +canonicalize("stdout") +check(readfile("stdout") == "testbranch\n") + -- check if the workspace is already set to the existing branch check(mtn("branch", "testbranch"), 1, false, true) check(qgrep("workspace is already set to testbranch", "stderr"))