diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2017-08-21 23:08:50 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2017-08-21 23:08:50 +0200 |
commit | c8a40229dabee642d598a9a8f852e33e6a183780 (patch) | |
tree | 34394dfae6f5ade0f57ea0b1fa114a7448f6da5c /src/lib.rs | |
parent | f3c7ede6af566839918cb884cde5572049962f7f (diff) |
Wrote example hook for prepending branch name to file
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..18b3476 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,31 @@ +extern crate git2; + +use std::env; +use std::io::{stdin, BufRead}; + +use git2::Repository; + + +pub fn log() { + let name_arg = env::args().nth(0).unwrap_or(String::from("unknown")); + let args: Vec<_> = env::args().skip(1).collect(); + println!("{} called with {:?}", name_arg, args); + + println!("BEGIN STDIN"); + let stdin = stdin(); + for line in stdin.lock().lines() { + println!("{:?}", line); + } + println!("END STDIN"); +} + +pub fn get_current_branch() -> Result<String, git2::Error> { + let git_repo = Repository::discover("./")?; + let head = git_repo.head()?; + let head_name = head.shorthand(); + match head_name { + Some(name) => Ok(name.to_string()), + None => Err(git2::Error::from_str("No branch name found")) + } +} + |