1 use std::io::{Error, ErrorKind::Other, Result};
2 use std::path::PathBuf;
3 use std::process::{Command, Stdio};
4 use std::time::{SystemTime, UNIX_EPOCH};
14 impl super::Remote for Git {
15 fn can_handle(&self, _: &str) -> bool {
16 // If we ever implement another remote we will want a check strategy
20 fn sync_up(&self, remote: &str, directory: &PathBuf) -> Result<()> {
21 let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)
22 .map_err(|_| Error::new(Other, "Invalid time"))?
26 format!("cd {} && git init -b main", directory.display()),
27 format!("cd {} && git add .", directory.display()),
28 format!("cd {} && git commit --allow-empty -m blog-sync-up-{}", directory.display(), timestamp),
29 format!("cd {} && git push {} main --force", directory.display(), remote),
32 for command in commands {
36 .stdout(Stdio::null())
37 .stderr(Stdio::null())
39 .map_err(|_| Error::new(Other, "Failed while performing sync up with git"))?;
45 fn sync_down(&self, remote: &str, directory: &PathBuf) -> Result<()> {
47 format!("cd {} && git init -b main", directory.display()),
48 format!("cd {} && git checkout .", directory.display()),
49 format!("cd {} && git clean . -f", directory.display()),
50 format!("cd {} && git pull {} main", directory.display(), remote),
53 for command in commands {
57 .stdout(Stdio::null())
58 .stderr(Stdio::null())
60 .map_err(|_| Error::new(Other, "Failed while performing sync down with git"))?;