2019-10-26 06:20:20 +00:00
|
|
|
use ansi_term::{ANSIStrings, Color};
|
2020-03-15 17:12:25 +00:00
|
|
|
use remove_dir_all::remove_dir_all;
|
2019-08-28 03:11:42 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io;
|
2019-10-26 06:20:20 +00:00
|
|
|
use std::path::PathBuf;
|
2019-08-28 03:11:42 +00:00
|
|
|
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
|
|
|
|
2019-10-15 15:10:16 +00:00
|
|
|
/// Right after the calls to git the filesystem state may not have finished
|
|
|
|
/// updating yet causing some of the tests to fail. These barriers are placed
|
|
|
|
/// after each call to git.
|
|
|
|
/// This barrier is windows-specific though other operating systems may need it
|
|
|
|
/// in the future.
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
fn barrier() {}
|
|
|
|
#[cfg(windows)]
|
|
|
|
fn barrier() {
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
|
|
|
}
|
|
|
|
|
2020-07-07 22:45:32 +00:00
|
|
|
fn format_output(symbols: &str) -> String {
|
|
|
|
format!("{} ", Color::Red.bold().paint(format!("[{}]", symbols)))
|
|
|
|
}
|
|
|
|
|
2020-04-15 07:55:32 +00:00
|
|
|
#[test]
|
|
|
|
fn show_nothing_on_empty_dir() -> io::Result<()> {
|
|
|
|
let repo_dir = tempfile::tempdir()?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(repo_dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = "";
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
repo_dir.close()
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
behind(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇣");
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
behind(&repo_dir)?;
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
behind = "⇣$count"
|
2019-09-05 04:09:51 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇣1");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-15 15:10:16 +00:00
|
|
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
2019-10-26 06:20:20 +00:00
|
|
|
ahead(&repo_dir)?;
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇡");
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-15 15:10:16 +00:00
|
|
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
2019-10-26 06:20:20 +00:00
|
|
|
ahead(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
2019-09-05 04:09:51 +00:00
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
ahead="⇡$count"
|
2019-09-05 04:09:51 +00:00
|
|
|
})
|
2019-08-28 03:11:42 +00:00
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇡1");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
diverge(&repo_dir)?;
|
2019-10-15 15:10:16 +00:00
|
|
|
|
2019-08-28 03:11:42 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇕");
|
2019-09-05 04:09:51 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
diverge(&repo_dir)?;
|
2019-10-15 15:10:16 +00:00
|
|
|
|
2019-09-05 04:09:51 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
diverged=r"⇕⇡$ahead_count⇣$behind_count"
|
2019-09-05 04:09:51 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-09-05 04:09:51 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("⇕⇡1⇣1");
|
2019-08-28 03:11:42 +00:00
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_conflict(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
2019-10-26 06:20:20 +00:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("=");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
assert_eq!(expected, actual);
|
2019-10-15 15:10:16 +00:00
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_conflicted_with_count() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_conflict(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
2019-10-26 06:20:20 +00:00
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
conflicted = "=$count"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
2019-08-28 03:11:42 +00:00
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("=1");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_untracked(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("?");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_untracked_file_with_count() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_untracked(&repo_dir)?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
untracked = "?$count"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("?1");
|
2019-10-26 06:20:20 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_untracked(&repo_dir)?;
|
2019-09-03 00:14:45 +00:00
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["config", "status.showUntrackedFiles", "no"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
2019-10-15 15:10:16 +00:00
|
|
|
barrier();
|
2019-09-03 00:14:45 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-09-03 00:14:45 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = "";
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-09-03 00:14:45 +00:00
|
|
|
}
|
|
|
|
|
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-10-15 15:10:16 +00:00
|
|
|
barrier();
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-12-29 03:20:36 +00:00
|
|
|
create_stash(&repo_dir)?;
|
2019-10-15 15:10:16 +00:00
|
|
|
|
|
|
|
Command::new("git")
|
2019-12-29 03:20:36 +00:00
|
|
|
.args(&["reset", "--hard", "HEAD"])
|
2019-10-15 15:10:16 +00:00
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-12-29 03:20:36 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-12-29 03:20:36 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("$");
|
2019-12-29 03:20:36 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-12-29 03:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shows_stashed_with_count() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
create_stash(&repo_dir)?;
|
|
|
|
barrier();
|
|
|
|
|
2019-08-28 03:11:42 +00:00
|
|
|
Command::new("git")
|
2019-10-15 15:10:16 +00:00
|
|
|
.args(&["reset", "--hard", "HEAD"])
|
2019-08-28 03:11:42 +00:00
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
2019-10-15 15:10:16 +00:00
|
|
|
barrier();
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
2019-12-29 03:20:36 +00:00
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
stashed = r"\$$count"
|
2019-12-29 03:20:36 +00:00
|
|
|
})
|
2019-08-28 03:11:42 +00:00
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("$1");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_modified(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("!");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
2019-10-26 06:20:20 +00:00
|
|
|
fn shows_modified_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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_modified(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
modified = "!$count"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
2019-10-26 06:20:20 +00:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("!1");
|
2019-10-26 06:20:20 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_staged_file() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_staged(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("+");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
2019-10-26 06:20:20 +00:00
|
|
|
fn shows_staged_file_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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_staged(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
staged = "+[$count](green)"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
2019-10-26 06:20:20 +00:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let expected = format!(
|
2020-07-07 22:45:32 +00:00
|
|
|
"{} ",
|
2019-10-26 06:20:20 +00:00
|
|
|
ANSIStrings(&[
|
|
|
|
Color::Red.bold().paint("[+"),
|
|
|
|
Color::Green.paint("1"),
|
2020-07-07 22:45:32 +00:00
|
|
|
Color::Red.bold().paint("]"),
|
2019-10-26 06:20:20 +00:00
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_renamed_file() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_renamed(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("»");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_renamed_file_with_count() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_renamed(&repo_dir)?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
renamed = "»$count"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("»1");
|
2019-10-26 06:20:20 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 03:11:42 +00:00
|
|
|
#[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
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
create_deleted(&repo_dir)?;
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("✘");
|
2019-08-28 03:11:42 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-08-28 03:11:42 +00:00
|
|
|
}
|
2019-09-15 20:44:53 +00:00
|
|
|
|
2019-10-26 06:20:20 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn shows_deleted_file_with_count() -> io::Result<()> {
|
|
|
|
let repo_dir = common::create_fixture_repo()?;
|
|
|
|
|
|
|
|
create_deleted(&repo_dir)?;
|
|
|
|
|
|
|
|
let output = common::render_module("git_status")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[git_status]
|
2020-07-07 22:45:32 +00:00
|
|
|
deleted = "✘$count"
|
2019-10-26 06:20:20 +00:00
|
|
|
})
|
|
|
|
.arg("--path")
|
2020-03-15 17:12:25 +00:00
|
|
|
.arg(&repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-07 22:45:32 +00:00
|
|
|
let expected = format_output("✘1");
|
2019-10-26 06:20:20 +00:00
|
|
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
2020-03-15 17:12:25 +00:00
|
|
|
remove_dir_all(repo_dir)
|
2019-10-26 06:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ahead(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["commit", "-am", "Update readme"])
|
|
|
|
.current_dir(&repo_dir)
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn behind(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["reset", "--hard", "HEAD^"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn diverge(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["reset", "--hard", "HEAD^"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
fs::write(repo_dir.join("Cargo.toml"), " ")?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["commit", "-am", "Update readme"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_conflict(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["reset", "--hard", "HEAD^"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
fs::write(repo_dir.join("readme.md"), "# goodbye")?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "."])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["commit", "-m", "Change readme"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["pull", "--rebase"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
2019-12-29 03:20:36 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_stash(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["stash", "--all"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
2019-10-26 06:20:20 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_untracked(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
File::create(repo_dir.join("license"))?.sync_all()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_modified(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_staged(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
File::create(repo_dir.join("license"))?.sync_all()?;
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "."])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_renamed(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["mv", "readme.md", "readme.md.bak"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Command::new("git")
|
|
|
|
.args(&["add", "-A"])
|
|
|
|
.current_dir(repo_dir.as_path())
|
|
|
|
.output()?;
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_deleted(repo_dir: &PathBuf) -> io::Result<()> {
|
|
|
|
fs::remove_file(repo_dir.join("readme.md"))?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|