Creates the git pre-commit context acquiring the staged files via running `git diff` in `project_root`. The `project_root` is expected to contain the `.git` dir (see [`locate_project_root`] function for more on that). The staged files are stored in [`PreCommitContext`] as paths relative to `project_root`.
(project_root: impl Into<PathBuf>)
| 97 | /// The staged files are stored in [`PreCommitContext`] as paths relative |
| 98 | /// to `project_root`. |
| 99 | pub fn from_git_diff(project_root: impl Into<PathBuf>) -> Result<Self> { |
| 100 | let project_root = project_root.into(); |
| 101 | let diff = cmd!( |
| 102 | "git", |
| 103 | "diff", |
| 104 | "--diff-filter", |
| 105 | "MAR", |
| 106 | "--name-only", |
| 107 | "--cached" |
| 108 | ) |
| 109 | .current_dir(&project_root) |
| 110 | .read()?; |
| 111 | |
| 112 | Ok(Self { |
| 113 | staged_files: diff.lines().map(PathBuf::from).collect(), |
| 114 | project_root, |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | /// Returns an iterator over all the files staged for the commit. |
| 119 | pub fn staged_files(&self) -> impl Iterator<Item = &Path> { |
nothing calls this directly
no test coverage detected