diff options
Diffstat (limited to 'src/modules/git_branch.rs')
-rw-r--r-- | src/modules/git_branch.rs | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index 22b934da3..500cc10b8 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -1,5 +1,4 @@ use ansi_term::Color; -use git2::Repository; use super::{Context, Module}; @@ -7,32 +6,17 @@ use super::{Context, Module}; /// /// Will display the branch name if the current directory is a git repo pub fn segment(context: &Context) -> Option<Module> { - let repo_root = context.repo_root.as_ref()?; - let repository = Repository::open(repo_root).ok()?; + let branch_name = context.branch_name.as_ref()?; - match get_current_branch(&repository) { - Ok(branch_name) => { - const GIT_BRANCH_CHAR: &str = " "; - let segment_color = Color::Purple.bold(); + const GIT_BRANCH_CHAR: &str = " "; + let segment_color = Color::Purple.bold(); - let mut module = Module::new("git_branch"); - module.set_style(segment_color); - module.get_prefix().set_value("in "); + let mut module = Module::new("git_branch"); + module.set_style(segment_color); + module.get_prefix().set_value("on "); - module.new_segment("branch_char", GIT_BRANCH_CHAR); - module.new_segment("branch_name", branch_name); + module.new_segment("branch_char", GIT_BRANCH_CHAR); + module.new_segment("branch_name", branch_name.to_string()); - Some(module) - } - Err(_e) => None, - } -} - -fn get_current_branch(repository: &Repository) -> Result<String, git2::Error> { - let head = repository.head()?; - let head_name = head.shorthand(); - match head_name { - Some(name) => Ok(name.to_string()), - None => Err(git2::Error::from_str("No branch name found")), - } + Some(module) } |