From ee4f8f28768e6b5563eb9fc838b18a47d22bef8f Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Mon, 19 Jun 2023 17:44:11 -0700 Subject: [PATCH] test_git_fetch: move a fetch test from test_git_import_export --- tests/test_git_fetch.rs | 61 +++++++++++++++++++++++++++++++++ tests/test_git_import_export.rs | 61 --------------------------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/tests/test_git_fetch.rs b/tests/test_git_fetch.rs index 7808eb09b..083d8bbb2 100644 --- a/tests/test_git_fetch.rs +++ b/tests/test_git_fetch.rs @@ -890,3 +890,64 @@ fn test_git_fetch_removed_parent_branch() { ◉ 000000000000 "###); } + +#[test] +fn test_git_fetch_remote_only_branch() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + // Create non-empty git repo to add as a remote + let git_repo_path = test_env.env_root().join("git-repo"); + let git_repo = git2::Repository::init(git_repo_path).unwrap(); + let signature = + git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap(); + let mut tree_builder = git_repo.treebuilder(None).unwrap(); + let file_oid = git_repo.blob(b"content").unwrap(); + tree_builder + .insert("file", file_oid, git2::FileMode::Blob.into()) + .unwrap(); + let tree_oid = tree_builder.write().unwrap(); + let tree = git_repo.find_tree(tree_oid).unwrap(); + test_env.jj_cmd_success( + &repo_path, + &["git", "remote", "add", "origin", "../git-repo"], + ); + // Create a commit and a branch in the git repo + git_repo + .commit( + Some("refs/heads/feature1"), + &signature, + &signature, + "message", + &tree, + &[], + ) + .unwrap(); + + // Fetch normally + test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]); + insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" + feature1: 9f01a0e04879 message + "###); + + git_repo + .commit( + Some("refs/heads/feature2"), + &signature, + &signature, + "message", + &tree, + &[], + ) + .unwrap(); + + // Fetch using git.auto_local_branch = false + test_env.add_config("git.auto-local-branch = false"); + test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]); + insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" + feature1: 9f01a0e04879 message + feature2 (deleted) + @origin: 9f01a0e04879 message + "###); +} diff --git a/tests/test_git_import_export.rs b/tests/test_git_import_export.rs index 2fbf57756..5f09dc354 100644 --- a/tests/test_git_import_export.rs +++ b/tests/test_git_import_export.rs @@ -89,67 +89,6 @@ fn test_git_export_conflicting_git_refs() { "###); } -#[test] -fn test_git_fetch_remote_only_branch() { - let test_env = TestEnvironment::default(); - test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); - let repo_path = test_env.env_root().join("repo"); - - // Create non-empty git repo to add as a remote - let git_repo_path = test_env.env_root().join("git-repo"); - let git_repo = git2::Repository::init(git_repo_path).unwrap(); - let signature = - git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap(); - let mut tree_builder = git_repo.treebuilder(None).unwrap(); - let file_oid = git_repo.blob(b"content").unwrap(); - tree_builder - .insert("file", file_oid, git2::FileMode::Blob.into()) - .unwrap(); - let tree_oid = tree_builder.write().unwrap(); - let tree = git_repo.find_tree(tree_oid).unwrap(); - test_env.jj_cmd_success( - &repo_path, - &["git", "remote", "add", "origin", "../git-repo"], - ); - // Create a commit and a branch in the git repo - git_repo - .commit( - Some("refs/heads/feature1"), - &signature, - &signature, - "message", - &tree, - &[], - ) - .unwrap(); - - // Fetch normally - test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]); - insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" - feature1: 9f01a0e04879 message - "###); - - git_repo - .commit( - Some("refs/heads/feature2"), - &signature, - &signature, - "message", - &tree, - &[], - ) - .unwrap(); - - // Fetch using git.auto_local_branch = false - test_env.add_config("git.auto-local-branch = false"); - test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]); - insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" - feature1: 9f01a0e04879 message - feature2 (deleted) - @origin: 9f01a0e04879 message - "###); -} - #[test] fn test_git_export_undo() { let test_env = TestEnvironment::default();