diff options
author | Neil Kistner <neil.kistner@gmail.com> | 2019-08-27 22:11:42 -0500 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-08-27 20:11:42 -0700 |
commit | 9853743eda935a25ddce18e32e97cca0192d9389 (patch) | |
tree | f0522e78ae1e8e7be5ad1770066d73f5fedbb3c4 /src/modules/git_status.rs | |
parent | ed27cf4a2c56d9acb5e552a45f675e03bbc72286 (diff) |
feat: Add commit count for ahead/behind symbols (#247)
Add logic for the git status module to display the number of commits the index is ahead or behind next to the symbol.
Diffstat (limited to 'src/modules/git_status.rs')
-rw-r--r-- | src/modules/git_status.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/modules/git_status.rs b/src/modules/git_status.rs index 8c675c334..693b938a9 100644 --- a/src/modules/git_status.rs +++ b/src/modules/git_status.rs @@ -66,12 +66,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { // Add the ahead/behind segment if let Ok((ahead, behind)) = ahead_behind { + let ahead_segment = format!("{}{}", GIT_STATUS_AHEAD, ahead); + let behind_segment = format!("{}{}", GIT_STATUS_BEHIND, behind); + if ahead > 0 && behind > 0 { module.new_segment("diverged", GIT_STATUS_DIVERGED); + module.new_segment("ahead", ahead_segment.as_str()); + module.new_segment("behind", behind_segment.as_str()); } else if ahead > 0 { - module.new_segment("ahead", GIT_STATUS_AHEAD); + module.new_segment("ahead", ahead_segment.as_str()); } else if behind > 0 { - module.new_segment("behind", GIT_STATUS_BEHIND); + module.new_segment("behind", behind_segment.as_str()); } } @@ -113,7 +118,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { /// Gets the bitflags associated with the repo's git status fn get_repo_status(repository: &Repository) -> Result<Status, git2::Error> { let mut status_options = git2::StatusOptions::new(); + status_options.include_untracked(true); + status_options.renames_from_rewrites(true); + status_options.renames_head_to_index(true); + status_options.renames_index_to_workdir(true); let repo_file_statuses = repository.statuses(Some(&mut status_options))?; |