// Copyright 2024 The Jujutsu Authors//// 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. use std::path::Path;use std::path::PathBuf; use indoc::formatdoc;use test_case::test_case;use testutils::git; use crate::common::to_toml_value;use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir; fn init_git_repo(git_repo_path: &Path, bare: bool) -> gix::Repository { let git_repo = if bare { git::init_bare(git_repo_path) } else { git::init(git_repo_path) }; let git::CommitResult { commit_id, .. } = git::add_commit( &git_repo, "refs/heads/my-bookmark", "some-file", b"some content", "My commit message", &[], ); git::set_head_to_id(&git_repo, commit_id); git_repo} #[must_use]fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput { work_dir.run_jj(["bookmark", "list", "--all-remotes"])} #[must_use]fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#" separate(" ", commit_id.short(), bookmarks, if(git_head, "git_head()"), description, )"#; work_dir.run_jj(["log", "-T", template, "-r=all()"])} fn read_git_target(work_dir: &TestWorkDir) -> String { String::from_utf8(work_dir.read_file(".jj/repo/store/git_target").into()).unwrap()} #[test]fn test_git_init_internal() { let test_env = TestEnvironment::default(); let output = test_env.run_jj_in(".", ["git", "init", "repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Initialized repo in "repo" [EOF] "#); let work_dir = test_env.work_dir("repo"); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); assert!(store_path.join("git").is_dir()); assert_eq!(read_git_target(&work_dir), "git");} #[test]fn test_git_init_internal_ignore_working_copy() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("").create_dir("repo"); work_dir.write_file("file1", ""); let output = work_dir.run_jj(["git", "init", "--ignore-working-copy"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --ignore-working-copy is not respected [EOF] [exit status: 2] ");} #[test]fn test_git_init_internal_at_operation() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("").create_dir("repo"); let output = work_dir.run_jj(["git", "init", "--at-op=@-"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --at-op is not respected [EOF] [exit status: 2] ");} #[test_case(false; "full")]#[test_case(true; "bare")]fn test_git_init_external(bare: bool) { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, bare); let output = test_env.run_jj_in( ".", [ "git", "init", "repo", "--git-repo", git_repo_path.to_str().unwrap(), ], ); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Working copy (@) now at: sqpuoqvx ed6b5138 (empty) (no description set) Parent commit (@-) : nntyzxmz e80a42cc my-bookmark | My commit message Added 1 files, modified 0 files, removed 0 files Initialized repo in "repo" [EOF] "#); } let work_dir = test_env.work_dir("repo"); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); let unix_git_target_file_contents = read_git_target(&work_dir).replace('\\', "/"); if bare { assert!(unix_git_target_file_contents.ends_with("/git-repo")); } else { assert!(unix_git_target_file_contents.ends_with("/git-repo/.git")); } // Check that the Git repo's HEAD got checked out insta::allow_duplicates! { insta::assert_snapshot!(get_log_output(&work_dir), @r" @ ed6b513890ae ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); }} #[test_case(false; "full")]#[test_case(true; "bare")]fn test_git_init_external_import_trunk(bare: bool) { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); let git_repo = init_git_repo(&git_repo_path, bare); // Add remote bookmark "trunk" for remote "origin", and set it as "origin/HEAD" let oid = git_repo .find_reference("refs/heads/my-bookmark") .unwrap() .id(); git_repo .reference( "refs/remotes/origin/trunk", oid.detach(), gix::refs::transaction::PreviousValue::MustNotExist, "create remote ref", ) .unwrap(); git::set_symbolic_reference( &git_repo, "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk", ); let output = test_env.run_jj_in( ".", [ "git", "init", "repo", "--git-repo", git_repo_path.to_str().unwrap(), ], ); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Setting the revset alias `trunk()` to `trunk@origin` Working copy (@) now at: sqpuoqvx ed6b5138 (empty) (no description set) Parent commit (@-) : nntyzxmz e80a42cc my-bookmark trunk@origin | My commit message Added 1 files, modified 0 files, removed 0 files Initialized repo in "repo" [EOF] "#); } // "trunk()" alias should be set to remote "origin"'s default bookmark "trunk" let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["config", "list", "--repo", "revset-aliases.\"trunk()\""]); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" revset-aliases."trunk()" = "trunk@origin" [EOF] "#); }} #[test]fn test_git_init_external_ignore_working_copy() { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let work_dir = test_env.work_dir("").create_dir("repo"); work_dir.write_file("file1", ""); // No snapshot should be taken let output = work_dir.run_jj([ "git", "init", "--ignore-working-copy", "--git-repo", git_repo_path.to_str().unwrap(), ]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --ignore-working-copy is not respected [EOF] [exit status: 2] ");} #[test]fn test_git_init_external_at_operation() { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let work_dir = test_env.work_dir("").create_dir("repo"); let output = work_dir.run_jj([ "git", "init", "--at-op=@-", "--git-repo", git_repo_path.to_str().unwrap(), ]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --at-op is not respected [EOF] [exit status: 2] ");} #[test]fn test_git_init_external_non_existent_directory() { let test_env = TestEnvironment::default(); let output = test_env.run_jj_in(".", ["git", "init", "repo", "--git-repo", "non-existent"]); insta::assert_snapshot!(output.strip_stderr_last_line(), @r" ------- stderr ------- Error: Failed to access the repository Caused by: 1: Cannot access $TEST_ENV/non-existent [EOF] [exit status: 1] ");} #[test]fn test_git_init_external_non_existent_git_directory() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("repo"); let output = test_env.run_jj_in(".", ["git", "init", "repo", "--git-repo", "repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: Failed to access the repository Caused by: 1: Failed to open git repository 2: "$TEST_ENV/repo" does not appear to be a git repository 3: Missing HEAD at '.git/HEAD' [EOF] [exit status: 1] "#); let jj_path = work_dir.root().join(".jj"); assert!(!jj_path.exists());} #[test]fn test_git_init_colocated_via_git_repo_path() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("repo"); init_git_repo(work_dir.root(), false); let output = work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); assert!(read_git_target(&work_dir) .replace('\\', "/") .ends_with("../../../.git")); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] ");} #[test]fn test_git_init_colocated_via_git_repo_path_gitlink() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); let git_repo = init_git_repo(&git_repo_path, false); let jj_work_dir = test_env.work_dir("").create_dir("repo"); git::create_gitlink(jj_work_dir.root(), git_repo.path()); assert!(jj_work_dir.root().join(".git").is_file()); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] ");} #[cfg(unix)]#[test]fn test_git_init_colocated_via_git_repo_path_symlink_directory() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let jj_work_dir = test_env.work_dir("").create_dir("repo"); std::os::unix::fs::symlink(git_repo_path.join(".git"), jj_work_dir.root().join(".git")) .unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] ");} #[cfg(unix)]#[test]fn test_git_init_colocated_via_git_repo_path_symlink_directory_without_bare_config() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo.git"); let jj_work_dir = test_env.work_dir("repo"); // Set up git repo without core.bare set (as the "repo" tool would do.) // The core.bare config is deduced from the directory name. let git_repo = init_git_repo(jj_work_dir.root(), false); git::remove_config_value(git_repo, "config", "bare"); std::fs::rename(jj_work_dir.root().join(".git"), &git_repo_path).unwrap(); std::os::unix::fs::symlink(&git_repo_path, jj_work_dir.root().join(".git")).unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] ");} #[cfg(unix)]#[test]fn test_git_init_colocated_via_git_repo_path_symlink_gitlink() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_workdir_path>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); let git_workdir_path = test_env.env_root().join("git-workdir"); let git_repo = init_git_repo(&git_repo_path, false); std::fs::create_dir(&git_workdir_path).unwrap(); git::create_gitlink(&git_workdir_path, git_repo.path()); assert!(git_workdir_path.join(".git").is_file()); let jj_work_dir = test_env.work_dir("").create_dir("repo"); std::os::unix::fs::symlink( git_workdir_path.join(".git"), jj_work_dir.root().join(".git"), ) .unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF]Lines 1–500 of 912. Load more
// Copyright 2024 The Jujutsu Authors // // 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. use std::path::Path; use std::path::PathBuf; use indoc::formatdoc; use test_case::test_case; use testutils::git; use crate::common::to_toml_value; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; fn init_git_repo(git_repo_path: &Path, bare: bool) -> gix::Repository { let git_repo = if bare { git::init_bare(git_repo_path) } else { git::init(git_repo_path) }; let git::CommitResult { commit_id, .. } = git::add_commit( &git_repo, "refs/heads/my-bookmark", "some-file", b"some content", "My commit message", &[], ); git::set_head_to_id(&git_repo, commit_id); git_repo } #[must_use] fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput { work_dir.run_jj(["bookmark", "list", "--all-remotes"]) } #[must_use] fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { let template = r#" separate(" ", commit_id.short(), bookmarks, if(git_head, "git_head()"), description, )"#; work_dir.run_jj(["log", "-T", template, "-r=all()"]) } fn read_git_target(work_dir: &TestWorkDir) -> String { String::from_utf8(work_dir.read_file(".jj/repo/store/git_target").into()).unwrap() } #[test] fn test_git_init_internal() { let test_env = TestEnvironment::default(); let output = test_env.run_jj_in(".", ["git", "init", "repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Initialized repo in "repo" [EOF] "#); let work_dir = test_env.work_dir("repo"); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); assert!(store_path.join("git").is_dir()); assert_eq!(read_git_target(&work_dir), "git"); } #[test] fn test_git_init_internal_ignore_working_copy() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("").create_dir("repo"); work_dir.write_file("file1", ""); let output = work_dir.run_jj(["git", "init", "--ignore-working-copy"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --ignore-working-copy is not respected [EOF] [exit status: 2] "); } #[test] fn test_git_init_internal_at_operation() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("").create_dir("repo"); let output = work_dir.run_jj(["git", "init", "--at-op=@-"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --at-op is not respected [EOF] [exit status: 2] "); } #[test_case(false; "full")] #[test_case(true; "bare")] fn test_git_init_external(bare: bool) { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, bare); let output = test_env.run_jj_in( ".", [ "git", "init", "repo", "--git-repo", git_repo_path.to_str().unwrap(), ], ); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Working copy (@) now at: sqpuoqvx ed6b5138 (empty) (no description set) Parent commit (@-) : nntyzxmz e80a42cc my-bookmark | My commit message Added 1 files, modified 0 files, removed 0 files Initialized repo in "repo" [EOF] "#); } let work_dir = test_env.work_dir("repo"); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); let unix_git_target_file_contents = read_git_target(&work_dir).replace('\\', "/"); if bare { assert!(unix_git_target_file_contents.ends_with("/git-repo")); } else { assert!(unix_git_target_file_contents.ends_with("/git-repo/.git")); } // Check that the Git repo's HEAD got checked out insta::allow_duplicates! { insta::assert_snapshot!(get_log_output(&work_dir), @r" @ ed6b513890ae ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); } } #[test_case(false; "full")] #[test_case(true; "bare")] fn test_git_init_external_import_trunk(bare: bool) { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); let git_repo = init_git_repo(&git_repo_path, bare); // Add remote bookmark "trunk" for remote "origin", and set it as "origin/HEAD" let oid = git_repo .find_reference("refs/heads/my-bookmark") .unwrap() .id(); git_repo .reference( "refs/remotes/origin/trunk", oid.detach(), gix::refs::transaction::PreviousValue::MustNotExist, "create remote ref", ) .unwrap(); git::set_symbolic_reference( &git_repo, "refs/remotes/origin/HEAD", "refs/remotes/origin/trunk", ); let output = test_env.run_jj_in( ".", [ "git", "init", "repo", "--git-repo", git_repo_path.to_str().unwrap(), ], ); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Setting the revset alias `trunk()` to `trunk@origin` Working copy (@) now at: sqpuoqvx ed6b5138 (empty) (no description set) Parent commit (@-) : nntyzxmz e80a42cc my-bookmark trunk@origin | My commit message Added 1 files, modified 0 files, removed 0 files Initialized repo in "repo" [EOF] "#); } // "trunk()" alias should be set to remote "origin"'s default bookmark "trunk" let work_dir = test_env.work_dir("repo"); let output = work_dir.run_jj(["config", "list", "--repo", "revset-aliases.\"trunk()\""]); insta::allow_duplicates! { insta::assert_snapshot!(output, @r#" revset-aliases."trunk()" = "trunk@origin" [EOF] "#); } } #[test] fn test_git_init_external_ignore_working_copy() { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let work_dir = test_env.work_dir("").create_dir("repo"); work_dir.write_file("file1", ""); // No snapshot should be taken let output = work_dir.run_jj([ "git", "init", "--ignore-working-copy", "--git-repo", git_repo_path.to_str().unwrap(), ]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --ignore-working-copy is not respected [EOF] [exit status: 2] "); } #[test] fn test_git_init_external_at_operation() { let test_env = TestEnvironment::default(); let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let work_dir = test_env.work_dir("").create_dir("repo"); let output = work_dir.run_jj([ "git", "init", "--at-op=@-", "--git-repo", git_repo_path.to_str().unwrap(), ]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: --at-op is not respected [EOF] [exit status: 2] "); } #[test] fn test_git_init_external_non_existent_directory() { let test_env = TestEnvironment::default(); let output = test_env.run_jj_in(".", ["git", "init", "repo", "--git-repo", "non-existent"]); insta::assert_snapshot!(output.strip_stderr_last_line(), @r" ------- stderr ------- Error: Failed to access the repository Caused by: 1: Cannot access $TEST_ENV/non-existent [EOF] [exit status: 1] "); } #[test] fn test_git_init_external_non_existent_git_directory() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("repo"); let output = test_env.run_jj_in(".", ["git", "init", "repo", "--git-repo", "repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: Failed to access the repository Caused by: 1: Failed to open git repository 2: "$TEST_ENV/repo" does not appear to be a git repository 3: Missing HEAD at '.git/HEAD' [EOF] [exit status: 1] "#); let jj_path = work_dir.root().join(".jj"); assert!(!jj_path.exists()); } #[test] fn test_git_init_colocated_via_git_repo_path() { let test_env = TestEnvironment::default(); let work_dir = test_env.work_dir("repo"); init_git_repo(work_dir.root(), false); let output = work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); let jj_path = work_dir.root().join(".jj"); let repo_path = jj_path.join("repo"); let store_path = repo_path.join("store"); assert!(work_dir.root().is_dir()); assert!(jj_path.is_dir()); assert!(jj_path.join("working_copy").is_dir()); assert!(repo_path.is_dir()); assert!(store_path.is_dir()); assert!(read_git_target(&work_dir) .replace('\\', "/") .ends_with("../../../.git")); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] "); } #[test] fn test_git_init_colocated_via_git_repo_path_gitlink() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); let git_repo = init_git_repo(&git_repo_path, false); let jj_work_dir = test_env.work_dir("").create_dir("repo"); git::create_gitlink(jj_work_dir.root(), git_repo.path()); assert!(jj_work_dir.root().join(".git").is_file()); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] "); } #[cfg(unix)] #[test] fn test_git_init_colocated_via_git_repo_path_symlink_directory() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); init_git_repo(&git_repo_path, false); let jj_work_dir = test_env.work_dir("").create_dir("repo"); std::os::unix::fs::symlink(git_repo_path.join(".git"), jj_work_dir.root().join(".git")) .unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] "); } #[cfg(unix)] #[test] fn test_git_init_colocated_via_git_repo_path_symlink_directory_without_bare_config() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo.git"); let jj_work_dir = test_env.work_dir("repo"); // Set up git repo without core.bare set (as the "repo" tool would do.) // The core.bare config is deduced from the directory name. let git_repo = init_git_repo(jj_work_dir.root(), false); git::remove_config_value(git_repo, "config", "bare"); std::fs::rename(jj_work_dir.root().join(".git"), &git_repo_path).unwrap(); std::os::unix::fs::symlink(&git_repo_path, jj_work_dir.root().join(".git")).unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF] "#); insta::assert_snapshot!(read_git_target(&jj_work_dir), @"../../../.git"); // Check that the Git repo's HEAD got checked out insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ f3fe58bc88cc ○ e80a42cccd06 my-bookmark git_head() My commit message ◆ 000000000000 [EOF] "); // Check that the Git repo's HEAD moves jj_work_dir.run_jj(["new"]).success(); insta::assert_snapshot!(get_log_output(&jj_work_dir), @r" @ 0c77f9e21b55 ○ f3fe58bc88cc git_head() ○ e80a42cccd06 my-bookmark My commit message ◆ 000000000000 [EOF] "); } #[cfg(unix)] #[test] fn test_git_init_colocated_via_git_repo_path_symlink_gitlink() { let test_env = TestEnvironment::default(); // <jj_work_dir>/.git -> <git_workdir_path>/.git -> <git_repo_path> let git_repo_path = test_env.env_root().join("git-repo"); let git_workdir_path = test_env.env_root().join("git-workdir"); let git_repo = init_git_repo(&git_repo_path, false); std::fs::create_dir(&git_workdir_path).unwrap(); git::create_gitlink(&git_workdir_path, git_repo.path()); assert!(git_workdir_path.join(".git").is_file()); let jj_work_dir = test_env.work_dir("").create_dir("repo"); std::os::unix::fs::symlink( git_workdir_path.join(".git"), jj_work_dir.root().join(".git"), ) .unwrap(); let output = jj_work_dir.run_jj(["git", "init", "--git-repo", "."]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Done importing changes from the underlying Git repo. Initialized repo in "." [EOF]