diff --git a/Cargo.toml b/Cargo.toml index 244da33..8a438e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_util" -version = "0.6.22" +version = "0.6.23" authors = ["Hatter Jiang "] edition = "2018" description = "Hatter's Rust Util" diff --git a/src/util_git.rs b/src/util_git.rs index 412bd44..d97588b 100644 --- a/src/util_git.rs +++ b/src/util_git.rs @@ -45,6 +45,16 @@ pub fn git_status(working_dir: Option<&str>) -> XResult { Ok(git_status) } +pub fn git_branch(working_dir: Option<&str>) -> XResult> { + let mut cmd = new_git_command(working_dir); + cmd.arg("branch"); + util_msg::print_info(&format!("Exec: {:?}", cmd)); + let output = cmd.output()?; + let git_branch = String::from_utf8(output.stdout)?; + let current_branch = git_branch.lines().find(|ln| ln.trim().starts_with("*")); + Ok(current_branch.map(|ln| ln.trim()[1..].trim().into())) +} + pub fn git_push(working_dir: Option<&str>) { let mut cmd = new_git_command(working_dir); cmd.arg("push");