git_rune/git/
hook.rs

1use super::repo::GitRepo;
2use crate::{config::Config, error::Result};
3use std::path::Path;
4
5const HOOK_SCRIPT: &str = r#"#!/bin/sh
6export SKIP_HOOK=1 # Prevent recursive commits
7rune commit
8"#;
9
10pub fn install_hook() -> Result<()> {
11    let repo = GitRepo::open()?;
12    let git_root = repo.root_path().to_path_buf();
13
14    repo.install_hook("commit-msg", HOOK_SCRIPT)?;
15    install_default_config(&git_root)?;
16    repo.setup_commit_template()?;
17
18    println!("Installed git hooks and default configuration successfully");
19    Ok(())
20}
21
22pub fn install_default_config(git_root: &Path) -> Result<()> {
23    let config_path = git_root.join(".rune.yml");
24    if !config_path.exists() {
25        let default_config = Config::default();
26        default_config.save(&config_path)?;
27        println!("Created default configuration file at .rune.yml");
28    }
29    Ok(())
30}