toru/src/vcs.rs

44 lines
973 B
Rust
Raw Normal View History

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
let mut child = command
2022-08-20 07:06:55 +00:00
.current_dir(vault_folder)
.args(args)
.spawn()?;
2022-08-20 07:06:55 +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")?)
}
2022-08-30 22:45:37 +00:00
pub fn set_svn_ignore(vault_folder : &path::Path) -> Result<(), error::Error> {
let mut child = process::Command::new("svn")
.current_dir(vault_folder)
.args(&["propset", "svn:ignore", "state.toml\ntemp.toml\ntemp.md", "."])
.spawn()?;
let _ = child.wait()?;
Ok(())
}