2019-08-28 03:11:42 +00:00
|
|
|
use ansi_term::Color;
|
|
|
|
use git2::Repository;
|
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io;
|
|
|
|
use std::process::Command;
|
|
|
|
|
2019-09-05 04:09:51 +00:00
|
|
|
use crate::common::{self, TestCommand};
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
2019-09-05 04:09:51 +00:00
|
|
|
fn shows_behind() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["reset", "--hard", "HEAD^"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(repo_dir)
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2019-09-05 04:09:51 +00:00
|
|
|
let expected = Color::Red.bold().paint(format!("[{}] ", "⇣")).to_string();
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_behind_with_count() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
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();
|
2019-08-28 03:11:42 +00:00
|
|
|
let expected = Color::Red
|
|
|
|
.bold()
|
|
|
|
.paint(format!("[{}] ", "⇣1"))
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
2019-09-05 04:09:51 +00:00
|
|
|
fn shows_ahead() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
.arg("--path")
|
|
|
|
.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<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
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")
|
2019-09-05 04:09:51 +00:00
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
|
|
|
show_sync_count = true
|
|
|
|
})
|
2019-08-28 03:11:42 +00:00
|
|
|
.arg("--path")
|
|
|
|
.arg(repo_dir)
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = Color::Red
|
|
|
|
.bold()
|
|
|
|
.paint(format!("[{}] ", "⇡1"))
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_diverged() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(repo_dir)
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2019-09-05 04:09:51 +00:00
|
|
|
let expected = Color::Red.bold().paint(format!("[{}] ", "⇕")).to_string();
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_diverged_with_count() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
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();
|
2019-08-28 03:11:42 +00:00
|
|
|
let expected = Color::Red
|
|
|
|
.bold()
|
|
|
|
.paint(format!("[{}] ", "⇕⇡1⇣1"))
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_conflicted() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["reset", "--hard", "HEAD^"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
fs::write(repo_dir.join("readme.md"), "# goodbye")?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "."])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["commit", "-m", "Change readme"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["pull", "--rebase"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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_untracked_file() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
File::create(repo_dir.join("license"))?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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(())
|
|
|
|
}
|
|
|
|
|
2019-09-03 00:14:45 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-09-03 00:14:45 +00:00
|
|
|
|
|
|
|
File::create(repo_dir.join("license"))?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["config", "status.showUntrackedFiles", "no"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(repo_dir)
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = "";
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:11:42 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_stashed() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
File::create(repo_dir.join("readme.md"))?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.arg("stash")
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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_modified() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
File::create(repo_dir.join("readme.md"))?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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]
|
2019-09-03 00:14:45 +00:00
|
|
|
fn shows_staged_file() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
File::create(repo_dir.join("license"))?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "."])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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_renamed_file() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["mv", "readme.md", "readme.md.bak"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "-A"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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_deleted_file() -> io::Result<()> {
|
2019-09-07 16:25:01 +00:00
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
fs::remove_file(repo_dir.join("readme.md"))?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.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(())
|
|
|
|
}
|