2 use std::path::PathBuf;
3 use std::process::Command;
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 .expect("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 {
37 .expect("Failed while performing sync up with git");
43 fn sync_down(&self, remote: &str, directory: &PathBuf) -> Result<()> {
45 format!("cd {} && git init -b main", directory.display()),
46 format!("cd {} && git checkout .", directory.display()),
47 format!("cd {} && git clean . -f", directory.display()),
48 format!("cd {} && git pull {} main", directory.display(), remote),
51 for command in commands {
56 .expect("Failed while performing sync down with git");