// Copyright 2022 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; use indoc::formatdoc;use indoc::indoc;use testutils::git; use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir;use crate::common::to_toml_value; fn set_up_non_empty_git_repo(git_repo: &gix::Repository) { set_up_git_repo_with_file(git_repo, "file");} fn set_up_git_repo_with_file(git_repo: &gix::Repository, filename: &str) { git::add_commit( git_repo, "refs/heads/main", filename, b"content", "message", &[], ); git::set_symbolic_reference(git_repo, "HEAD", "refs/heads/main");} #[test]fn test_git_clone() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); test_env.add_config("git.auto-local-bookmark = true"); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); // Clone an empty repo let output = root_dir.run_jj(["git", "clone", "source", "empty"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/empty" Nothing changed. [EOF] "#); set_up_non_empty_git_repo(&git_repo); // Clone with relative source path let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); // Subsequent fetch should just work even if the source path was relative let output = clone_dir.run_jj(["git", "fetch"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Nothing changed. [EOF] "); // Failed clone should clean up the destination directory root_dir.create_dir("bad"); let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(!test_env.env_root().join("failed").exists()); // Failed clone shouldn't remove the existing destination directory let failed_dir = root_dir.create_dir("failed"); let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(failed_dir.root().exists()); assert!(!failed_dir.root().join(".jj").exists()); // Failed clone (if attempted) shouldn't remove the existing workspace let output = root_dir.run_jj(["git", "clone", "bad", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); assert!(clone_dir.root().join(".jj").exists()); // Try cloning into an existing workspace let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into an existing file root_dir.write_file("file", "contents"); let output = root_dir.run_jj(["git", "clone", "source", "file"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into non-empty, non-workspace directory clone_dir.remove_dir_all(".jj"); let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Clone into a nested path let output = root_dir.run_jj(["git", "clone", "source", "nested/path/to/repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/nested/path/to/repo" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuzqqzqu c871b515 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#);} #[test]fn test_git_clone_bad_source() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let output = root_dir.run_jj(["git", "clone", "", "dest"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: local path "" does not specify a path to a repository [EOF] [exit status: 2] "#); // Invalid port number let output = root_dir.run_jj(["git", "clone", "https://example.net:bad-port/bar", "dest"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: URL "https://example.net:bad-port/bar" can not be parsed as valid URL Caused by: invalid port number [EOF] [exit status: 2] "#);} #[test]fn test_git_clone_colocate() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); test_env.add_config("git.auto-local-bookmark = true"); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); // Clone an empty repo let output = root_dir.run_jj(["git", "clone", "source", "empty", "--colocate"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/empty" Nothing changed. Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); // git_target path should be relative to the store let empty_dir = test_env.work_dir("empty"); let git_target_file_contents = String::from_utf8(empty_dir.read_file(".jj/repo/store/git_target").into()).unwrap(); insta::assert_snapshot!( git_target_file_contents.replace(path::MAIN_SEPARATOR, "/"), @"../../../.git"); set_up_non_empty_git_repo(&git_repo); // Clone with relative source path let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(clone_dir.root().join(".git").exists()); eprintln!( "{:?}", git_repo.head().expect("Repo head should be set").name() ); let jj_git_repo = git::open(clone_dir.root()); assert_eq!( jj_git_repo .head_id() .expect("Clone Repo HEAD should be set.") .detach(), git_repo .head_id() .expect("Repo HEAD should be set.") .detach(), ); // ".jj" directory should be ignored at Git side. let git_statuses = git::status(&jj_git_repo); insta::assert_debug_snapshot!(git_statuses, @r#" [ GitStatus { path: ".jj/.gitignore", status: Worktree( Ignored, ), }, GitStatus { path: ".jj/repo", status: Worktree( Ignored, ), }, GitStatus { path: ".jj/working_copy", status: Worktree( Ignored, ), }, ] "#); // The old default bookmark "master" shouldn't exist. insta::assert_snapshot!(get_bookmark_output(&clone_dir), @r" main: qomsplrm ebeb70d8 message @git: qomsplrm ebeb70d8 message @origin: qomsplrm ebeb70d8 message [EOF] "); // Subsequent fetch should just work even if the source path was relative let output = clone_dir.run_jj(["git", "fetch"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Nothing changed. [EOF] "); // Failed clone should clean up the destination directory root_dir.create_dir("bad"); let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(!test_env.env_root().join("failed").exists()); // Failed clone shouldn't remove the existing destination directory let failed_dir = root_dir.create_dir("failed"); let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(failed_dir.root().exists()); assert!(!failed_dir.root().join(".git").exists()); assert!(!failed_dir.root().join(".jj").exists()); // Failed clone (if attempted) shouldn't remove the existing workspace let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); assert!(clone_dir.root().join(".git").exists()); assert!(clone_dir.root().join(".jj").exists()); // Try cloning into an existing workspace let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into an existing file root_dir.write_file("file", "contents"); let output = root_dir.run_jj(["git", "clone", "source", "file", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into non-empty, non-workspace directory clone_dir.remove_dir_all(".jj"); let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Clone into a nested path let output = root_dir.run_jj([ "git", "clone", "source", "nested/path/to/repo", "--colocate", ]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/nested/path/to/repo" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: vzqnnsmr fea36bca (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#);} #[test]fn test_git_clone_colocate_via_config() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); test_env.add_config("git.colocate = true"); set_up_non_empty_git_repo(&git_repo); let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(clone_dir.root().join(".git").exists());} #[test]fn test_git_clone_no_colocate() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); test_env.add_config("git.colocate = true"); set_up_non_empty_git_repo(&git_repo); let output = root_dir.run_jj(["git", "clone", "--no-colocate", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(!clone_dir.root().join(".git").exists());} #[test]fn test_git_clone_tags() { use gix::remote::fetch::Tags; let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let source_git_repo = git::init(git_repo_path); git::add_commit( &source_git_repo, "refs/tags/v1.0", "foo", b"content", "message", &[], ); let commit = git::add_commit( &source_git_repo, "refs/tags/v2.0", "bar", b"content", "message", &[], ) .commit_id; git::add_commit( &source_git_repo, "refs/heads/main", "baz", b"content", "message", &[commit], ); git::set_symbolic_reference(&source_git_repo, "HEAD", "refs/heads/main"); let run_test = |name, args: &[_]| { // Clone an empty repo root_dir.run_jj( ["git", "clone", "source", name, "--colocate"] .iter() .chain(args), ) }; let get_remote_fetch_tags = |name| { git::open(test_env.env_root().join(name)) .find_remote("origin") .unwrap() .fetch_tags() }; insta::assert_snapshot!(run_test("default", &[]), @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/default" bookmark: main@origin [new] tracked tag: v1.0@git [new] tag: v2.0@git [new] Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 88542a00 (empty) (no description set) Parent commit (@-) : lnmyztun e93ca54d main | message Added 2 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); insta::assert_snapshot!(run_test("included", &["--fetch-tags", "included"]), @r#" ------- stderr -------Lines 1–500 of 1251. Load more
// Copyright 2022 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; use indoc::formatdoc; use indoc::indoc; use testutils::git; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; use crate::common::to_toml_value; fn set_up_non_empty_git_repo(git_repo: &gix::Repository) { set_up_git_repo_with_file(git_repo, "file"); } fn set_up_git_repo_with_file(git_repo: &gix::Repository, filename: &str) { git::add_commit( git_repo, "refs/heads/main", filename, b"content", "message", &[], ); git::set_symbolic_reference(git_repo, "HEAD", "refs/heads/main"); } #[test] fn test_git_clone() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); test_env.add_config("git.auto-local-bookmark = true"); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); // Clone an empty repo let output = root_dir.run_jj(["git", "clone", "source", "empty"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/empty" Nothing changed. [EOF] "#); set_up_non_empty_git_repo(&git_repo); // Clone with relative source path let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); // Subsequent fetch should just work even if the source path was relative let output = clone_dir.run_jj(["git", "fetch"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Nothing changed. [EOF] "); // Failed clone should clean up the destination directory root_dir.create_dir("bad"); let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(!test_env.env_root().join("failed").exists()); // Failed clone shouldn't remove the existing destination directory let failed_dir = root_dir.create_dir("failed"); let output = root_dir.run_jj(["git", "clone", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(failed_dir.root().exists()); assert!(!failed_dir.root().join(".jj").exists()); // Failed clone (if attempted) shouldn't remove the existing workspace let output = root_dir.run_jj(["git", "clone", "bad", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); assert!(clone_dir.root().join(".jj").exists()); // Try cloning into an existing workspace let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into an existing file root_dir.write_file("file", "contents"); let output = root_dir.run_jj(["git", "clone", "source", "file"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into non-empty, non-workspace directory clone_dir.remove_dir_all(".jj"); let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Clone into a nested path let output = root_dir.run_jj(["git", "clone", "source", "nested/path/to/repo"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/nested/path/to/repo" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuzqqzqu c871b515 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#); } #[test] fn test_git_clone_bad_source() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let output = root_dir.run_jj(["git", "clone", "", "dest"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: local path "" does not specify a path to a repository [EOF] [exit status: 2] "#); // Invalid port number let output = root_dir.run_jj(["git", "clone", "https://example.net:bad-port/bar", "dest"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Error: URL "https://example.net:bad-port/bar" can not be parsed as valid URL Caused by: invalid port number [EOF] [exit status: 2] "#); } #[test] fn test_git_clone_colocate() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); test_env.add_config("git.auto-local-bookmark = true"); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); // Clone an empty repo let output = root_dir.run_jj(["git", "clone", "source", "empty", "--colocate"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/empty" Nothing changed. Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); // git_target path should be relative to the store let empty_dir = test_env.work_dir("empty"); let git_target_file_contents = String::from_utf8(empty_dir.read_file(".jj/repo/store/git_target").into()).unwrap(); insta::assert_snapshot!( git_target_file_contents.replace(path::MAIN_SEPARATOR, "/"), @"../../../.git"); set_up_non_empty_git_repo(&git_repo); // Clone with relative source path let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: uuqppmxq 3711b3b5 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(clone_dir.root().join(".git").exists()); eprintln!( "{:?}", git_repo.head().expect("Repo head should be set").name() ); let jj_git_repo = git::open(clone_dir.root()); assert_eq!( jj_git_repo .head_id() .expect("Clone Repo HEAD should be set.") .detach(), git_repo .head_id() .expect("Repo HEAD should be set.") .detach(), ); // ".jj" directory should be ignored at Git side. let git_statuses = git::status(&jj_git_repo); insta::assert_debug_snapshot!(git_statuses, @r#" [ GitStatus { path: ".jj/.gitignore", status: Worktree( Ignored, ), }, GitStatus { path: ".jj/repo", status: Worktree( Ignored, ), }, GitStatus { path: ".jj/working_copy", status: Worktree( Ignored, ), }, ] "#); // The old default bookmark "master" shouldn't exist. insta::assert_snapshot!(get_bookmark_output(&clone_dir), @r" main: qomsplrm ebeb70d8 message @git: qomsplrm ebeb70d8 message @origin: qomsplrm ebeb70d8 message [EOF] "); // Subsequent fetch should just work even if the source path was relative let output = clone_dir.run_jj(["git", "fetch"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Nothing changed. [EOF] "); // Failed clone should clean up the destination directory root_dir.create_dir("bad"); let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(!test_env.env_root().join("failed").exists()); // Failed clone shouldn't remove the existing destination directory let failed_dir = root_dir.create_dir("failed"); let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "failed"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/failed" Error: Could not find repository at '$TEST_ENV/bad' [EOF] [exit status: 1] "#); assert!(failed_dir.root().exists()); assert!(!failed_dir.root().join(".git").exists()); assert!(!failed_dir.root().join(".jj").exists()); // Failed clone (if attempted) shouldn't remove the existing workspace let output = root_dir.run_jj(["git", "clone", "--colocate", "bad", "clone"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); assert!(clone_dir.root().join(".git").exists()); assert!(clone_dir.root().join(".jj").exists()); // Try cloning into an existing workspace let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into an existing file root_dir.write_file("file", "contents"); let output = root_dir.run_jj(["git", "clone", "source", "file", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Try cloning into non-empty, non-workspace directory clone_dir.remove_dir_all(".jj"); let output = root_dir.run_jj(["git", "clone", "source", "clone", "--colocate"]); insta::assert_snapshot!(output, @r" ------- stderr ------- Error: Destination path exists and is not an empty directory [EOF] [exit status: 1] "); // Clone into a nested path let output = root_dir.run_jj([ "git", "clone", "source", "nested/path/to/repo", "--colocate", ]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/nested/path/to/repo" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: vzqnnsmr fea36bca (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); } #[test] fn test_git_clone_colocate_via_config() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); test_env.add_config("git.colocate = true"); set_up_non_empty_git_repo(&git_repo); let output = root_dir.run_jj(["git", "clone", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(clone_dir.root().join(".git").exists()); } #[test] fn test_git_clone_no_colocate() { let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let git_repo = git::init(git_repo_path); test_env.add_config("git.colocate = true"); set_up_non_empty_git_repo(&git_repo); let output = root_dir.run_jj(["git", "clone", "--no-colocate", "source", "clone"]); insta::assert_snapshot!(output, @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/clone" bookmark: main@origin [new] tracked Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 1ca44815 (empty) (no description set) Parent commit (@-) : qomsplrm ebeb70d8 main | message Added 1 files, modified 0 files, removed 0 files [EOF] "#); let clone_dir = test_env.work_dir("clone"); assert!(clone_dir.root().join("file").exists()); assert!(!clone_dir.root().join(".git").exists()); } #[test] fn test_git_clone_tags() { use gix::remote::fetch::Tags; let test_env = TestEnvironment::default(); let root_dir = test_env.work_dir(""); let git_repo_path = test_env.env_root().join("source"); let source_git_repo = git::init(git_repo_path); git::add_commit( &source_git_repo, "refs/tags/v1.0", "foo", b"content", "message", &[], ); let commit = git::add_commit( &source_git_repo, "refs/tags/v2.0", "bar", b"content", "message", &[], ) .commit_id; git::add_commit( &source_git_repo, "refs/heads/main", "baz", b"content", "message", &[commit], ); git::set_symbolic_reference(&source_git_repo, "HEAD", "refs/heads/main"); let run_test = |name, args: &[_]| { // Clone an empty repo root_dir.run_jj( ["git", "clone", "source", name, "--colocate"] .iter() .chain(args), ) }; let get_remote_fetch_tags = |name| { git::open(test_env.env_root().join(name)) .find_remote("origin") .unwrap() .fetch_tags() }; insta::assert_snapshot!(run_test("default", &[]), @r#" ------- stderr ------- Fetching into new repo in "$TEST_ENV/default" bookmark: main@origin [new] tracked tag: v1.0@git [new] tag: v2.0@git [new] Setting the revset alias `trunk()` to `main@origin` Working copy (@) now at: sqpuoqvx 88542a00 (empty) (no description set) Parent commit (@-) : lnmyztun e93ca54d main | message Added 2 files, modified 0 files, removed 0 files Hint: Running `git clean -xdf` will remove `.jj/`! [EOF] "#); insta::assert_snapshot!(run_test("included", &["--fetch-tags", "included"]), @r#" ------- stderr -------