Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/cli/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func buildHookBody(strict bool) string {
if strict {
lint = "ccg lint --strict"
}
return "\n" + hookGuardBegin + "\nccg build . && ccg docs && " + lint + "\n" + hookGuardEnd + "\n"
// Use the incremental update on commit: it re-parses only the changed files (fast) and
// preserves graph state, whereas a full build re-parses the whole repo every commit.
return "\n" + hookGuardBegin + "\nccg update . && ccg docs && " + lint + "\n" + hookGuardEnd + "\n"
}

// newHooksCmd creates the top-level hooks command group.
Expand Down Expand Up @@ -49,7 +51,7 @@ func newHooksInstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install",
Short: "Install ccg pre-commit git hook",
Long: `Install a pre-commit hook that runs "ccg build && ccg docs && ccg lint".
Long: `Install a pre-commit hook that runs "ccg update && ccg docs && ccg lint".

Use --strict to block commits when lint finds issues.
If a pre-commit hook already exists, the ccg block is appended (idempotent).`,
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestHooksInstall_CreatesPreCommitHook(t *testing.T) {
}

hook := string(content)
for _, want := range []string{"#!/bin/sh", "ccg build", "ccg docs", "ccg lint"} {
for _, want := range []string{"#!/bin/sh", "ccg update", "ccg docs", "ccg lint"} {
if !strings.Contains(hook, want) {
t.Errorf("expected %q in hook, got:\n%s", want, hook)
}
Expand Down Expand Up @@ -106,8 +106,8 @@ func TestHooksInstall_ExistingHook_AppendsWithGuard(t *testing.T) {
if !strings.Contains(hook, "existing hook") {
t.Errorf("expected original hook content to be preserved")
}
if !strings.Contains(hook, "ccg build") {
t.Errorf("expected ccg build to be appended")
if !strings.Contains(hook, "ccg update") {
t.Errorf("expected ccg update to be appended")
}
}

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

// Should not have duplicate ccg blocks
hook := string(content)
first := strings.Index(hook, "ccg build")
last := strings.LastIndex(hook, "ccg build")
first := strings.Index(hook, "ccg update")
last := strings.LastIndex(hook, "ccg update")
if first != last {
t.Errorf("ccg build appears multiple times in hook (not idempotent):\n%s", hook)
t.Errorf("ccg update appears multiple times in hook (not idempotent):\n%s", hook)
}
}
Loading