toru/src/git.rs

28 lines
752 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;
pub fn run_command(args : Vec<String>, vault_folder : &path::Path) -> Result<(), error::Error> {
let mut command = process::Command::new("git");
let mut child = command
2022-08-20 07:06:55 +00:00
.current_dir(vault_folder)
// Force colour output even though run from other process.
.args(["-c", "color.ui=always"])
.args(args)
.spawn()?;
2022-08-20 07:06:55 +00:00
// No point handling the potential error code as Git will report the error directly with more
// info.
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")?)
}