-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Problem
The README states:
The install() call is idempotent. It won't modify the existing setup and hooks.
However, the implementation in src/lib.rs uses fs::write() directly without checking if files already exist:
fs::write(
self._hooks_abs_dir(repo_path.as_str()).join("pre-commit"),
r#"#!/bin/sh
. "$(dirname "$0")/_/sloughi.sh"
echo "Running Sloughi pre-commit..."
"#,
)?;fs::write() truncates and overwrites existing files, meaning any custom pre-commit hook content is lost on every cargo build.
Expected Behavior
If a hook file already exists, install() should either:
- Skip writing to that file entirely (true idempotent behavior)
- Only update the
_/sloughi.shhelper while preserving user hooks - Provide an option to force overwrite vs preserve existing
Reproduction
- Add sloughi to build-dependencies with
.custom_path(".githooks") - Create a custom
.githooks/pre-commitwith additional logic (fmt, clippy, etc.) - Run
cargo build - Observe that
.githooks/pre-commitis overwritten with the minimal template
Suggested Fix
Check if the file exists before writing:
let pre_commit_path = self._hooks_abs_dir(repo_path.as_str()).join("pre-commit");
if !pre_commit_path.exists() {
fs::write(pre_commit_path, r#"#!/bin/sh..."#)?;
}Or use OpenOptions with create_new(true) to fail if the file exists.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels