|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
use std::process::Command; |
|
|
|
|
use crate::paths; |
|
|
|
|
|
|
|
|
|
use std::process::Command; |
|
|
|
|
use std::io; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -7,12 +8,38 @@ pub struct Git {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Git { |
|
|
|
|
pub fn commit(db_path: String) -> io::Result<()> { |
|
|
|
|
// TODO: impllement
|
|
|
|
|
// Command::new("git")
|
|
|
|
|
// .arg("add")
|
|
|
|
|
pub fn sync() -> io::Result<()> { |
|
|
|
|
let sp = paths::get_storage_path()?; |
|
|
|
|
Command::new("git") |
|
|
|
|
.arg("add") |
|
|
|
|
.arg(paths::PATH_DB) |
|
|
|
|
.current_dir(&sp) |
|
|
|
|
.status() |
|
|
|
|
.map_err(|e| io::Error::new( |
|
|
|
|
io::ErrorKind::Other, |
|
|
|
|
format!("Failed to execute git add: {}", e) |
|
|
|
|
))?; |
|
|
|
|
Command::new("git") |
|
|
|
|
.arg("commit") |
|
|
|
|
.arg("-m") |
|
|
|
|
.arg("\"sync\"") |
|
|
|
|
.current_dir(&sp) |
|
|
|
|
.status() |
|
|
|
|
.map_err(|e| io::Error::new( |
|
|
|
|
io::ErrorKind::Other, |
|
|
|
|
format!("Failed to execute git commit: {}", e) |
|
|
|
|
))?; |
|
|
|
|
|
|
|
|
|
Command::new("git") |
|
|
|
|
.arg("push") |
|
|
|
|
.arg(paths::PATH_DB) |
|
|
|
|
.current_dir(&sp) |
|
|
|
|
.status() |
|
|
|
|
.map_err(|e| io::Error::new( |
|
|
|
|
io::ErrorKind::Other, |
|
|
|
|
format!("Failed to execute git push: {}", e) |
|
|
|
|
))?; |
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|