use git2::{Repository, Signature};
use predicates::prelude::*;
use predicates::str::contains;
use std::fs;
use std::path::Path;
use tempfile::TempDir;
fn repo_with_uncommitted_changes() -> TempDir {
let dir = TempDir::new().unwrap();
let repo = Repository::init(dir.path()).unwrap();
let sig = Signature::now("T", "t@e.com").unwrap();
fs::write(dir.path().join("a.txt"), "original\n").unwrap();
fs::write(dir.path().join("untouched.txt"), "stable\n").unwrap();
let mut idx = repo.index().unwrap();
idx.add_path(Path::new("a.txt")).unwrap();
idx.add_path(Path::new("untouched.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(dir.path().join("a.txt"), "MODIFIED\n").unwrap();
fs::write(dir.path().join("b.txt"), "new file\n").unwrap();
dir
}
#[test]
fn changeset_tree_lists_only_changed_files() {
let dir = repo_with_uncommitted_changes();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("gnaw");
cmd.current_dir(dir.path())
.arg(".")
.args(["--diff", "--diff-mode", "all"])
.args(["-O", "-", "--no-clipboard", "--quiet"])
.assert()
.success()
.stdout(contains("a.txt"))
.stdout(contains("b.txt"))
.stdout(contains("untouched.txt").not())
.stdout(contains("MODIFIED"));
}