svn integration

This commit is contained in:
aaron-jack-manning 2022-08-24 20:38:47 +10:00
parent 17301735c0
commit 71d1744d9b
4 changed files with 24 additions and 12 deletions

2
Cargo.lock generated
View File

@ -825,7 +825,7 @@ dependencies = [
[[package]] [[package]]
name = "toru" name = "toru"
version = "0.1.1" version = "0.1.2"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",

View File

@ -76,7 +76,6 @@ Then you can run `toru new` to create your first task.
- Keep track of completed date, and correctly update upon marking as complete or manual edit - Keep track of completed date, and correctly update upon marking as complete or manual edit
- Disallow removing it in a manual edit unless complete is also marked to false - Disallow removing it in a manual edit unless complete is also marked to false
- Add to statistics - Add to statistics
- SVN integration
- Statistics - Statistics
- Completed tasks over last x days - Completed tasks over last x days
- Improve formatting to terminal to make easier to read for `tracked` command - Improve formatting to terminal to make easier to read for `tracked` command

View File

@ -1,4 +1,4 @@
mod git; mod vcs;
mod edit; mod edit;
mod vault; mod vault;
mod error; mod error;
@ -64,6 +64,11 @@ enum Command {
Git { Git {
args : Vec<String>, args : Vec<String>,
}, },
/// Run Subversion commands at the root of the vault.
#[clap(trailing_var_arg=true)]
Svn {
args : Vec<String>,
},
/// Adds the recommended .gitignore file to the vault. /// Adds the recommended .gitignore file to the vault.
#[clap(name="gitignore")] #[clap(name="gitignore")]
GitIgnore, GitIgnore,
@ -216,13 +221,17 @@ fn program() -> Result<(), error::Error> {
} }
else if let Git { args } = command { else if let Git { args } = command {
let vault_folder = &config.current_vault()?.1; let vault_folder = &config.current_vault()?.1;
git::run_command(args, vault_folder)?; vcs::command(args, vcs::Vcs::Git, vault_folder)?;
} }
else if command == GitIgnore { else if command == GitIgnore {
let vault_folder = &config.current_vault()?.1; let vault_folder = &config.current_vault()?.1;
git::create_gitignore(vault_folder)?; vcs::create_gitignore(vault_folder)?;
println!("Default .gitignore file created"); println!("Default .gitignore file created");
} }
else if let Svn { args } = command {
let vault_folder = &config.current_vault()?.1;
vcs::command(args, vcs::Vcs::Svn, vault_folder)?;
}
// Commands that require loading in the state. // Commands that require loading in the state.
else { else {
let vault_folder = &config.current_vault()?.1; let vault_folder = &config.current_vault()?.1;
@ -294,7 +303,7 @@ fn program() -> Result<(), error::Error> {
println!("Deleted all discarded tasks"); println!("Deleted all discarded tasks");
} }
// All commands which are dealt with in if let chain at start. // All commands which are dealt with in if let chain at start.
Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(), Vault(_) | Config(_) | Git { args : _ } | Svn { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(),
} }
state.save()?; state.save()?;

View File

@ -4,19 +4,23 @@ use std::fs;
use std::path; use std::path;
use std::process; use std::process;
pub fn run_command(args : Vec<String>, vault_folder : &path::Path) -> Result<(), error::Error> { pub enum Vcs {
Git,
Svn,
}
let mut command = process::Command::new("git"); pub fn command(args : Vec<String>, vcs : Vcs, vault_folder : &path::Path) -> Result<(), error::Error> {
let mut command = match vcs {
Vcs::Git => process::Command::new("git"),
Vcs::Svn => process::Command::new("svn"),
};
let mut child = command let mut child = command
.current_dir(vault_folder) .current_dir(vault_folder)
// Force colour output even though run from other process.
.args(["-c", "color.ui=always"])
.args(args) .args(args)
.spawn()?; .spawn()?;
// No point handling the potential error code as Git will report the error directly with more
// info.
let _ = child.wait()?; let _ = child.wait()?;
Ok(()) Ok(())