Created
January 30, 2015 00:39
-
-
Save ucarion/ecfaf80a0d122b05e89d to your computer and use it in GitHub Desktop.
Rust issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn read_file(path: &str) -> IoResult<String> { | |
let basepath = Path::new(".git"); | |
File::open(&basepath.join(path)).read_to_string() | |
} | |
pub enum HeadState { | |
Detached(String), | |
Attached(String) | |
} | |
pub fn read_head() -> HeadState { | |
let head = read_file("HEAD").unwrap(); | |
let head_slice = head.as_slice(); | |
let re = regex!(r"ref: (.+)"); | |
match re.captures(head_slice) { | |
None => { | |
HeadState::Detached(head.clone()) | |
}, | |
Some(captures) => { | |
HeadState::Attached(captures.at(1).unwrap().to_string()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment