{
  "id": 292848,
  "title": "I \"Verified Live\" the Same Git Hook Fix Three Times. I Never Once Let Git Decide Whether to Run It.",
  "url": "https://urgent.news/2026/08/08/i-verified-live-the-same-git-hook-fix-three-times-i-never-once-let",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-08T03:47:47.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/enjoy_kumawat/i-verified-live-the-same-git-hook-fix-three-times-i-never-once-let-git-decide-whether-to-run-it-hdo"
  },
  "original_language": "en",
  "account": "This repository has a prepare-commit-msg hook that utilizes a local script to generate commit messages. This hook has been corrected three times: initially due to lack of installation, another time because of incorrect directory depth in path arithmetic, and finally because a fix for one installation method disrupted the other. Each correction was followed by the statement \"verified live\" and a successful reproduction.\n\n\"Verified live\" practically means replicating the hook script's required context — the working directory and what $0 would resolve to — and then directly invoking the script using: os.chdir(\"/some/other/repo\") subprocess.run([\"/path/to/hooks/prepare-commit-msg\", \"/tmp/COMMIT_EDITMSG\"])\n\nThis method effectively tests path-resolution logic and successfully identified the three bugs. However, it doesn't equate to running git commit and determining if the hook script gets invoked. These are two distinct questions, with only one being addressed.\n\nUpon checking the file's executable bit, it was found to be non-executable. This fact remained constant despite the three path-resolution fixes since none of them included a reason to consider file permissions. A fresh clone obtained the mode exactly as committed, and these fixes were solely focused on string arithmetic.\n\nTo verify the actual behavior, a scratch clone was created. After cloning and setting up the hooksPath, a test file was added, committed, and the error message was displayed indicating the hook was ignored because it was not executable. The message was then aborted due to the empty commit message, indicating that the hook's logic was never executed.\n\nThis occurred because the initial installation method, recommended in the README, directly links to the tracked hooks directory, bypassing any potential issues with file permissions. The other documented method, while not affected by the path-resolution fixes, also doesn't face this issue because it includes a chmod +x, which runs unconditionally on the copy and compensates for the bug in the source file's permissions.\n\nTherefore, while two install methods exist, one is functionally flawless and the other is not, solely due to the executable bit. The fixes were found to be effective in diagnosing and resolving specific bugs within the hook script but failed to address the permission gate issue.\n\nThe issue with the missing executable bit highlights the distinction between a git hook and a plain script. The testing of a git hook by directly calling it, skips the critical part where git decides to invoke it. This underscores the necessity to consider the executable bit when testing git hooks, rather than just assuming it's sufficient to run the script itself.",
  "summary": "This repo has a prepare-commit-msg hook that shells out to a local script and asks a model to write the commit message. It has been fixed, in this exact same file, three separate times: once because it was never installed at all, once because its path arithmetic assumed the wrong directory depth, once because a fix for one install method broke the other. Every one of those three writeups ends…",
  "key_points": [
    "Verified live three times, each fix identified specific bug",
    "Executable bit remained non-executable throughout fixes",
    "Initial method bypassed permission issue, second method included chmod +x"
  ],
  "editors_take": "Directly invoking a git hook script to test it bypasses git's permission checks, which can wrongly suggest the hook works when its executable bit is not set, a crucial consideration for correct functionality.",
  "illustration": "https://urgent.news/ill/292848.png",
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}