Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created November 7, 2014 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamhjk/2eb74d326242a9093f9e to your computer and use it in GitHub Desktop.
Save adamhjk/2eb74d326242a9093f9e to your computer and use it in GitHub Desktop.
fn current_branch(path: &Path) -> String {
let head_ref = head_ref(path);
println!("The ref for HEAD is {}", head_ref);
let r = regex!(r"refs/heads/(.+)");
let caps_result = r.captures(head_ref.as_slice());
let branch: String = match caps_result {
Some(cap) => { String::from_str(cap.at(1)) },
None => { panic!("You must be somewhere on refs/heads, and you aren't") }
};
branch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment