From 8d1cc3eec683546af1c5c14fea373687dd881fa5 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 29 Mar 2020 16:03:35 +0200 Subject: [PATCH] test resetting workdir part of untracked stages file --- asyncgit/src/sync/reset.rs | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/asyncgit/src/sync/reset.rs b/asyncgit/src/sync/reset.rs index b6b496e0..cdfd8015 100644 --- a/asyncgit/src/sync/reset.rs +++ b/asyncgit/src/sync/reset.rs @@ -195,4 +195,52 @@ mod tests { 0 ); } + + #[test] + fn test_reset_untracked_in_subdir_and_index() { + let (_td, repo) = repo_init(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + let file = "foo/bar.txt"; + + { + fs::create_dir(&root.join("foo")).unwrap(); + File::create(&root.join(file)) + .unwrap() + .write_all(b"test\nfoo") + .unwrap(); + } + + debug_cmd_print(repo_path, "git status"); + + debug_cmd_print(repo_path, "git add ."); + + debug_cmd_print(repo_path, "git status"); + + { + File::create(&root.join(file)) + .unwrap() + .write_all(b"test\nfoo\nnewend") + .unwrap(); + } + + debug_cmd_print(repo_path, "git status"); + + assert_eq!(get_status(repo_path, StatusType::Stage).len(), 1); + assert_eq!( + get_status(repo_path, StatusType::WorkingDir).len(), + 1 + ); + + let res = reset_workdir(repo_path, Path::new(file)); + assert_eq!(res, true); + + debug_cmd_print(repo_path, "git status"); + + assert_eq!( + get_status(repo_path, StatusType::WorkingDir).len(), + 0 + ); + assert_eq!(get_status(repo_path, StatusType::Stage).len(), 1); + } }