2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2020 The Jujutsu Authors
|
2020-12-28 08:26:37 +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-03-30 05:14:39 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_lib::git_backend::GitBackend;
|
|
|
|
use jj_lib::op_store::WorkspaceId;
|
|
|
|
use jj_lib::repo::Repo;
|
|
|
|
use jj_lib::settings::UserSettings;
|
|
|
|
use jj_lib::workspace::Workspace;
|
2021-05-19 18:52:28 +00:00
|
|
|
use test_case::test_case;
|
2022-12-24 15:38:20 +00:00
|
|
|
use testutils::{write_random_commit, TestWorkspace};
|
2020-12-28 08:26:37 +00:00
|
|
|
|
2022-03-30 05:14:39 +00:00
|
|
|
fn canonicalize(input: &Path) -> (PathBuf, PathBuf) {
|
|
|
|
let uncanonical = input.join("..").join(input.file_name().unwrap());
|
|
|
|
let canonical = uncanonical.canonicalize().unwrap();
|
|
|
|
(canonical, uncanonical)
|
|
|
|
}
|
|
|
|
|
2020-12-28 08:26:37 +00:00
|
|
|
#[test]
|
|
|
|
fn test_init_local() {
|
|
|
|
let settings = testutils::user_settings();
|
2022-09-07 03:29:39 +00:00
|
|
|
let temp_dir = testutils::new_temp_dir();
|
2022-03-30 05:14:39 +00:00
|
|
|
let (canonical, uncanonical) = canonicalize(temp_dir.path());
|
2022-09-23 21:03:43 +00:00
|
|
|
let (workspace, repo) = Workspace::init_local(&settings, &uncanonical).unwrap();
|
2023-05-12 13:05:32 +00:00
|
|
|
assert!(repo
|
|
|
|
.store()
|
|
|
|
.backend_impl()
|
|
|
|
.downcast_ref::<GitBackend>()
|
|
|
|
.is_none());
|
2022-03-30 05:14:39 +00:00
|
|
|
assert_eq!(repo.repo_path(), &canonical.join(".jj").join("repo"));
|
|
|
|
assert_eq!(workspace.workspace_root(), &canonical);
|
2020-12-28 08:26:37 +00:00
|
|
|
|
2021-07-30 21:35:08 +00:00
|
|
|
// Just test that we can write a commit to the store
|
2022-11-13 06:29:06 +00:00
|
|
|
let mut tx = repo.start_transaction(&settings, "test");
|
2022-12-24 15:38:20 +00:00
|
|
|
write_random_commit(tx.mut_repo(), &settings);
|
2020-12-28 08:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_init_internal_git() {
|
|
|
|
let settings = testutils::user_settings();
|
2022-09-07 03:29:39 +00:00
|
|
|
let temp_dir = testutils::new_temp_dir();
|
2022-03-30 05:14:39 +00:00
|
|
|
let (canonical, uncanonical) = canonicalize(temp_dir.path());
|
2022-09-23 21:03:43 +00:00
|
|
|
let (workspace, repo) = Workspace::init_internal_git(&settings, &uncanonical).unwrap();
|
2023-05-12 13:05:32 +00:00
|
|
|
assert!(repo
|
|
|
|
.store()
|
|
|
|
.backend_impl()
|
|
|
|
.downcast_ref::<GitBackend>()
|
|
|
|
.is_some());
|
2022-03-30 05:14:39 +00:00
|
|
|
assert_eq!(repo.repo_path(), &canonical.join(".jj").join("repo"));
|
|
|
|
assert_eq!(workspace.workspace_root(), &canonical);
|
2020-12-28 08:26:37 +00:00
|
|
|
|
2021-07-30 21:35:08 +00:00
|
|
|
// Just test that we ca write a commit to the store
|
2022-11-13 06:29:06 +00:00
|
|
|
let mut tx = repo.start_transaction(&settings, "test");
|
2022-12-24 15:38:20 +00:00
|
|
|
write_random_commit(tx.mut_repo(), &settings);
|
2020-12-28 08:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_init_external_git() {
|
|
|
|
let settings = testutils::user_settings();
|
2022-09-07 03:29:39 +00:00
|
|
|
let temp_dir = testutils::new_temp_dir();
|
2022-03-30 05:14:39 +00:00
|
|
|
let (canonical, uncanonical) = canonicalize(temp_dir.path());
|
|
|
|
let git_repo_path = uncanonical.join("git");
|
2020-12-28 08:26:37 +00:00
|
|
|
git2::Repository::init(&git_repo_path).unwrap();
|
2022-11-24 18:39:22 +00:00
|
|
|
std::fs::create_dir(uncanonical.join("jj")).unwrap();
|
2021-11-22 06:55:31 +00:00
|
|
|
let (workspace, repo) =
|
2022-09-23 21:03:43 +00:00
|
|
|
Workspace::init_external_git(&settings, &uncanonical.join("jj"), &git_repo_path).unwrap();
|
2023-05-12 13:05:32 +00:00
|
|
|
|
|
|
|
assert!(repo
|
|
|
|
.store()
|
|
|
|
.backend_impl()
|
|
|
|
.downcast_ref::<GitBackend>()
|
|
|
|
.is_some());
|
2022-03-30 05:14:39 +00:00
|
|
|
assert_eq!(
|
|
|
|
repo.repo_path(),
|
|
|
|
&canonical.join("jj").join(".jj").join("repo")
|
|
|
|
);
|
|
|
|
assert_eq!(workspace.workspace_root(), &canonical.join("jj"));
|
2020-12-28 08:26:37 +00:00
|
|
|
|
2021-07-30 21:35:08 +00:00
|
|
|
// Just test that we can write a commit to the store
|
2022-11-13 06:29:06 +00:00
|
|
|
let mut tx = repo.start_transaction(&settings, "test");
|
2022-12-24 15:38:20 +00:00
|
|
|
write_random_commit(tx.mut_repo(), &settings);
|
2020-12-28 08:26:37 +00:00
|
|
|
}
|
2021-05-19 18:52:28 +00:00
|
|
|
|
2021-09-12 06:52:38 +00:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2021-05-19 18:52:28 +00:00
|
|
|
fn test_init_no_config_set(use_git: bool) {
|
|
|
|
// Test that we can create a repo without setting any config
|
2022-03-10 02:04:19 +00:00
|
|
|
let settings = UserSettings::from_config(config::Config::default());
|
2022-05-21 17:55:51 +00:00
|
|
|
let test_workspace = TestWorkspace::init(&settings, use_git);
|
2021-11-21 07:46:54 +00:00
|
|
|
let repo = &test_workspace.repo;
|
2022-09-18 21:46:12 +00:00
|
|
|
let wc_commit_id = repo
|
|
|
|
.view()
|
|
|
|
.get_wc_commit_id(&WorkspaceId::default())
|
|
|
|
.unwrap();
|
|
|
|
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
|
|
|
assert_eq!(wc_commit.author().name, "(no name configured)".to_string());
|
2021-05-19 18:52:28 +00:00
|
|
|
assert_eq!(
|
2022-09-18 21:46:12 +00:00
|
|
|
wc_commit.author().email,
|
2021-05-19 18:52:28 +00:00
|
|
|
"(no email configured)".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2022-09-18 21:46:12 +00:00
|
|
|
wc_commit.committer().name,
|
2021-05-19 18:52:28 +00:00
|
|
|
"(no name configured)".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2022-09-18 21:46:12 +00:00
|
|
|
wc_commit.committer().email,
|
2021-05-19 18:52:28 +00:00
|
|
|
"(no email configured)".to_string()
|
|
|
|
);
|
|
|
|
}
|
2021-08-11 18:18:37 +00:00
|
|
|
|
2021-09-12 06:52:38 +00:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2021-08-11 18:18:37 +00:00
|
|
|
fn test_init_checkout(use_git: bool) {
|
2023-01-25 16:29:15 +00:00
|
|
|
// Test the contents of the working-copy commit after init
|
2021-08-11 18:18:37 +00:00
|
|
|
let settings = testutils::user_settings();
|
2022-05-21 17:55:51 +00:00
|
|
|
let test_workspace = TestWorkspace::init(&settings, use_git);
|
2021-11-21 07:46:54 +00:00
|
|
|
let repo = &test_workspace.repo;
|
2022-09-18 21:46:12 +00:00
|
|
|
let wc_commit_id = repo
|
|
|
|
.view()
|
|
|
|
.get_wc_commit_id(&WorkspaceId::default())
|
|
|
|
.unwrap();
|
|
|
|
let wc_commit = repo.store().get_commit(wc_commit_id).unwrap();
|
|
|
|
assert_eq!(wc_commit.tree_id(), repo.store().empty_tree_id());
|
2022-09-19 04:59:49 +00:00
|
|
|
assert_eq!(
|
|
|
|
wc_commit.store_commit().parents,
|
|
|
|
vec![repo.store().root_commit_id().clone()]
|
|
|
|
);
|
2022-09-18 21:46:12 +00:00
|
|
|
assert_eq!(wc_commit.predecessors(), vec![]);
|
|
|
|
assert_eq!(wc_commit.description(), "");
|
|
|
|
assert_eq!(wc_commit.author().name, settings.user_name());
|
|
|
|
assert_eq!(wc_commit.author().email, settings.user_email());
|
|
|
|
assert_eq!(wc_commit.committer().name, settings.user_name());
|
|
|
|
assert_eq!(wc_commit.committer().email, settings.user_email());
|
2021-08-11 18:18:37 +00:00
|
|
|
}
|