Skip to content

Commit 480a8c1

Browse files
tae2089claude
andauthored
Use incremental update in the pre-commit hook (#6)
The pre-commit hook ran "ccg build ." — a full re-parse of the entire repo on every commit. A commit only changes a few files, so use "ccg update ." which re-parses just the changed files (hash-based) and preserves existing graph state. Verified with the real binary that update builds correctly from an empty graph (first commit) and skips unchanged files on subsequent runs. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent e2d38b3 commit 480a8c1

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

internal/cli/hooks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func buildHookBody(strict bool) string {
2121
if strict {
2222
lint = "ccg lint --strict"
2323
}
24-
return "\n" + hookGuardBegin + "\nccg build . && ccg docs && " + lint + "\n" + hookGuardEnd + "\n"
24+
// Use the incremental update on commit: it re-parses only the changed files (fast) and
25+
// preserves graph state, whereas a full build re-parses the whole repo every commit.
26+
return "\n" + hookGuardBegin + "\nccg update . && ccg docs && " + lint + "\n" + hookGuardEnd + "\n"
2527
}
2628

2729
// newHooksCmd creates the top-level hooks command group.
@@ -49,7 +51,7 @@ func newHooksInstallCmd() *cobra.Command {
4951
cmd := &cobra.Command{
5052
Use: "install",
5153
Short: "Install ccg pre-commit git hook",
52-
Long: `Install a pre-commit hook that runs "ccg build && ccg docs && ccg lint".
54+
Long: `Install a pre-commit hook that runs "ccg update && ccg docs && ccg lint".
5355
5456
Use --strict to block commits when lint finds issues.
5557
If a pre-commit hook already exists, the ccg block is appended (idempotent).`,

internal/cli/hooks_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestHooksInstall_CreatesPreCommitHook(t *testing.T) {
2525
}
2626

2727
hook := string(content)
28-
for _, want := range []string{"#!/bin/sh", "ccg build", "ccg docs", "ccg lint"} {
28+
for _, want := range []string{"#!/bin/sh", "ccg update", "ccg docs", "ccg lint"} {
2929
if !strings.Contains(hook, want) {
3030
t.Errorf("expected %q in hook, got:\n%s", want, hook)
3131
}
@@ -106,8 +106,8 @@ func TestHooksInstall_ExistingHook_AppendsWithGuard(t *testing.T) {
106106
if !strings.Contains(hook, "existing hook") {
107107
t.Errorf("expected original hook content to be preserved")
108108
}
109-
if !strings.Contains(hook, "ccg build") {
110-
t.Errorf("expected ccg build to be appended")
109+
if !strings.Contains(hook, "ccg update") {
110+
t.Errorf("expected ccg update to be appended")
111111
}
112112
}
113113

@@ -134,9 +134,9 @@ func TestHooksInstall_Idempotent(t *testing.T) {
134134

135135
// Should not have duplicate ccg blocks
136136
hook := string(content)
137-
first := strings.Index(hook, "ccg build")
138-
last := strings.LastIndex(hook, "ccg build")
137+
first := strings.Index(hook, "ccg update")
138+
last := strings.LastIndex(hook, "ccg update")
139139
if first != last {
140-
t.Errorf("ccg build appears multiple times in hook (not idempotent):\n%s", hook)
140+
t.Errorf("ccg update appears multiple times in hook (not idempotent):\n%s", hook)
141141
}
142142
}

0 commit comments

Comments
 (0)