From 7311e02c89b66849f5e660b690ca69b5e8fd1383 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 9 Jun 2025 00:55:34 +0200 Subject: git: Add ls-tree --- server/common/src/tests.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'server/common/src/tests.rs') diff --git a/server/common/src/tests.rs b/server/common/src/tests.rs index 09e780b..34cc315 100644 --- a/server/common/src/tests.rs +++ b/server/common/src/tests.rs @@ -205,6 +205,53 @@ async fn git_get_author_commiter(repo: &git::Repository) { assert!(repo.get_author("").await.is_err()); } +async fn git_ls_tree(repo: &git::Repository) { + let t1 = repo + .ls_tree("d7c502b9c6b833060576a0c4da0287933d603011", false) + .await + .unwrap(); + assert_eq!( + t1, + vec![ + git::TreeEntry { + object_type: git::ObjectType::BLOB, + object_name: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391".to_string(), + path: "empty".to_string(), + }, + git::TreeEntry { + object_type: git::ObjectType::BLOB, + object_name: "d393216eb885c4b4ec91b691dd59a88c846d881d".to_string(), + path: "phrase".to_string(), + }, + ] + ); + + let t2 = repo + .ls_tree("2cecdec660a30bf3964cee645d9cee03640ef8dc", false) + .await + .unwrap(); + assert_eq!( + t2, + vec![ + git::TreeEntry { + object_type: git::ObjectType::BLOB, + object_name: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391".to_string(), + path: "empty".to_string(), + }, + git::TreeEntry { + object_type: git::ObjectType::BLOB, + object_name: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391".to_string(), + path: "foo".to_string(), + }, + git::TreeEntry { + object_type: git::ObjectType::BLOB, + object_name: "d393216eb885c4b4ec91b691dd59a88c846d881d".to_string(), + path: "phrase".to_string(), + }, + ] + ); +} + async fn git_fetch(bare: bool) -> git::Repository { let path = testdir!().join("repo"); let remote_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/testdata/bare"); @@ -288,6 +335,12 @@ async fn test_git_bare_delete_branch() { assert!(repo.delete_branch("does-not-exist").await.is_err()); } +#[tokio::test] +async fn test_git_ls_tree() { + let repo = BARE.get_or_init(|| git_setup(true)).await; + git_ls_tree(repo).await; +} + #[tokio::test] async fn test_grit_parse_base() { let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/testdata/grit/base.grd"); -- cgit v1.2.3-70-g09d2