2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2021 The Jujutsu Authors
|
2021-11-21 07:03:54 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-10-28 03:57:44 +00:00
|
|
|
use assert_matches::assert_matches;
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_lib::op_store::WorkspaceId;
|
|
|
|
use jj_lib::repo::{Repo, StoreFactories};
|
|
|
|
use jj_lib::workspace::{Workspace, WorkspaceLoadError};
|
2021-11-21 07:03:54 +00:00
|
|
|
use test_case::test_case;
|
2022-11-08 12:35:16 +00:00
|
|
|
use testutils::TestWorkspace;
|
2021-11-21 07:03:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_load_bad_path() {
|
|
|
|
let settings = testutils::user_settings();
|
2022-09-07 03:29:39 +00:00
|
|
|
let temp_dir = testutils::new_temp_dir();
|
2021-11-21 07:03:54 +00:00
|
|
|
let workspace_root = temp_dir.path().to_owned();
|
|
|
|
// We haven't created a repo in the workspace_root, so it should fail to load.
|
2022-12-14 18:08:31 +00:00
|
|
|
let result = Workspace::load(&settings, &workspace_root, &StoreFactories::default());
|
2022-10-28 03:57:44 +00:00
|
|
|
assert_matches!(
|
2021-11-21 07:03:54 +00:00
|
|
|
result.err(),
|
2022-10-28 03:57:44 +00:00
|
|
|
Some(WorkspaceLoadError::NoWorkspaceHere(root)) if root == workspace_root
|
2021-11-21 07:03:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-30 19:58:05 +00:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
// #[test_case(true ; "git backend")]
|
|
|
|
fn test_init_additional_workspace(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-05-21 17:55:51 +00:00
|
|
|
let test_workspace = TestWorkspace::init(&settings, use_git);
|
2022-01-30 19:58:05 +00:00
|
|
|
let workspace = &test_workspace.workspace;
|
|
|
|
|
|
|
|
let ws2_id = WorkspaceId::new("ws2".to_string());
|
2022-03-30 05:14:39 +00:00
|
|
|
let ws2_root = test_workspace.root_dir().join("ws2_root");
|
2022-01-30 19:58:05 +00:00
|
|
|
std::fs::create_dir(&ws2_root).unwrap();
|
|
|
|
let (ws2, repo) = Workspace::init_workspace_with_existing_repo(
|
|
|
|
&settings,
|
2022-09-23 21:03:43 +00:00
|
|
|
&ws2_root,
|
2022-01-30 19:58:05 +00:00
|
|
|
&test_workspace.repo,
|
|
|
|
ws2_id.clone(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2022-09-18 21:46:12 +00:00
|
|
|
let wc_commit_id = repo.view().get_wc_commit_id(&ws2_id);
|
|
|
|
assert_ne!(wc_commit_id, None);
|
|
|
|
let wc_commit_id = wc_commit_id.unwrap();
|
|
|
|
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
2022-01-30 19:58:05 +00:00
|
|
|
assert_eq!(
|
2022-09-18 21:46:12 +00:00
|
|
|
wc_commit.parent_ids(),
|
2022-01-30 19:58:05 +00:00
|
|
|
vec![repo.store().root_commit_id().clone()]
|
|
|
|
);
|
2022-10-03 11:18:34 +00:00
|
|
|
assert_eq!(ws2.workspace_id(), &ws2_id);
|
2022-02-03 06:00:37 +00:00
|
|
|
assert_eq!(
|
|
|
|
*ws2.repo_path(),
|
2022-03-30 06:13:13 +00:00
|
|
|
workspace.repo_path().canonicalize().unwrap()
|
2022-02-03 06:00:37 +00:00
|
|
|
);
|
2022-03-30 05:14:39 +00:00
|
|
|
assert_eq!(*ws2.workspace_root(), ws2_root.canonicalize().unwrap());
|
2022-12-14 18:08:31 +00:00
|
|
|
let same_workspace = Workspace::load(&settings, &ws2_root, &StoreFactories::default());
|
2022-01-30 19:58:05 +00:00
|
|
|
assert!(same_workspace.is_ok());
|
|
|
|
let same_workspace = same_workspace.unwrap();
|
2022-10-03 11:18:34 +00:00
|
|
|
assert_eq!(same_workspace.workspace_id(), &ws2_id);
|
2022-02-03 06:00:37 +00:00
|
|
|
assert_eq!(
|
|
|
|
*same_workspace.repo_path(),
|
2022-03-30 06:13:13 +00:00
|
|
|
workspace.repo_path().canonicalize().unwrap()
|
2022-02-03 06:00:37 +00:00
|
|
|
);
|
2022-01-30 19:58:05 +00:00
|
|
|
assert_eq!(same_workspace.workspace_root(), ws2.workspace_root());
|
|
|
|
}
|