Skip to content

Commit 71af242

Browse files
tae2089claude
andcommitted
refactor: rename hooks install --strict to --lint-strict
Avoids confusion with ccg lint --strict by making the hook flag name explicit about what it controls. - ccg hooks install: hook runs ccg lint (report only) - ccg hooks install --lint-strict: hook runs ccg lint --strict (blocks commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e9bb7cb commit 71af242

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

internal/cli/hooks.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import (
1212
const hookGuardBegin = "# --- ccg hook begin ---"
1313
const hookGuardEnd = "# --- ccg hook end ---"
1414

15-
const hookBody = `
16-
` + hookGuardBegin + `
17-
ccg build . && ccg docs && ccg lint --strict
18-
` + hookGuardEnd + `
19-
`
15+
func buildHookBody(strict bool) string {
16+
lint := "ccg lint"
17+
if strict {
18+
lint = "ccg lint --strict"
19+
}
20+
return "\n" + hookGuardBegin + "\nccg build . && ccg docs && " + lint + "\n" + hookGuardEnd + "\n"
21+
}
2022

2123
func newHooksCmd(_ *Deps) *cobra.Command {
2224
hooksCmd := &cobra.Command{
@@ -29,12 +31,14 @@ func newHooksCmd(_ *Deps) *cobra.Command {
2931

3032
func newHooksInstallCmd() *cobra.Command {
3133
var gitDir string
34+
var lintStrict bool
3235

3336
cmd := &cobra.Command{
3437
Use: "install",
3538
Short: "Install ccg pre-commit git hook",
36-
Long: `Install a pre-commit hook that runs "ccg build && ccg docs" on every commit.
39+
Long: `Install a pre-commit hook that runs "ccg build && ccg docs && ccg lint".
3740
41+
Use --strict to block commits when lint finds issues.
3842
If a pre-commit hook already exists, the ccg block is appended (idempotent).`,
3943
Args: cobra.NoArgs,
4044
RunE: func(cmd *cobra.Command, args []string) error {
@@ -66,7 +70,7 @@ If a pre-commit hook already exists, the ccg block is appended (idempotent).`,
6670
content = "#!/bin/sh\n"
6771
}
6872

69-
content += hookBody
73+
content += buildHookBody(lintStrict)
7074

7175
if err := os.WriteFile(hookPath, []byte(content), 0o755); err != nil {
7276
return fmt.Errorf("write pre-commit hook: %w", err)
@@ -78,5 +82,6 @@ If a pre-commit hook already exists, the ccg block is appended (idempotent).`,
7882
}
7983

8084
cmd.Flags().StringVar(&gitDir, "git-dir", "", "Path to the git repository root (default: current directory)")
85+
cmd.Flags().BoolVar(&lintStrict, "lint-strict", false, "Include --strict on ccg lint (blocks commit on issues)")
8186
return cmd
8287
}

internal/cli/hooks_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func TestHooksInstall_CreatesPreCommitHook(t *testing.T) {
3030
t.Errorf("expected %q in hook, got:\n%s", want, hook)
3131
}
3232
}
33+
// Without --strict flag, lint should NOT have --strict
34+
if strings.Contains(hook, "--strict") {
35+
t.Errorf("expected no --strict without flag, got:\n%s", hook)
36+
}
3337

3438
// Hook must be executable
3539
info, err := os.Stat(hookPath)
@@ -41,6 +45,29 @@ func TestHooksInstall_CreatesPreCommitHook(t *testing.T) {
4145
}
4246
}
4347

48+
func TestHooksInstall_StrictFlag(t *testing.T) {
49+
repoDir := t.TempDir()
50+
if err := os.MkdirAll(filepath.Join(repoDir, ".git", "hooks"), 0o755); err != nil {
51+
t.Fatal(err)
52+
}
53+
54+
deps, stdout, stderr := newTestDeps()
55+
if err := executeCmd(deps, stdout, stderr, "hooks", "install", "--git-dir", repoDir, "--lint-strict"); err != nil {
56+
t.Fatalf("unexpected error: %v", err)
57+
}
58+
59+
hookPath := filepath.Join(repoDir, ".git", "hooks", "pre-commit")
60+
content, err := os.ReadFile(hookPath)
61+
if err != nil {
62+
t.Fatalf("expected pre-commit hook at %s: %v", hookPath, err)
63+
}
64+
65+
hook := string(content)
66+
if !strings.Contains(hook, "ccg lint --strict") {
67+
t.Errorf("expected 'ccg lint --strict' in hook, got:\n%s", hook)
68+
}
69+
}
70+
4471
func TestHooksInstall_NoGitDir_Fails(t *testing.T) {
4572
repoDir := t.TempDir()
4673
// No .git directory

0 commit comments

Comments
 (0)