use git2::{Repository, Signature};
use predicates::str::contains;
use std::fs;
use std::path::Path;
use tempfile::TempDir;
fn repo_with_unstaged_change() -> TempDir {
let dir = TempDir::new().unwrap();
let repo = Repository::init(dir.path()).unwrap();
let sig = Signature::now("T", "t@e.com").unwrap();
let file = dir.path().join("a.txt");
fs::write(&file, "original\n").unwrap();
let mut idx = repo.index().unwrap();
idx.add_path(Path::new("a.txt")).unwrap();
idx.write().unwrap();
let tree = repo.find_tree(idx.write_tree().unwrap()).unwrap();
repo.commit(Some("HEAD"), &sig, &sig, "init", &tree, &[])
.unwrap();
fs::write(&file, "MODIFIED LINE\n").unwrap();
dir
}
#[test]
fn diff_flag_includes_working_tree_diff() {
let dir = repo_with_unstaged_change();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("gnaw");
cmd.current_dir(dir.path())
.arg(".")
.args(["--diff", "--diff-mode", "unstaged"])
.args(["-O", "-", "--no-clipboard", "--quiet"])
.assert()
.success()
.stdout(contains("MODIFIED LINE")) .stdout(contains("original")); }