2020-12-12 08:00:42 +00:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// 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-01-16 06:06:12 +00:00
|
|
|
use jujutsu::testutils::TestEnvironment;
|
2020-12-12 08:00:42 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-12-28 08:26:37 +00:00
|
|
|
fn test_init_git_internal() {
|
2022-01-16 06:06:12 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(test_env.env_root(), &["init", "repo", "--git"])
|
|
|
|
.assert()
|
|
|
|
.success();
|
2020-12-28 08:26:37 +00:00
|
|
|
|
2022-01-16 06:06:12 +00:00
|
|
|
let workspace_root = test_env.env_root().join("repo");
|
2022-01-29 04:26:16 +00:00
|
|
|
let jj_path = workspace_root.join(".jj");
|
|
|
|
let repo_path = jj_path.join("repo");
|
|
|
|
let store_path = repo_path.join("store");
|
|
|
|
assert!(workspace_root.is_dir());
|
|
|
|
assert!(jj_path.is_dir());
|
|
|
|
assert!(jj_path.join("working_copy").is_dir());
|
2022-01-16 06:06:12 +00:00
|
|
|
assert.stdout(format!(
|
|
|
|
"Initialized repo in \"{}\"\n",
|
|
|
|
workspace_root.to_str().unwrap()
|
|
|
|
));
|
2020-12-28 08:26:37 +00:00
|
|
|
assert!(repo_path.is_dir());
|
2022-01-29 04:26:16 +00:00
|
|
|
assert!(store_path.is_dir());
|
|
|
|
assert!(store_path.join("git").is_dir());
|
|
|
|
assert!(store_path.join("git_target").is_file());
|
|
|
|
let git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")).unwrap();
|
2021-10-14 05:50:50 +00:00
|
|
|
assert_eq!(git_target_file_contents, "git");
|
2020-12-28 08:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_init_git_external() {
|
2022-01-16 06:06:12 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
2020-12-12 08:00:42 +00:00
|
|
|
git2::Repository::init(git_repo_path.clone()).unwrap();
|
2022-01-16 06:06:12 +00:00
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(
|
|
|
|
test_env.env_root(),
|
|
|
|
&[
|
|
|
|
"init",
|
|
|
|
"repo",
|
|
|
|
"--git-repo",
|
|
|
|
git_repo_path.to_str().unwrap(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.assert()
|
|
|
|
.success();
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2022-01-16 06:06:12 +00:00
|
|
|
let workspace_root = test_env.env_root().join("repo");
|
2022-01-29 04:26:16 +00:00
|
|
|
let jj_path = workspace_root.join(".jj");
|
|
|
|
let repo_path = jj_path.join("repo");
|
|
|
|
let store_path = repo_path.join("store");
|
|
|
|
assert!(workspace_root.is_dir());
|
|
|
|
assert!(jj_path.is_dir());
|
|
|
|
assert!(jj_path.join("working_copy").is_dir());
|
2022-01-16 06:06:12 +00:00
|
|
|
assert.stdout(format!(
|
|
|
|
"Initialized repo in \"{}\"\n",
|
|
|
|
workspace_root.display()
|
|
|
|
));
|
2020-12-12 08:00:42 +00:00
|
|
|
assert!(repo_path.is_dir());
|
2022-01-29 04:26:16 +00:00
|
|
|
assert!(store_path.is_dir());
|
|
|
|
let git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")).unwrap();
|
2021-10-14 05:50:50 +00:00
|
|
|
assert!(git_target_file_contents
|
2021-03-11 06:35:16 +00:00
|
|
|
.replace('\\', "/")
|
|
|
|
.ends_with("/git-repo"));
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_init_local() {
|
2022-01-16 06:06:12 +00:00
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(test_env.env_root(), &["init", "repo"])
|
|
|
|
.assert()
|
|
|
|
.success();
|
2020-12-12 08:00:42 +00:00
|
|
|
|
2022-01-16 06:06:12 +00:00
|
|
|
let workspace_root = test_env.env_root().join("repo");
|
2022-01-29 04:26:16 +00:00
|
|
|
let jj_path = workspace_root.join(".jj");
|
|
|
|
let repo_path = jj_path.join("repo");
|
|
|
|
let store_path = repo_path.join("store");
|
|
|
|
assert!(workspace_root.is_dir());
|
|
|
|
assert!(jj_path.is_dir());
|
|
|
|
assert!(jj_path.join("working_copy").is_dir());
|
2022-01-16 06:06:12 +00:00
|
|
|
assert.stdout(format!(
|
|
|
|
"Initialized repo in \"{}\"\n",
|
|
|
|
workspace_root.display()
|
|
|
|
));
|
2020-12-12 08:00:42 +00:00
|
|
|
assert!(repo_path.is_dir());
|
2022-01-29 04:26:16 +00:00
|
|
|
assert!(store_path.is_dir());
|
|
|
|
assert!(store_path.join("commits").is_dir());
|
|
|
|
assert!(store_path.join("trees").is_dir());
|
|
|
|
assert!(store_path.join("files").is_dir());
|
|
|
|
assert!(store_path.join("symlinks").is_dir());
|
|
|
|
assert!(store_path.join("conflicts").is_dir());
|
2020-12-12 08:00:42 +00:00
|
|
|
}
|