mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
feat(git_status): added symbol for local repos up-to-date with remote. (#2945)
* git_status: added symbol for when local branch is up-to-date with upstream * updated docs * removed unused variable, moved location of config comment * changed uptodate default to empty string, simplified and made safer * added uptodate default line back into docstring * fixed linting and formatting errors * refactored uptodate to up_to_date, removed redundant else statement
This commit is contained in:
parent
b7b7df9885
commit
b2e2330cb0
@ -1314,6 +1314,7 @@ current directory.
|
||||
| `ahead` | `"⇡"` | The format of `ahead` |
|
||||
| `behind` | `"⇣"` | The format of `behind` |
|
||||
| `diverged` | `"⇕"` | The format of `diverged` |
|
||||
| `up_to_date` | `""` | The format of `up_to_date` |
|
||||
| `untracked` | `"?"` | The format of `untracked` |
|
||||
| `stashed` | `"$"` | The format of `stashed` |
|
||||
| `modified` | `"!"` | The format of `modified` |
|
||||
@ -1328,9 +1329,9 @@ current directory.
|
||||
The following variables can be used in `format`:
|
||||
|
||||
| Variable | Description |
|
||||
| -------------- | --------------------------------------------------------------------------------------------- |
|
||||
| -------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| `all_status` | Shortcut for`$conflicted$stashed$deleted$renamed$modified$staged$untracked` |
|
||||
| `ahead_behind` | Displays `diverged` `ahead` or `behind` format string based on the current status of the repo |
|
||||
| `ahead_behind` | Displays `diverged`, `ahead`, `behind` or `up_to_date` format string based on the current status of the repo. |
|
||||
| `conflicted` | Displays `conflicted` when this branch has merge conflicts. |
|
||||
| `untracked` | Displays `untracked` when there are untracked files in the working directory. |
|
||||
| `stashed` | Displays `stashed` when a stash exists for the local repository. |
|
||||
@ -1365,6 +1366,7 @@ conflicted = "🏳"
|
||||
ahead = "🏎💨"
|
||||
behind = "😰"
|
||||
diverged = "😵"
|
||||
up_to_date = "✓"
|
||||
untracked = "🤷"
|
||||
stashed = "📦"
|
||||
modified = "📝"
|
||||
|
@ -10,6 +10,7 @@ pub struct GitStatusConfig<'a> {
|
||||
pub stashed: &'a str,
|
||||
pub ahead: &'a str,
|
||||
pub behind: &'a str,
|
||||
pub up_to_date: &'a str,
|
||||
pub diverged: &'a str,
|
||||
pub conflicted: &'a str,
|
||||
pub deleted: &'a str,
|
||||
@ -28,6 +29,7 @@ impl<'a> Default for GitStatusConfig<'a> {
|
||||
stashed: "\\$",
|
||||
ahead: "⇡",
|
||||
behind: "⇣",
|
||||
up_to_date: "",
|
||||
diverged: "⇕",
|
||||
conflicted: "=",
|
||||
deleted: "✘",
|
||||
|
@ -18,6 +18,7 @@ const ALL_STATUS_FORMAT: &str = "$conflicted$stashed$deleted$renamed$modified$st
|
||||
/// - `⇡` – 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
|
||||
@ -47,6 +48,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
format_count(config.stashed, "git_status.stashed", count)
|
||||
}),
|
||||
"ahead_behind" => info.get_ahead_behind().and_then(|(ahead, behind)| {
|
||||
let (ahead, behind) = (ahead?, behind?);
|
||||
if ahead > 0 && behind > 0 {
|
||||
format_text(config.diverged, "git_status.diverged", |variable| {
|
||||
match variable {
|
||||
@ -60,7 +62,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
} else if behind > 0 && ahead == 0 {
|
||||
format_count(config.behind, "git_status.behind", behind)
|
||||
} else {
|
||||
None
|
||||
format_symbol(config.up_to_date, "git_status.up_to_date")
|
||||
}
|
||||
}),
|
||||
"conflicted" => info.get_conflicted().and_then(|count| {
|
||||
@ -120,7 +122,7 @@ impl<'a> GitStatusInfo<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ahead_behind(&self) -> Option<(usize, usize)> {
|
||||
pub fn get_ahead_behind(&self) -> Option<(Option<usize>, Option<usize>)> {
|
||||
self.get_repo_status().map(|data| (data.ahead, data.behind))
|
||||
}
|
||||
|
||||
@ -217,8 +219,8 @@ fn get_stashed_count(context: &Context) -> Option<usize> {
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone)]
|
||||
struct RepoStatus {
|
||||
ahead: usize,
|
||||
behind: usize,
|
||||
ahead: Option<usize>,
|
||||
behind: Option<usize>,
|
||||
conflicted: usize,
|
||||
deleted: usize,
|
||||
renamed: usize,
|
||||
@ -271,8 +273,8 @@ impl RepoStatus {
|
||||
let re = Regex::new(r"branch\.ab \+([0-9]+) \-([0-9]+)").unwrap();
|
||||
|
||||
if let Some(caps) = re.captures(s) {
|
||||
self.ahead = caps.get(1).unwrap().as_str().parse::<usize>().unwrap();
|
||||
self.behind = caps.get(2).unwrap().as_str().parse::<usize>().unwrap();
|
||||
self.ahead = caps.get(1).unwrap().as_str().parse::<usize>().ok();
|
||||
self.behind = caps.get(2).unwrap().as_str().parse::<usize>().ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -303,6 +305,10 @@ fn format_count(format_str: &str, config_path: &str, count: usize) -> Option<Vec
|
||||
})
|
||||
}
|
||||
|
||||
fn format_symbol(format_str: &str, config_path: &str) -> Option<Vec<Segment>> {
|
||||
format_text(format_str, config_path, |_variable| None)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ansi_term::{ANSIStrings, Color};
|
||||
@ -450,6 +456,23 @@ mod tests {
|
||||
repo_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_up_to_date_with_upstream() -> io::Result<()> {
|
||||
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
||||
|
||||
let actual = ModuleRenderer::new("git_status")
|
||||
.config(toml::toml! {
|
||||
[git_status]
|
||||
up_to_date="✓"
|
||||
})
|
||||
.path(&repo_dir.path())
|
||||
.collect();
|
||||
let expected = format_output("✓");
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
repo_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shows_conflicted() -> io::Result<()> {
|
||||
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
||||
|
Loading…
Reference in New Issue
Block a user