}
impl super::Remote for Git {
- fn can_handle(&self, _: &str) -> bool {
- // If we ever implement another remote we will want a check strategy
- true
+ fn can_handle(&self, remote: &str) -> bool {
+ let command = format!("git ls-remote {remote}");
+ match Command::new("sh")
+ .arg("-c")
+ .arg(&command)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .status()
+ {
+ Ok(status) => status.success(),
+ _ => false,
+ }
}
fn sync_up(&self, remote: &str, directory: &Path) -> Result<()> {
}
#[test]
- fn test_dummy_handle() {
+ fn test_can_handle_git_remotes() {
+ let git = Git::new();
+
+ let test_dir = setup_test_dir();
+ let remote_dir = test_dir.join("remote");
+ let remote_dir_as_string = remote_dir.display().to_string();
+
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+ create_remote(&remote_dir);
+ assert!(git.can_handle(&remote_dir_as_string));
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_can_not_handle_not_git_remotes() {
let git = Git::new();
- let can_handle = git.can_handle("anything");
- assert!(can_handle);
+
+ let test_dir = setup_test_dir();
+ let remote_dir = test_dir.join("remote");
+ let remote_dir_as_string = remote_dir.display().to_string();
+
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+ assert!(!git.can_handle(&remote_dir_as_string));
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_can_not_handle_invalid_paths() {
+ let git = Git::new();
+
+ let invalid_remote = String::from("test\0");
+ assert!(!git.can_handle(&invalid_remote));
}
#[test]