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>)
| 199 | /// |
| 200 | /// It will silently overwrite the existing git pre-commit hook. |
| 201 | pub 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 |