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

Function install_self_as_hook

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

Copies the [`std::env::current_exe()`] file to `${project_root}/.git/hooks/pre-commit` That's all you need to register a git pre-commit hook. It will silently overwrite the existing git pre-commit hook.

(project_root: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

199///
200/// It will silently overwrite the existing git pre-commit hook.
201pub fn install_self_as_hook(project_root: impl AsRef<Path>) -> Result<()> {
202 let hook_path = project_root
203 .as_ref()
204 .join(".git")
205 .join("hooks")
206 .join("pre-commit")
207 .with_extension(consts::EXE_EXTENSION);
208
209 let me = env::current_exe()?;
210 fs::copy(me, hook_path)?;
211
212 Ok(())
213}
214
215/// Searches for a project root dir, which is a directory that contains
216/// a `.git` dir as its direct child (it should also be the root of

Callers 1

install_hookFunction · 0.85

Calls 1

as_refMethod · 0.80

Tested by

no test coverage detected