2022-08-20 07:06:55 +00:00
|
|
|
use crate::error;
|
|
|
|
|
2022-08-22 08:51:54 +00:00
|
|
|
use std::fs;
|
2022-08-20 07:06:55 +00:00
|
|
|
use std::path;
|
|
|
|
use std::process;
|
|
|
|
|
2022-08-24 10:38:47 +00:00
|
|
|
pub enum Vcs {
|
|
|
|
Git,
|
|
|
|
Svn,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn command(args : Vec<String>, vcs : Vcs, vault_folder : &path::Path) -> Result<(), error::Error> {
|
2022-08-20 07:06:55 +00:00
|
|
|
|
2022-08-24 10:38:47 +00:00
|
|
|
let mut command = match vcs {
|
|
|
|
Vcs::Git => process::Command::new("git"),
|
|
|
|
Vcs::Svn => process::Command::new("svn"),
|
|
|
|
};
|
2022-08-20 07:06:55 +00:00
|
|
|
|
2022-08-20 23:58:05 +00:00
|
|
|
let mut child = command
|
2022-08-20 07:06:55 +00:00
|
|
|
.current_dir(vault_folder)
|
2022-08-20 23:58:05 +00:00
|
|
|
.args(args)
|
|
|
|
.spawn()?;
|
2022-08-20 07:06:55 +00:00
|
|
|
|
2022-08-20 23:58:05 +00:00
|
|
|
let _ = child.wait()?;
|
2022-08-20 07:06:55 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-08-22 08:51:54 +00:00
|
|
|
|
|
|
|
pub fn create_gitignore(vault_folder : &path::Path) -> Result<(), error::Error> {
|
|
|
|
Ok(fs::write(vault_folder.join(".gitignore"), "state.toml\ntemp.toml\ntemp.md")?)
|
|
|
|
}
|