use once_cell::sync::OnceCell;
use regex::Regex;
use super::{Context, Module, ModuleConfig};
use crate::configs::git_status::GitStatusConfig;
use crate::context;
use crate::formatter::StringFormatter;
use crate::segment::Segment;
use std::sync::Arc;
const ALL_STATUS_FORMAT: &str =
"$conflicted$stashed$deleted$renamed$modified$typechanged$staged$untracked";
/// Creates a module with the Git branch in the current directory
///
/// Will display the branch name if the current directory is a git repo
/// By default, the following symbols will be used to represent the repo's status:
/// - `=` – This branch has merge conflicts
/// - `⇡` – This branch is ahead of the branch being tracked
/// - `⇣` – This branch is behind of the branch being tracked
/// - `⇕` – This branch has diverged from the branch being tracked
/// - `` – This branch is up-to-date with the branch being tracked
/// - `?` — There are untracked files in the working directory
/// - `$` — A stash exists for the local repository
/// - `!` — There are file modifications in the working directory
/// - `+` — A new file has been added to the staging area
/// - `»` — A renamed file has been added to the staging area
/// - `✘` — A file's deletion has been added to the staging area
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("git_status");
let config: GitStatusConfig = GitStatusConfig::try_load(module.config);
// Return None if not in git repository
let repo = context.get_repo().ok()?;
if repo.kind.is_bare() {
log::debug!("This is a bare repository, git_status is not applicable");
return None;
}
if let Some(git_status) = git_status_wsl(context, &config) {
if git_status.is_empty() {
return None;
}
module.set_segments(Segment::from_text(None, git_status));
return Some(module);
}
let info