use git_iris::config::Config;
use git_iris::git::GitRepo;
#[tokio::test]
async fn test_remote_repository_support() {
if std::env::var("CI").is_ok() || std::env::var("SKIP_REMOTE_TESTS").is_ok() {
return;
}
let repo_url = "https://github.com/hyperb1iss/tiny-test-repo.git";
let test_future = async {
let git_repo = match GitRepo::new_from_url(Some(repo_url.to_string())) {
Ok(repo) => repo,
Err(e) => {
println!("Failed to clone test repo: {e}");
println!("Skipping remote repository test - network might be unavailable");
return;
}
};
assert!(
git_repo.is_remote(),
"Repository should be marked as remote"
);
assert_eq!(
git_repo.get_remote_url(),
Some(repo_url),
"Remote URL should match"
);
let config = Config::default();
let context = match git_repo.get_git_info(&config) {
Ok(ctx) => ctx,
Err(e) => {
println!("Failed to get git info: {e}");
println!("Skipping remaining remote repository tests");
return;
}
};
assert!(
!context.branch.is_empty(),
"Should have a valid branch name"
);
assert!(
!context.recent_commits.is_empty(),
"Should have recent commits"
);
let update_result = git_repo.update_remote();
assert!(update_result.is_ok(), "Should be able to update remote");
let result = git_repo.commit("Test commit message");
assert!(
result.is_err(),
"Commit should fail for remote repositories"
);
let error_message = result
.expect_err("Expected an error when committing to a remote repository")
.to_string();
assert!(
error_message.contains("Cannot commit to a remote repository"),
"Error message should indicate it's a remote repository"
);
};
if let Ok(()) = tokio::time::timeout(std::time::Duration::from_secs(30), test_future).await {
println!("Remote repository test completed successfully");
} else {
println!("Remote repository test timed out after 30 seconds");
println!("Consider using --skip-remote-tests if network is slow");
}
}