Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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