Repository: o0Ignition0o/cargo-scout (language: rust)

Issue:
Run cargo-scout on unstaged added files
Currently, cargo-scout is able to run on the staged modifed and added files, but only on the unstaged modified files (since the unstaged added files are created as untracked).

This behaviour is a bit incoherent with clippy's usage, where even untracked files are checked.

Ideally, we'd need clippy to run on untracked files.
The problem is that `git diff` cannot check untracked files as is.


Discussion / hints:
That's a great idea!

It seems like we can get a list of untracked files [using git ls-files](https://stackoverflow.com/questions/33254470/show-untracked-files-as-git-diff?lq=1)

It would definitely add some consistency ! 🎉 
Just got tricked while running cargo-scout while preparing #48 (Forgot to git add everything...) 

Fix patch:
diff --git a/src/git.rs b/src/git.rs
index 79ae7dd..6fec30e 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -16,7 +16,10 @@ where
     let repo = Repository::discover(repo_path)?;
     let tree = repo.revparse_single(branch)?.peel_to_tree()?;
     let mut config = DiffOptions::default();
-    config.context_lines(0);
+    config
+        .context_lines(0)
+        .show_untracked_content(true)
+        .recurse_untracked_dirs(true);
 
     let diff = repo.diff_tree_to_workdir_with_index(Some(&tree), Some(&mut config))?;
     let mut sections = Vec::new();
@@ -26,7 +29,7 @@ where
         None,
         Some(&mut |delta, hunk| {
             match delta.status() {
-                Delta::Modified | Delta::Added => {
+                Delta::Modified | Delta::Added | Delta::Untracked => {
                     if let Some(file_path) = delta.new_file().path() {
                         let file_path = file_path.to_string_lossy().to_string();
 
@@ -62,7 +65,7 @@ mod tests {
     fn no_changes() -> Result<()> {
         let repo = RepoFixture::new()?;
 
-        let sections = get_sections(repo.path(), "master").unwrap();
+        let sections = get_sections(repo.path(), "master")?;
         assert!(sections.is_empty());
         Ok(())
     }
@@ -86,7 +89,30 @@ mod tests {
                 line_end: 7,
             },
         ];
-        let actual = get_sections(repo.path(), "master").unwrap();
+        let actual = get_sections(repo.path(), "master")?;
+        assert_eq!(expected, actual);
+        Ok(())
+    }
+
+    #[test]
+    fn untracked_files() -> Result<()> {
+        let repo = RepoFixture::new()?
+            .write("foo.rs", "test_files/git/added/foo.rs")?
+            .write("inside/some/dir/bar.rs", "test_files/git/added/bar.rs")?;
+
+        let expected = vec![
+            Section {
+                file_name: "foo.rs".into(),
+                line_start: 1,
+                line_end: 7,
+            },
+            Section {
+                file_name: "inside/some/dir/bar.rs".into(),
+                line_start: 1,
+                line_end: 5,
+            },
+        ];
+        let actual = get_sections(repo.path(), "master")?;
         assert_eq!(expected, actual);
         Ok(())
     }
@@ -124,7 +150,7 @@ mod tests {
                 line_end: 7,
             },
         ];
-        let actual = get_sections(repo.path(), "master").unwrap();
+        let actual = get_sections(repo.path(), "master")?;
         assert_eq!(expected, actual);
         Ok(())
     }
@@ -141,7 +167,7 @@ mod tests {
             line_start: 1,
             line_end: 7,
         }];
-        let actual = get_sections(repo.path(), "master").unwrap();
+        let actual = get_sections(repo.path(), "master")?;
         assert_eq!(expected, actual);
         Ok(())
     }
@@ -167,7 +193,7 @@ mod tests {
                 line_end: 7,
             },
         ];
-        let actual = get_sections(repo.path(), "other").unwrap();
+        let actual = get_sections(repo.path(), "other")?;
         assert_eq!(expected, actual);
         Ok(())
     }
@@ -196,7 +222,10 @@ mod tests {
             Ok(RepoFixture { dir, repo })
         }
 
-        pub fn write(self, path: &str, test_file: &str) -> Result<Self> {
+        pub fn write<P: AsRef<Path>>(self, path: P, test_file: &str) -> Result<Self> {
+            let parent_dir = path.as_ref().parent().unwrap();
+            fs::create_dir_all(self.dir.path().join(parent_dir))?;
+
             let contents = fs::read_to_string(test_file)?;
             let mut file = File::create(self.dir.path().join(path))?;
             file.write_all(contents.as_bytes())?;


Test patch: