diff --git a/src/config.rs b/src/config.rs index 8a6d894..3545b93 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,9 +44,9 @@ pub struct SerializableBranch(pub Branch); #[derive(Debug, Default, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] pub struct SerializableUpdate(pub Update); -/**======================================================================== - ** Implement Serialize/Deserialize for Config - *========================================================================**/ +// ======================================================================== +// Implement Serialize/Deserialize for Config +// ======================================================================== /// implements Serialize for [`SerializableIgnore`] impl Serialize for SerializableIgnore { fn serialize(&self, serializer: S) -> Result diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 809fddc..c813709 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -366,14 +366,28 @@ impl TestHarness { .arg(&remote_dir) .output()?; + // Set the default branch to main for the bare repository + std::process::Command::new("git") + .args(["symbolic-ref", "HEAD", "refs/heads/main"]) + .current_dir(&remote_dir) + .output()?; + // Create a working copy to add content let work_copy = self.temp_dir.path().join(format!("{name}_work")); std::process::Command::new("git") - .args([ - "clone", - remote_dir.to_str().unwrap(), - work_copy.to_str().unwrap(), - ]) + .args(["init"]) + .arg(&work_copy) + .output()?; + + // Set up the main branch and remote + std::process::Command::new("git") + .args(["checkout", "-b", "main"]) + .current_dir(&work_copy) + .output()?; + + std::process::Command::new("git") + .args(["remote", "add", "origin", remote_dir.to_str().unwrap()]) + .current_dir(&work_copy) .output()?; // Configure git @@ -452,22 +466,37 @@ impl TestHarness { .current_dir(&work_copy) .output()?; - // Push everything - std::process::Command::new("git") + // Push everything with error checking + let push_main = std::process::Command::new("git") .args(["push", "origin", "main"]) .current_dir(&work_copy) .output()?; - std::process::Command::new("git") + if !push_main.status.success() { + let stderr = String::from_utf8_lossy(&push_main.stderr); + return Err(format!("Failed to push main branch: {stderr}").into()); + } + + let push_develop = std::process::Command::new("git") .args(["push", "origin", "develop"]) .current_dir(&work_copy) .output()?; - std::process::Command::new("git") + if !push_develop.status.success() { + let stderr = String::from_utf8_lossy(&push_develop.stderr); + return Err(format!("Failed to push develop branch: {stderr}").into()); + } + + let push_tags = std::process::Command::new("git") .args(["push", "origin", "--tags"]) .current_dir(&work_copy) .output()?; + if !push_tags.status.success() { + let stderr = String::from_utf8_lossy(&push_tags.stderr); + return Err(format!("Failed to push tags: {stderr}").into()); + } + Ok(remote_dir) } } diff --git a/tests/error_handling_tests.rs b/tests/error_handling_tests.rs index 62fdd26..311f400 100644 --- a/tests/error_handling_tests.rs +++ b/tests/error_handling_tests.rs @@ -69,6 +69,18 @@ mod tests { #[test] fn test_permission_denied_scenarios() { + // Check if running as root - permission tests don't work as root + let is_root = std::process::Command::new("id") + .arg("-u") + .output() + .map(|output| String::from_utf8_lossy(&output.stdout).trim() == "0") + .unwrap_or(false); + + if is_root { + println!("Skipping permission test - running as root"); + return; + } + let harness = TestHarness::new().expect("Failed to create test harness"); harness.init_git_repo().expect("Failed to init git repo"); @@ -299,8 +311,8 @@ active = true let harness = TestHarness::new().expect("Failed to create test harness"); harness.init_git_repo().expect("Failed to init git repo"); - // Use a URL that should timeout (non-routable address) - let timeout_url = "http://192.0.2.1/repo.git"; // RFC 3330 test address + // Use a URL that should fail quickly (invalid domain) + let timeout_url = "http://nonexistent.invalid.domain.test/repo.git"; let output = harness .run_submod(&["add", "timeout-test", "lib/timeout", timeout_url]) @@ -312,6 +324,8 @@ active = true stderr.contains("Failed to add submodule") || stderr.contains("timeout") || stderr.contains("clone failed") + || stderr.contains("could not resolve") + || stderr.contains("Name or service not known") ); } @@ -344,6 +358,18 @@ active = true #[test] fn test_config_file_locked() { + // Check if running as root - permission tests don't work as root + let is_root = std::process::Command::new("id") + .arg("-u") + .output() + .map(|output| String::from_utf8_lossy(&output.stdout).trim() == "0") + .unwrap_or(false); + + if is_root { + println!("Skipping config file lock test - running as root"); + return; + } + let harness = TestHarness::new().expect("Failed to create test harness"); harness.init_git_repo().expect("Failed to init git repo"); diff --git a/tests/performance_tests.rs b/tests/performance_tests.rs index 8c8056b..0d770e9 100644 --- a/tests/performance_tests.rs +++ b/tests/performance_tests.rs @@ -210,9 +210,7 @@ ignore = "all" println!("Many patterns sparse checkout time: {duration:?}"); // Verify sparse checkout was configured - let sparse_file = harness - .work_dir - .join("lib/many-patterns/.git/info/sparse-checkout"); + let sparse_file = harness.get_sparse_checkout_file_path("lib/many-patterns"); assert!(sparse_file.exists()); let sparse_content = fs::read_to_string(&sparse_file).expect("Failed to read sparse file"); @@ -417,18 +415,18 @@ ignore = "all" let harness = TestHarness::new().expect("Failed to create test harness"); harness.init_git_repo().expect("Failed to init git repo"); - let unicode_config = r#"[测试-submodule] + let unicode_config = r#"["测试-submodule"] path = "lib/测试" url = "https://github.com/用户/项目.git" active = true sparse_paths = ["源码/", "文档/", "*.md"] -[émoji-test-🚀] +["émoji-test-🚀"] path = "lib/émoji🚀" url = "https://github.com/user/émoji-repo.git" active = true -[special-chars-!@#$%] +["special-chars-!@#$%"] path = "lib/special" url = "https://github.com/user/special-chars.git" active = true