MCPcopy Create free account
hub / github.com/elastio/devx / from_git_diff

Method from_git_diff

devx-pre-commit/src/lib.rs:99–116  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

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> {

Callers

nothing calls this directly

Calls 2

readMethod · 0.80
current_dirMethod · 0.80

Tested by

no test coverage detected