mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 07:30:05 +08:00
feat: add git branch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rust_util"
|
||||
version = "0.6.22"
|
||||
version = "0.6.23"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
description = "Hatter's Rust Util"
|
||||
|
||||
@@ -45,6 +45,16 @@ pub fn git_status(working_dir: Option<&str>) -> XResult<String> {
|
||||
Ok(git_status)
|
||||
}
|
||||
|
||||
pub fn git_branch(working_dir: Option<&str>) -> XResult<Option<String>> {
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user