Skip to content

feat: exit code semantics for CI and git hook integration #1

Closed

Description

@machado144

Summary

Currently dupehound scan exits with code 0 regardless of whether clones are found or not. This makes it impossible to use as a git pre-commit hook or CI gate — tools that block on non-zero exit cannot act on the result.

The fix is straightforward: exit 1 when clones are detected, 0 when the codebase is clean, and 2 on a tool/configuration error. An escape hatch flag --exit-zero should be provided for reporting pipelines that should never fail the pipeline regardless of findings.

Exit code contract

Situation Exit code
No clones found 0
Clones found 1
Tool error (bad path, invalid format, etc.) 2
--exit-zero flag present always 0

Motivation

# pre-commit hook — blocks commit if duplicates exist
dupehound scan --path . --min-tokens 50
# exits 1 → commit blocked, developer sees the report

# CI reporting step — never fails the pipeline, just reports
dupehound scan --path . --format json --output report.json --exit-zero

Implementation checklist

Core

  • actions/scan.go: return a typed sentinel error (e.g. ErrClonesFound) when report.TotalClones > 0
  • helpers/errors.go: add ErrClonesFound sentinel
  • main.go: map ErrClonesFound → exit code 1, other errors → exit code 2, success → 0
  • flags.go: add --exit-zero boolean flag
  • actions/scan.go: respect --exit-zero (suppress ErrClonesFound when set)

Tests

  • integration/cli_test.go: assert exit code 1 when duplicates are found
  • integration/cli_test.go: assert exit code 0 when no duplicates found
  • integration/cli_test.go: assert exit code 0 with --exit-zero even when clones exist
  • integration/cli_test.go: assert exit code 2 (or non-zero) on bad --path

Docs / DX

  • README.md: document exit codes in a table
  • README.md: add pre-commit hook snippet
  • README.md: add GitHub Actions step example

Build & quality

  • make test passes (all unit + integration tests green)
  • lefthook pre-commit passes (gofumpt, govet, golangci-lint, structlint)
  • No regressions in existing tests

Activity

  1. added 2 commits that reference this issue on Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址