Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
47 changes: 38 additions & 9 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
30 changes: 28 additions & 2 deletions tests/error_handling_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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])
Expand All @@ -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")
);
}

Expand Down Expand Up @@ -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");

Expand Down
10 changes: 4 additions & 6 deletions tests/performance_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
Loading