From 0ee09c9f29a04c24da10628698d84e120f8d6089 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 5 Feb 2022 11:05:48 -0800 Subject: [PATCH] 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. --- src/commands.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index 86450cbe0..9dc884bae 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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!(