cli: don't allow creating multiple workspaces with the same name

It's harmless but potentially confusing to have multiple workspaces
with the same ID (it would mean that they always have the same
checkout). Let's just prevent it for now. We can add an override later
if people think of usecases for it.
This commit is contained in:
Martin von Zweigbergk 2022-02-05 11:05:48 -08:00
parent 53b458a601
commit 0ee09c9f29

View file

@ -3948,10 +3948,17 @@ fn cmd_workspace_add(
.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() {
return Err(UserError(format!(
"Workspace named '{}' already exists",
name
)));
}
let (new_workspace, repo) = Workspace::init_workspace_with_existing_repo(
ui.settings(),
destination_path.clone(),
old_workspace_command.repo(),
repo,
workspace_id,
)?;
writeln!(