MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / test_clone_local

Function test_clone_local

src/git_operations.rs:794–872  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

792
793 #[tokio::test]
794 async fn test_clone_local() {
795 // Create source repository with commits
796 let source_repo = TestGitRepository::new().unwrap();
797 source_repo.init_with_commit().unwrap();
798
799 // Create first commit
800 source_repo.create_file("file1.txt", "First file").unwrap();
801 source_repo.stage_all().unwrap();
802 source_repo.commit("First commit").unwrap();
803 let first_commit_sha = get_current_commit(source_repo.path()).await.unwrap();
804
805 // Create second commit
806 source_repo.create_file("file2.txt", "Second file").unwrap();
807 source_repo.stage_all().unwrap();
808 source_repo.commit("Second commit").unwrap();
809 let second_commit_sha = get_current_commit(source_repo.path()).await.unwrap();
810
811 // Clone the repository
812 let dest_repo = TestGitRepository::new().unwrap();
813 let dest_path = dest_repo.path().join("cloned_repo");
814 clone_local(source_repo.path(), &dest_path).await.unwrap();
815
816 // Verify cloned repository exists and is a valid git repository
817 assert!(dest_path.exists(), "Cloned repository should exist");
818 assert!(
819 dest_path.join(".git").exists(),
820 "Cloned repository should have .git directory"
821 );
822
823 // Verify the cloned repository has the same HEAD commit
824 let cloned_head_sha = get_current_commit(&dest_path).await.unwrap();
825 assert_eq!(
826 cloned_head_sha, second_commit_sha,
827 "Cloned repository should have the same HEAD commit"
828 );
829
830 // Verify both files exist in the cloned repository
831 assert!(
832 dest_path.join("file1.txt").exists(),
833 "First file should exist in cloned repo"
834 );
835 assert!(
836 dest_path.join("file2.txt").exists(),
837 "Second file should exist in cloned repo"
838 );
839
840 // Verify we can access the first commit in the cloned repository
841 let first_commit_oid = git2::Oid::from_str(&first_commit_sha).unwrap();
842 let cloned_git_repo = git2::Repository::open(&dest_path).unwrap();
843 let first_commit = cloned_git_repo.find_commit(first_commit_oid).unwrap();
844 assert_eq!(
845 first_commit.id().to_string(),
846 first_commit_sha,
847 "Should be able to access first commit in cloned repo"
848 );
849
850 // Verify pack file optimization (should have 1-2 pack files, not 30+)
851 let pack_dir = dest_path.join(".git/objects/pack");

Callers

nothing calls this directly

Calls 7

get_current_commitFunction · 0.85
clone_localFunction · 0.85
init_with_commitMethod · 0.80
create_fileMethod · 0.80
stage_allMethod · 0.80
commitMethod · 0.80
pathMethod · 0.80

Tested by

no test coverage detected