Skip to content

fix(generators): keep .env.test.local git-ignored in dotenv generator - #146

Open
detail-app[bot] wants to merge 1 commit into
masterfrom
detail/bug-fix/fix-generators-keep-env-test-local-git-ignored-in-00bd9e
Open

fix(generators): keep .env.test.local git-ignored in dotenv generator#146
detail-app[bot] wants to merge 1 commit into
masterfrom
detail/bug-fix/fix-generators-keep-env-test-local-git-ignored-in-00bd9e

Conversation

@detail-app

@detail-app detail-app Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Closes #130

Bug

The pu:gem:dotenv generator set up dotenv for Rails apps by appending negation rules to .gitignore. It appended !/.env.test.local, which overrode Rails' default /.env* ignore pattern and made the test-secrets file trackable in git. Since the generator also copies .env.test.local and its template instructs users to put "Secrets for testing" there, real secrets could be staged and committed — a security footgun.

The bug was an inconsistency: the generator didn't unignore .env.local (another secrets file, correctly left ignored), but did unignore .env.test.local. It was introduced when .env.test.local was added to the copy_file list and the same !-prefix treatment was applied to it as to the non-secret template files.

Fix

Removed !/.env.test.local from the gitignore directive in lib/generators/pu/gem/dotenv/dotenv_generator.rb:

gitignore "!/.env", "!/.env.template", "!/.env.local.template"

.env.test.local is still copied (so devs have a starter file for test secrets); it is simply no longer un-ignored. Rails' default /.env* continues to ignore both .env.local and .env.test.local, while the non-secret files (.env, .env.template, .env.local.template) remain trackable — matching dotenv's own documented conventions.

Testing

Added test/generators/dotenv_generator_test.rb (21 tests) following the repo's existing generator-test pattern (static source guards, template-content assertions, and behavioral Rails::Generators::TestCase tests that run the generator in a temp dir with a real git init). bundle! is stubbed in a test-only subclass so the suite doesn't shell out to bundle install.

  • Unit tests, syntax check, and standardrb lint all pass. The new suite is green under all three appraisals: rails-7, rails-8.0, rails-8.1 (21 tests, 66 assertions, 0 failures each). bundle exec appraisal rails-8.1 rake test_generators reports "All generator test files passed." including the new file.
  • Regression guard verified. Temporarily re-adding !/.env.test.local flips 7 tests red (1 static source guard + 6 behavioral guards, including the git add .env.test.local refusal test); restoring the fix returns to 0 failures.
  • End-to-end against a fresh Rails 8.1 app (not committed): rails new test_app (which ships /.env* in .gitignore) → add plutonium as a path gem → bundle exec rails g pu:gem:dotenv. The generator emits only three gitignore directives (no !/.env.test.local); .gitignore ends with !/.env, !/.env.template, !/.env.local.template. git check-ignore -v .env.test.local reports .gitignore:11:/.env* as the deciding pattern (exit 0 = ignored), git check-ignore .env exits 1 (trackable), and git add .env.test.local after writing a real secret is refused: "The following paths are ignored by one of your .gitignore files: .env.test.local". git status shows only the three non-secret .env files as trackable.

Automatic Fixes PRs can be configured here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Dotenv generator makes .env.test.local trackable, risking committed test secrets

1 participant