Skip to main content

install_commit_msg

Function install_commit_msg 

Source
pub fn install_commit_msg(repo_root: &Path, force: bool) -> Result<PathBuf>
Expand description

Install commit-msg for the repository rooted at repo_root. The effective target directory is resolved as follows:

  1. Open the repository via git2::Repository::discover so a linked worktree’s .git file pointer is followed transparently.
  2. If core.hooksPath is set in the repo config (the project’s recommended setup is core.hooksPath = .githooks), resolve it against the workdir and install there. The directory is created if missing.
  3. Otherwise fall back to <gitdir>/hooks/ (where <gitdir> is the worktree’s admin dir — e.g. <main>/.git/worktrees/<name>/ for a linked worktree, or <root>/.git/ for the main worktree).

Returns the written path on success. When force is false (default) and the target file already exists, returns GwmError::Other("commit-msg hook already exists at … — pass --force to overwrite") without touching the file. Bare repos and non-git dirs are rejected with an error; the goal is “fail loudly, leak nothing into the filesystem”.