diff --git a/.claude/settings.json b/.claude/settings.json deleted file mode 100644 index 1c99753..0000000 --- a/.claude/settings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "hooks": { - "PostToolUse": [ - { - "matcher": "Bash", - "hooks": [ - { - "type": "command", - "command": "${CLAUDE_PROJECT_DIR}/.claude/skills/git-why/.claude/hooks/git-commit-reminder.sh", - "args": [] - } - ] - } - ] - } -} diff --git a/.claude/skills/git-why/.claude/hooks/git-commit-reminder.sh b/.claude/skills/git-why/.claude/hooks/git-commit-reminder.sh deleted file mode 100755 index 86547b7..0000000 --- a/.claude/skills/git-why/.claude/hooks/git-commit-reminder.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env bash -# PostToolUse hook (matcher: Bash). -# -# PostToolUse only fires when the matched tool call succeeded -- a failing -# Bash command (e.g. a commit rejected by a pre-commit hook) fires -# PostToolUseFailure instead, which this hook is not registered on. So by the -# time this script runs, any commit in the command has already succeeded; no -# exit-code checking is needed here. -# -# "Was this a git commit" is decided here rather than by an `if` matcher on -# the settings entry. `Bash(git commit *)` needs `git` and `commit` to be -# adjacent, so it misses `git -C dir commit`, `git -c k=v commit` and -# `git --no-pager commit` (#2); loosening it to `Bash(git *commit*)` would -# trade that for false positives like `git log --grep=commit`. Instead, for -# each shell command segment, this skips leading VAR=value assignments, -# requires the word `git`, skips git's own options (and the values of the -# ones that take one), and checks that the subcommand is exactly `commit`. -# -# This script makes no judgment call about whether the commit deserves a -# note -- it only guarantees the reminder fires every time, deterministically. -# The decision of whether to actually write one stays with Claude, per -# SKILL.md's own skip criteria (mechanical changes don't need a note). - -input=$(cat) - -is_commit() { - local segment w i - local -a words - # One segment per ; & | or newline -- crude, but quoting-aware parsing - # isn't needed to find a command word at the start of a segment. - while IFS= read -r segment; do - read -ra words <<<"$segment" - i=0 - while [ "$i" -lt "${#words[@]}" ] && [[ ${words[$i]} == [A-Za-z_]*=* ]]; do - i=$((i + 1)) - done - [ "${words[$i]:-}" = git ] || continue - i=$((i + 1)) - while [ "$i" -lt "${#words[@]}" ]; do - w=${words[$i]} - case $w in - -C | -c | --git-dir | --work-tree | --namespace | --exec-path | --config-env | --super-prefix) - i=$((i + 2)) ;; - -*) - i=$((i + 1)) ;; - *) - break ;; - esac - done - [ "${words[$i]:-}" = commit ] && return 0 - done < <(tr ';&|' '\n\n\n' <<<"$1") - return 1 -} - -# Without jq the command can't be extracted reliably, so fail open (remind) -# rather than silently dropping the reminder this hook exists to guarantee. -if command -v jq >/dev/null 2>&1; then - cmd=$(jq -r '.tool_input.command // empty' <<<"$input" 2>/dev/null) || cmd= - is_commit "$cmd" || exit 0 -fi - -cat <<'JSON' -{ - "hookSpecificOutput": { - "hookEventName": "PostToolUse", - "additionalContext": "A git commit just succeeded. Check it against the git-why skill's SKILL.md note criteria; skip if mechanical." - } -} -JSON diff --git a/.claude/skills/git-why/.claude/settings.json b/.claude/skills/git-why/.claude/settings.json deleted file mode 100644 index 420d061..0000000 --- a/.claude/skills/git-why/.claude/settings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "hooks": { - "PostToolUse": [ - { - "matcher": "Bash", - "hooks": [ - { - "type": "command", - "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/git-commit-reminder.sh", - "args": [] - } - ] - } - ] - } -} diff --git a/.claude/skills/git-why/.gitignore b/.claude/skills/git-why/.gitignore deleted file mode 100644 index e43b0f9..0000000 --- a/.claude/skills/git-why/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/.claude/skills/git-why/LICENSE b/.claude/skills/git-why/LICENSE deleted file mode 100644 index bb828f2..0000000 --- a/.claude/skills/git-why/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2026 Prateek Sharma - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/.claude/skills/git-why/README.md b/.claude/skills/git-why/README.md deleted file mode 100644 index 23c1e3a..0000000 --- a/.claude/skills/git-why/README.md +++ /dev/null @@ -1,158 +0,0 @@ -# git-why - -A Claude Code skill that captures the design reasoning behind non-trivial -commits as git notes attached to the commit itself. The "why" — rejected -alternatives, constraints that forced an approach, tradeoffs — becomes -retrievable from the terminal forever, independent of the chat that produced -it. - -## Install - -Clone this repo into `.claude/skills/git-why/` inside the target project, -then remove the nested `.git`: - -```bash -git clone .claude/skills/git-why && rm -rf .claude/skills/git-why/.git -``` - -Keep the two commands joined with `&&`. If the clone fails (no network, or -`.claude/skills/git-why` already exists), `rm -rf` must not run: on an -existing clone it would delete that clone's history, including any -unpushed work in it. - -The `rm -rf` step matters if the target project is itself a git repo (the -usual case): without it, `git add` there treats `.claude/skills/git-why` as -an embedded repository and stages a bare gitlink instead of the actual -files — SKILL.md and the scripts silently don't get committed, and the next -person to clone the target project gets an empty directory where the skill -should be, with no error at any point. Deleting `.git` first makes it plain -vendored files that commit normally. - -The resulting path **must** be `.claude/skills/git-why/SKILL.md`. A common -way this silently fails to load is an extra level of nesting, e.g. -`.claude/skills/git-why/git-why/SKILL.md` — double check the clone didn't -create a nested directory. - -### Updating - -With `.git` removed there's nothing to `git pull`. To update, delete the -folder and install again: - -```bash -rm -rf .claude/skills/git-why && git clone .claude/skills/git-why && rm -rf .claude/skills/git-why/.git -``` - -This replaces the folder wholesale, so any local edits to the skill are -lost. Review `git diff .claude/skills/git-why` in the target project before -committing the update. - -### Optional: the commit-reminder hook - -The skill's own `.claude/settings.json` is **not** read when it's installed -under `.claude/skills/` — Claude Code only loads a project's top-level -`.claude/settings.json`. To get the reminder after every commit in the -target project, add this to that file (merging into any existing `hooks`): - -```json -{ - "hooks": { - "PostToolUse": [ - { - "matcher": "Bash", - "hooks": [ - { - "type": "command", - "command": "${CLAUDE_PROJECT_DIR}/.claude/skills/git-why/.claude/hooks/git-commit-reminder.sh" - } - ] - } - ] - } -} -``` - -Pointing at the vendored script, rather than copying it, means updating the -skill also updates the hook. Leave out an `if` condition: the script decides -for itself whether the command was a commit (see below), and -`"if": "Bash(git commit *)"` would hide commits like `git -C dir commit` -from it. The script needs `jq` to read the command; without it, it reminds -after every Bash call rather than never. - -## How it works - -Claude applies this skill proactively: right after a commit that involved -real design reasoning, and whenever you ask "why does this exist" about -existing code. This only happens when Claude is present in the session — -there's no hook or background automation by default, and no retroactive -notes for commits made outside Claude. The full criteria for what warrants a -note, how to write one, and where to put it when a decision spans two files -lives in [SKILL.md](SKILL.md) — that's the canonical source Claude actually -follows; this file just covers install and the lookup tools. - -This repo also ships an optional `PostToolUse` hook -(`.claude/settings.json` and `.claude/hooks/git-commit-reminder.sh`), which -fires that reminder deterministically after every `git commit` instead of -relying on Claude to remember. It's active when this repo is the open -project; other projects opt in as described under -[Install](#optional-the-commit-reminder-hook). The script itself checks -whether a Bash command ran `git commit`, including forms like -`git -C dir commit`, `git -c key=value commit` and `git --no-pager commit`, -while ignoring look-alikes such as `git log --grep=commit` or -`git commit-tree`. - -## Usage - -### `scripts/git-why.sh [line]` - -Find the commit(s) that touched a file (or one line), and print any -reasoning note attached to them. Navigation-first: use it when you already -know the file. - -```bash -scripts/git-why.sh internal/process/lock.go -scripts/git-why.sh internal/process/lock.go 41 -``` - -### `scripts/git-notes-grep.sh [more keywords...]` - -Search every note's text for a keyword (case-insensitive, OR'd together, -matched literally). Recall-first: use it when you remember a concept but not -which file it lives in. - -```bash -scripts/git-notes-grep.sh lock reboot -``` - -### `scripts/git-why-record.sh [path]` - -Coverage check: report which recent commits don't have a reasoning note yet. -Purely mechanical, no AI — just how many commits have piled up since the -last note. It counts the tail only: un-noted commits older than the most -recent note aren't included, so it isn't a total-coverage number. - -```bash -scripts/git-why-record.sh -scripts/git-why-record.sh internal/process/lock.go -``` - -## Caveat: notes don't travel with push/fetch/clone by default - -`git notes` live on a separate ref, `refs/notes/commits`, which is **not** -included in a normal `git push`, `git fetch`, or `git clone`. - -For a solo project this doesn't matter. But the moment a project is shared -or cloned onto another machine, notes must be explicitly pushed and fetched, -or they will silently not show up for a collaborator: - -```bash -git push origin refs/notes/commits -git fetch origin refs/notes/commits:refs/notes/commits -``` - -This is the single most likely thing to confuse someone the first time -notes don't appear after a clone — if you're setting this up on a shared -repo, make sure everyone knows to run the fetch command above. - -## License - -MIT — see [LICENSE](LICENSE). diff --git a/.claude/skills/git-why/SKILL.md b/.claude/skills/git-why/SKILL.md deleted file mode 100644 index b153750..0000000 --- a/.claude/skills/git-why/SKILL.md +++ /dev/null @@ -1,162 +0,0 @@ ---- -name: git-why -description: Capture the design reasoning behind non-trivial commits as git notes attached to the commit itself, so "why" survives long after the chat that produced it is gone. Use this proactively right after any git commit that involved a real design decision — a rejected alternative, a constraint that forced an approach, a tradeoff, a subtle bug fix — not just a summary of what changed. Also use this whenever the user asks "why does this exist", "why was this done this way", or "what was the reasoning behind X" about existing code — look up the answer with the bundled scripts before falling back to searching old chat history. ---- - -# Commit Reasoning Notes - -Git commit messages capture *what* changed. They rarely capture *why* — and when an -agent makes a design decision (rejects an alternative, works around a library -limitation, picks one tradeoff over another), that reasoning usually only exists in -the chat that produced it. Once the chat is gone, so is the reasoning. This skill -attaches that reasoning directly to the commit, using `git notes`, so it's -retrievable from the terminal forever, independent of any chat history. - -## When to write a note - -After making a commit, write a note if — and only if — the change involved -non-obvious reasoning. Good candidates: - -- An approach was chosen specifically because a simpler one didn't work (a library - limitation, a race condition, a platform constraint). -- An alternative was seriously considered and rejected — worth recording *why* it - was rejected, not just that it was. -- A subtle bug fix where the root cause isn't obvious from the diff alone. -- A tradeoff was made deliberately (e.g. simplicity over performance, or vice versa). - -Skip it for mechanical changes: dependency bumps, formatting, straightforward -additions with no real decision behind them, typo fixes. Not every commit needs a -note — a note on every commit is noise, and noise gets ignored. - -## How to write a good note - -Do NOT restate the commit message or summarize the diff — that information is -already in `git log`. A note should answer the question someone will ask while -staring at this code later: **"why is it built this way, and not some other way?"** - -Keep it to a few sentences. Structure, loosely: - -1. The constraint or problem that ruled out the obvious/simpler approach. -2. What was chosen instead, and why it addresses that constraint. -3. (If relevant) what was considered and rejected, in one line — not a full - discussion. - -Write the note with: - -```bash -git notes add -m "" -``` - -If a note already exists on that commit and you need to add to it rather than -replace it: - -```bash -git notes append -m "" -``` - -### Example - -Commit message: `Add per-torrent advisory lock to prevent spawn race` - -Good note: -> Needed to prevent two processes racing to download into the same directory if the -> parent dies between spawning the child and recording its PID. Considered checking -> PID + boot_id alone, but that only detects the race after it's already happened. -> flock is auto-released on any process death (including SIGKILL), so it closes the -> race window itself rather than just detecting it afterward. - -Bad note (just restates the commit): "Added a lock file to prevent two processes -from running at once." - -### Decisions spanning two files: definition vs. call site - -Some decisions involve both a primitive's definition (a lock, a helper function) -and a specific call site that uses it in a particular way. Put the note on the -commit that actually makes the decision — usually the integration/call-site -commit, since the primitive itself is often decision-agnostic (it doesn't know -how it'll be used, only the caller does). - -But the primitive's own file is often the first place someone looks when they ask -"why does this exist" — they're staring at the lock, not the caller. If that's a -likely lookup point, add a short pointer note there too: - -```bash -git notes add -m "See commit for why this is used this way in ." -``` - -That way a file-scoped lookup on the primitive doesn't silently come up empty — it -at least points the reader to where the real reasoning lives, instead of relying -on them to already know to check the caller's commit. - -## How to look up existing reasoning - -Don't rely on memory or chat history to answer "why does this exist" — use the -bundled scripts, which read directly from git. - -**Not sure where the reasoning might be attached — start with `scripts/git-notes-grep.sh`:** - -```bash -scripts/git-notes-grep.sh lock reboot -``` - -Searches the text of every note in the repo for the given keyword(s) -(case-insensitive, OR'd together, matched literally — special characters in a -keyword are treated as plain text, not regex) and prints the matching commits -and their notes — regardless of which file each commit touched. This matters because a note -often lives on the commit that makes a decision, not on every file that decision -affects: e.g. "why we call X this way" may be attached to the commit that adds the -*call site* in Y, not to any commit that touched X's own file. A file-scoped -lookup on X can come up empty even though a perfectly good answer exists -elsewhere. When it's unclear whether the reasoning might live on a caller's commit -rather than the definition's own file, try this first or alongside -`git-why.sh` — not only as a fallback after `git-why.sh` comes up empty. - -**You already have a good guess which commit/file the reasoning lives on — use `scripts/git-why.sh`:** - -```bash -scripts/git-why.sh internal/process/lock.go -scripts/git-why.sh internal/process/lock.go 41 -``` - -Finds the commit(s) that touched that file (or that exact line, if given), and -prints any reasoning note attached to them. This is precise but strictly -file-scoped — it will only ever surface notes on commits that touched the exact -path you query — so treat it as the tool for once you know where to look, not as -a general-purpose "why does this exist" search on its own. - -Prefer these over re-reading old chat transcripts — the notes are the -purpose-built, structured source of truth for "why," and they stay accurate even -after the chat that produced them is long gone. - -**Checking whether notes are falling behind — use `scripts/git-why-record.sh`:** - -```bash -scripts/git-why-record.sh -scripts/git-why-record.sh internal/process/lock.go -``` - -Both scripts above answer "what's the reasoning for X" once a note exists. -This one answers a different question — "are we behind on writing notes at -all" — by reporting every commit newer than the most recent one that already -has a note attached. It's a purely mechanical coverage check (no AI, no note -generation, no side effects), useful for spot-checking that the habit is -actually being kept up. Takes an optional path argument to scope the check -to one file/directory's history instead of the whole branch. The count is -the tail gap since the newest note, not total coverage — un-noted commits -older than that note aren't counted, so a mid-history backfill can make the -number drop sharply without anything older being fixed. - -## Known limitation - -`git notes` live on a separate ref (`refs/notes/commits`) and are **not** included -in a normal `git push` / `git fetch` / `git clone`. For a solo repo this doesn't -matter. If the repo is ever shared or cloned onto another machine, notes need to be -explicitly pushed/fetched: - -```bash -git push origin refs/notes/commits -git fetch origin refs/notes/commits:refs/notes/commits -``` - -Mention this to the user if the project moves from solo to shared, since notes -silently not showing up for a collaborator is a confusing failure mode. diff --git a/.claude/skills/git-why/scripts/git-notes-grep.sh b/.claude/skills/git-why/scripts/git-notes-grep.sh deleted file mode 100755 index 23817b4..0000000 --- a/.claude/skills/git-why/scripts/git-notes-grep.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bash -# Usage: git-notes-grep.sh [more keywords...] -# -# Searches the text of every commit's reasoning note for the given -# keyword(s) (case-insensitive, OR'd together, matched literally -- regex -# metacharacters in a keyword are escaped, not interpreted) and prints -# matching commits, newest first. -# -# Recall-first lookup: use this when you remember a concept ("locking", -# "port exhaustion", "reboot") but not which file or commit it lives in. -# Complements git-why.sh, which is navigation-first (you already know the -# file/line and want the reasoning attached to it). -# -# Notes are read via `git log`'s own %N format placeholder, joined with each -# commit in the same walk, already in newest-first order -- no separate -# `git notes list` call, no accumulating/sorting match arrays. - -set -euo pipefail - -if [[ $# -eq 0 ]]; then - echo "usage: git-notes-grep.sh [more keywords...]" >&2 - exit 1 -fi - -# Escape ERE metacharacters so keywords match literally. No `declare -A` / -# `mapfile` here on purpose -- see the note on 8af5907 (macOS ships bash 3.2, -# which has neither). -escape_regex() { - local s="$1" out="" c i - for (( i = 0; i < ${#s}; i++ )); do - c="${s:i:1}" - case "$c" in - '.'|'*'|'['|']'|'^'|'$'|'+'|'?'|'('|')'|'{'|'}'|'|'|'\') - out+="\\$c" ;; - *) - out+="$c" ;; - esac - done - printf '%s' "$out" -} - -pattern="" -for kw in "$@"; do - escaped=$(escape_regex "$kw") - pattern="${pattern:+${pattern}|}${escaped}" -done - -US=$'\x1f' # field separator between sha / subject / note -RS=$'\x1e' # record separator between commits - -found=0 -while IFS= read -r -d "$RS" record; do - record="${record#$'\n'}" # strip the newline git appends after each record - sha="${record%%"$US"*}" - rest="${record#*"$US"}" - subject="${rest%%"$US"*}" - note="${rest#*"$US"}" - note="${note%$'\n'}" # %N appends one trailing newline when a note exists - - [[ -z "$note" ]] && continue - if grep -qiE "$pattern" <<<"$note"; then - found=1 - echo "commit ${sha:0:9} -- $subject" - echo "$note" | sed 's/^/ /' - echo - fi -done < <(git log --format="%H${US}%s${US}%N${RS}") - -if [[ "$found" -eq 0 ]]; then - echo "no notes matched: $*" -fi diff --git a/.claude/skills/git-why/scripts/git-why-record.sh b/.claude/skills/git-why/scripts/git-why-record.sh deleted file mode 100755 index 88b2a40..0000000 --- a/.claude/skills/git-why/scripts/git-why-record.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env bash -# Usage: git-why-record.sh [path] -# -# Coverage check, not a lookup: walks commit history from newest to oldest -# and reports every commit newer than the most recent one that already has a -# reasoning note attached -- "the gap" since notes were last kept up to date. -# -# That count is the tail gap only, not total coverage: un-noted commits older -# than the most recent note (e.g. gaps left behind a mid-history backfill) -# aren't counted, and the output says so, so the number isn't misread as -# "total commits without notes" (#1). -# -# Purely mechanical: no AI, no note generation, no side effects. Answers "are -# we behind on notes?" -- distinct from git-why.sh ("what's the reasoning for -# this file/line?") and git-notes-grep.sh ("which commit has a note about -# this concept?"). -# -# With no argument, walks the whole current branch. Pass a path to scope the -# walk to commits touching that file/directory instead. -# -# Notes are read via `git log`'s own %N format placeholder, joined with each -# commit in the same walk -- no separate `git notes list` call, no bash-side -# set-building. The walk stops at the first noted commit it finds, so on a -# repo with no notes fetched at all, this still reads the full history (there -# is nothing to stop early on), but does it in one `git log` process rather -# than forking git once per commit. - -set -euo pipefail - -path="${1:-}" -max_print=20 - -US=$'\x1f' # field separator between sha / subject / note -RS=$'\x1e' # record separator between commits - -log_args=(--format="%H${US}%s${US}%N${RS}") -if [[ -n "$path" ]]; then - log_args+=(-- "$path") -fi - -any=0 -gap=() -last_noted="" -last_noted_line="" -while IFS= read -r -d "$RS" record; do - record="${record#$'\n'}" # strip the newline git appends after each record - sha="${record%%"$US"*}" - rest="${record#*"$US"}" - subject="${rest%%"$US"*}" - note="${rest#*"$US"}" - note="${note%$'\n'}" # %N appends one trailing newline when a note exists - - any=1 - if [[ -n "$note" ]]; then - last_noted="$sha" - last_noted_line="${sha:0:9} -- ${subject}" - break - fi - gap+=("${sha:0:9} ${subject}") -done < <(git log "${log_args[@]}") - -if [[ "$any" -eq 0 ]]; then - echo "no commit history found${path:+ for $path}" - exit 0 -fi - -if [[ -z "$last_noted" ]]; then - echo "no notes found in this repo's history -- nothing to compare against" - exit 0 -fi - -if [[ ${#gap[@]} -eq 0 ]]; then - echo "up to date -- the newest commit already has a reasoning note" - echo "0 commits since the last note" - exit 0 -fi - -printed=0 -for entry in "${gap[@]}"; do - if [[ "$printed" -ge "$max_print" ]]; then - break - fi - echo "$entry" - printed=$((printed + 1)) -done - -total=${#gap[@]} -if [[ "$total" -gt "$max_print" ]]; then - echo "... and $((total - max_print)) more not shown" -fi - -echo -echo "$total commits since the last note (last noted: $last_noted_line)" -echo "tail only -- un-noted commits older than that note aren't counted" diff --git a/.claude/skills/git-why/scripts/git-why.sh b/.claude/skills/git-why/scripts/git-why.sh deleted file mode 100755 index a30303f..0000000 --- a/.claude/skills/git-why/scripts/git-why.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash -# Usage: git-why.sh [line] -# -# Finds the commit(s) that touched a file (or one specific line, if given) -# and prints the reasoning note attached to each one, if any. -# -# git log/blame answer "what changed and when" -- this answers "why". -# -# Notes are read via `git log`'s own %N format placeholder, which joins each -# commit with its note (empty if none) in the same process that walks -# history -- no separate `git notes list`/`git notes show` call, no bash-side -# matching. %N follows core.notesRef the same way `git notes show` does, so -# behavior doesn't diverge for a repo using a non-default notes ref. - -set -euo pipefail - -if [[ $# -eq 0 ]]; then - echo "usage: git-why.sh [line]" >&2 - exit 1 -fi - -file="$1" -line="${2:-}" - -US=$'\x1f' # field separator between sha / subject / note -RS=$'\x1e' # record separator between commits - -if [[ -n "$line" ]]; then - sha=$(git blame -L "${line},${line}" --porcelain -- "$file" 2>/dev/null | head -1 | cut -d' ' -f1) - if [[ -z "$sha" ]]; then - echo "could not blame ${file}:${line} -- check the file and line number" >&2 - exit 1 - fi - - info=$(git log -1 --format="%s${US}%N" "$sha") - subject="${info%%"$US"*}" - note="${info#*"$US"}" - note="${note%$'\n'}" # %N appends one trailing newline when a note exists - - found=0 - if [[ -n "$note" ]]; then - found=1 - echo "commit ${sha:0:9} -- $subject" - echo "$note" | sed 's/^/ /' - echo - fi - - if [[ "$found" -eq 0 ]]; then - echo "no reasoning note found for ${file}:${line}" - fi -else - any=0 - found=0 - while IFS= read -r -d "$RS" record; do - record="${record#$'\n'}" # strip the newline git appends after each record - sha="${record%%"$US"*}" - rest="${record#*"$US"}" - subject="${rest%%"$US"*}" - note="${rest#*"$US"}" - note="${note%$'\n'}" - - any=1 - if [[ -n "$note" ]]; then - found=1 - echo "commit ${sha:0:9} -- $subject" - echo "$note" | sed 's/^/ /' - echo - fi - done < <(git log --format="%H${US}%s${US}%N${RS}" -- "$file") - - if [[ "$any" -eq 0 ]]; then - echo "no history found for $file -- check the path" >&2 - exit 1 - fi - - if [[ "$found" -eq 0 ]]; then - echo "no reasoning note found for $file" - fi -fi