ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: allow specifying a custom workspace name

We use the destination directory's basename as the workspace
name. Let's allow the user to choose a different name.
This commit is contained in:
Martin von Zweigbergk 2022-02-05 11:05:48 -08:00
parent 0ee09c9f29
commit 731aa7578e

View file

@ -1365,12 +1365,24 @@ For information about branches, see https://github.com/martinvonz/jj/blob/main/d
.about("Commands for working with workspaces")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(
App::new("add").about("Add a workspace").arg(
Arg::new("destination")
.index(1)
.required(true)
.help("Where to create the new workspace"),
),
App::new("add")
.about("Add a workspace")
.arg(
Arg::new("destination")
.index(1)
.required(true)
.help("Where to create the new workspace"),
)
.arg(
Arg::new("name")
.long("name")
.takes_value(true)
.help("A name for the workspace")
.long_help(
"A name for the workspace, to override the default, which is the \
basename of the destination directory.",
),
),
)
.subcommand(
App::new("forget")
@ -3941,12 +3953,16 @@ fn cmd_workspace_add(
} else {
fs::create_dir(&destination_path).unwrap();
}
let name = destination_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
let name = if let Some(name) = args.value_of("name") {
name.to_string()
} else {
destination_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
};
let workspace_id = WorkspaceId::new(name.clone());
let repo = old_workspace_command.repo();
if repo.view().get_checkout(&workspace_id).is_some() {