summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-08-22 21:38:36 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-08-22 21:38:36 +0200
commit0c1e6e18373fde9407ccf287757f1d221469e6d1 (patch)
treee7d1c0a2e57c13bdacab30f682a4bea26f5cc0ab
parentce7cc08eeb78ebec41a1a29a18ba80c272d2f0eb (diff)
master: Added git hook for running cargo before commits
-rw-r--r--src/bin/commit-msg.rs13
-rw-r--r--src/bin/pre-commit.rs24
-rw-r--r--src/bin/pre-push.rs13
-rw-r--r--src/bin/prepare-commit-msg.rs3
-rw-r--r--src/lib.rs1
5 files changed, 26 insertions, 28 deletions
diff --git a/src/bin/commit-msg.rs b/src/bin/commit-msg.rs
index d880dc0..e34586b 100644
--- a/src/bin/commit-msg.rs
+++ b/src/bin/commit-msg.rs
@@ -1,14 +1,9 @@
+extern crate rust_git_hooks;
+use rust_git_hooks::*;
+
use std::env;
use std::io::{stdin, BufRead};
fn main() {
- let args: Vec<_> = env::args().skip(1).collect();
- println!("commit-msg called with {:?}", args);
-
- println!("BEGIN STDIN for commit-msg");
- let stdin = stdin();
- for line in stdin.lock().lines() {
- println!("{:?}", line);
- }
- println!("END STDIN");
+ log();
}
diff --git a/src/bin/pre-commit.rs b/src/bin/pre-commit.rs
index 7b52443..361dd9c 100644
--- a/src/bin/pre-commit.rs
+++ b/src/bin/pre-commit.rs
@@ -1,14 +1,20 @@
+extern crate rust_git_hooks;
+use rust_git_hooks::*;
+
use std::env;
use std::io::{stdin, BufRead};
+use std::process;
+use std::process::{Command, Stdio};
fn main() {
- let args: Vec<_> = env::args().skip(1).collect();
- println!("pre-commit called with {:?}", args);
-
- println!("BEGIN STDIN for pre-commit");
- let stdin = stdin();
- for line in stdin.lock().lines() {
- println!("{:?}", line);
- }
- println!("END STDIN");
+ log();
+
+ let command = Command::new("cargo")
+ .arg("test")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .output()
+ .expect("failed to execute process");
+
+ process::exit(command.status.code().unwrap_or(0));
}
diff --git a/src/bin/pre-push.rs b/src/bin/pre-push.rs
index 41f3bbb..e34586b 100644
--- a/src/bin/pre-push.rs
+++ b/src/bin/pre-push.rs
@@ -1,14 +1,9 @@
+extern crate rust_git_hooks;
+use rust_git_hooks::*;
+
use std::env;
use std::io::{stdin, BufRead};
fn main() {
- let args: Vec<_> = env::args().skip(1).collect();
- println!("pre-push called with {:?}", args);
-
- println!("BEGIN STDIN for pre-push");
- let stdin = stdin();
- for line in stdin.lock().lines() {
- println!("{:?}", line);
- }
- println!("END STDIN");
+ log();
}
diff --git a/src/bin/prepare-commit-msg.rs b/src/bin/prepare-commit-msg.rs
index 1a34fc2..64ddd65 100644
--- a/src/bin/prepare-commit-msg.rs
+++ b/src/bin/prepare-commit-msg.rs
@@ -1,6 +1,6 @@
extern crate rust_git_hooks;
-
use rust_git_hooks::*;
+
use std::fs::File;
use std::io::Write;
use std::io::Read;
@@ -11,6 +11,7 @@ fn main() {
log();
let commit_filename = env::args().nth(1);
+ let commit_source = env::args().nth(2);
let current_branch = get_current_branch();
diff --git a/src/lib.rs b/src/lib.rs
index fff1c85..00e02f7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,3 +29,4 @@ pub fn get_current_branch() -> Result<String, git2::Error> {
None => Err(git2::Error::from_str("No branch name found"))
}
}
+