feat: Add config for ahead/behind count of tracked branch (#281)

Add a configuration option (show_sync_count) to the git_status module that will show/hide the counts ahead/behind of the tracked branch. Currently have this default to false, and would opt-in to show this information.
This commit is contained in:
Neil Kistner
2019-09-04 23:09:51 -05:00
committed by Matan Kushner
parent c5e693b638
commit 1c66869117
3 changed files with 144 additions and 24 deletions
+99 -3
View File
@@ -5,11 +5,11 @@ use std::fs::{self, File};
use std::io;
use std::process::Command;
use crate::common;
use crate::common::{self, TestCommand};
#[test]
#[ignore]
fn shows_behind_count() -> io::Result<()> {
fn shows_behind() -> io::Result<()> {
let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
@@ -25,6 +25,35 @@ fn shows_behind_count() -> io::Result<()> {
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
}
#[test]
#[ignore]
fn shows_behind_with_count() -> io::Result<()> {
let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
Command::new("git")
.args(&["reset", "--hard", "HEAD^"])
.current_dir(repo_dir.as_path())
.output()?;
let output = common::render_module("git_status")
.use_config(toml::toml! {
[git_status]
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red
.bold()
.paint(format!("[{}] ", "⇣1"))
@@ -37,7 +66,7 @@ fn shows_behind_count() -> io::Result<()> {
#[test]
#[ignore]
fn shows_ahead_count() -> io::Result<()> {
fn shows_ahead() -> io::Result<()> {
let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
@@ -55,6 +84,37 @@ fn shows_ahead_count() -> io::Result<()> {
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
}
#[test]
#[ignore]
fn shows_ahead_with_count() -> io::Result<()> {
let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
File::create(repo_dir.join("readme.md"))?;
Command::new("git")
.args(&["commit", "-am", "Update readme"])
.current_dir(&repo_dir)
.output()?;
let output = common::render_module("git_status")
.use_config(toml::toml! {
[git_status]
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red
.bold()
.paint(format!("[{}] ", "⇡1"))
@@ -90,6 +150,42 @@ fn shows_diverged() -> io::Result<()> {
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
}
#[test]
#[ignore]
fn shows_diverged_with_count() -> io::Result<()> {
let fixture_repo_dir = common::create_fixture_repo()?;
let repo_dir = common::new_tempdir()?.path().join("rocket");
Repository::clone(fixture_repo_dir.to_str().unwrap(), &repo_dir.as_path()).unwrap();
Command::new("git")
.args(&["reset", "--hard", "HEAD^"])
.current_dir(repo_dir.as_path())
.output()?;
fs::write(repo_dir.join("Cargo.toml"), " ")?;
Command::new("git")
.args(&["commit", "-am", "Update readme"])
.current_dir(repo_dir.as_path())
.output()?;
let output = common::render_module("git_status")
.use_config(toml::toml! {
[git_status]
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red
.bold()
.paint(format!("[{}] ", "⇕⇡1⇣1"))