From 1b698a12412ac73c8ffcfaf5df9a5e49e79c7501 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 10 Nov 2026 17:49:58 +0000 Subject: [PATCH] Capture committed .env templates instead of skipping them Every run in this repository reported an incomplete file-change capture because the tracked .env.example matched the secret-file rules and was skipped. Committed templates (.example, .sample, .template, .dist) hold placeholders, so they are captured like any file; real secret files and protected directories stay excluded. --- internal/filediff/snapshot.go | 15 +++++++++++++++ internal/filediff/snapshot_test.go | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/internal/filediff/snapshot.go b/internal/filediff/snapshot.go index 2cb7c261..28ef9dc5 100644 --- a/internal/filediff/snapshot.go +++ b/internal/filediff/snapshot.go @@ -239,6 +239,12 @@ func hashFile(f *os.File) (hash [32]byte, binary bool, ok bool) { func protected(name string) bool { for _, part := range strings.Split(strings.ToLower(name), "/") { + // A committed template (.env.example, config.key.sample) holds + // placeholders, not secrets; excluding it would mark every capture of + // such a repository incomplete. + if template(part) { + continue + } if part == ".git" || part == "secrets" || part == ".ssh" || part == ".aws" || part == ".gnupg" || part == ".kube" || part == "node_modules" { return true } @@ -249,6 +255,15 @@ func protected(name string) bool { return false } +func template(part string) bool { + for _, suffix := range []string{".example", ".sample", ".template", ".dist"} { + if strings.HasSuffix(part, suffix) { + return true + } + } + return false +} + type boundedOutput struct { bytes.Buffer limit int diff --git a/internal/filediff/snapshot_test.go b/internal/filediff/snapshot_test.go index e434b9c1..b4c18b98 100644 --- a/internal/filediff/snapshot_test.go +++ b/internal/filediff/snapshot_test.go @@ -281,3 +281,22 @@ func TestGitStatusListsUncomparableChanges(t *testing.T) { t.Fatalf("status/diagnostic = %q/%q", changes.Status, changes.Diagnostic) } } + +func TestProtectedKeepsSecretsButNotCommittedTemplates(t *testing.T) { + for name, want := range map[string]bool{ + ".env": true, + ".env.local": true, + "app/prod.env": true, + "certs/server.key": true, + "secrets/token.example": true, // a protected directory stays protected + ".env.example": false, + "app/.env.sample": false, + "config/server.key.dist": false, + "deploy/.env.template": false, + "docs/example.md": false, + } { + if got := protected(name); got != want { + t.Errorf("protected(%q) = %v, want %v", name, got, want) + } + } +}