{"record":{"id":"feafe357de187d3b","repo":"nikivdev/code","slug":"refusing-to-overwrite-non-flow-hook-at-re-run","errorCode":null,"errorMessage":"Refusing to overwrite non-Flow hook at {}.\nRe-run with `f push hooks install --force` to replace it.","messagePattern":"Refusing to overwrite non-Flow hook at (.+?)\\.\nRe-run with `f push hooks install --force` to replace it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/push_hook.rs","lineNumber":88,"sourceCode":"pub fn install_hooks(force: bool) -> Result<()> {\n    let hooks_path = push_policy::effective_global_hooks_path()?;\n    let current_hooks_path = current_global_hooks_path()?;\n\n    if let Some(current) = current_hooks_path.as_ref()\n        && normalize_path(current) != normalize_path(&hooks_path)\n        && !force\n    {\n        bail!(\n            \"Global core.hooksPath already points to {}.\\nRe-run with `f push hooks install --force` to overwrite it.\",\n            current.display()\n        );\n    }\n\n    fs::create_dir_all(&hooks_path)\n        .with_context(|| format!(\"failed to create {}\", hooks_path.display()))?;\n    let hook_path = hooks_path.join(\"pre-push\");\n    if hook_path.exists() && !is_flow_managed_hook(&hook_path)? && !force {\n        bail!(\n            \"Refusing to overwrite non-Flow hook at {}.\\nRe-run with `f push hooks install --force` to replace it.\",\n            hook_path.display()\n        );\n    }\n\n    fs::write(&hook_path, render_pre_push_hook_script())\n        .with_context(|| format!(\"failed to write {}\", hook_path.display()))?;\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::PermissionsExt;\n        let mut perms = fs::metadata(&hook_path)?.permissions();\n        perms.set_mode(0o755);\n        fs::set_permissions(&hook_path, perms)?;\n    }\n\n    git_config_global_set(\"core.hooksPath\", &hooks_path)?;\n    println!(\"Installed Flow pre-push hook at {}\", hook_path.display());\n    println!(\"Global core.hooksPath -> {}\", hooks_path.display());","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/push_hook.rs#L70-L106","documentation":"Raised by install_hooks in src/push_hook.rs when a pre-push file already exists at the target hook path but does not contain the Flow marker (flow-global-pre-push-hook-v1), and --force was not passed. This protects a user's hand-written or third-party pre-push hook from being silently replaced by the Flow script.","triggerScenarios":"Running `f push hooks install` when <hooks_path>/pre-push exists, is_flow_managed_hook returns false (no Flow marker in the file contents), and force is false.","commonSituations":"A custom pre-push script or another tool's hook (pre-commit framework, husky) already occupies the file; a partially edited Flow hook lost its marker line; reinstalling after switching hook managers.","solutions":["If replacement is intended, re-run with `f push hooks install --force`","Back up the existing hook (e.g. `mv pre-push pre-push.bak`) and merge its logic into your workflow, then install","Check the file contents to confirm whether it is still needed before forcing an overwrite"],"exampleFix":"// before\n$ f push hooks install\nRefusing to overwrite non-Flow hook at ~/.flow/hooks/pre-push.\n// after\n$ cp ~/.flow/hooks/pre-push ~/.flow/hooks/pre-push.bak\n$ f push hooks install --force","handlingStrategy":"validation","validationCode":"let hook = hooks_dir.join(\"pre-push\");\nif hook.exists() {\n    let content = std::fs::read_to_string(&hook)?;\n    if !content.contains(\"flow-global-pre-push-hook-v1\") {\n        eprintln!(\"existing non-Flow pre-push hook at {}; back it up, then use --force\", hook.display());\n    }\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Refusing to overwrite non-Flow hook\") => {\n        eprintln!(\"back up the hook, merge logic, then re-run with --force\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Inspect <hooks-path>/pre-push before installing","Back up custom hooks and merge their logic into the Flow hook","Keep the Flow marker line intact if editing the hook manually"],"tags":["git-hooks","pre-push","overwrite-protection"],"backgroundTag":"non-managed-hook-conflict","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}