diff --git a/README.md b/README.md index 9ee1677..2a7c19c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ Require literal syntax when initializing empty or zero Python builtin types. - Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`. - Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`. +#### `catch-dotenv` +Prevents committing `.env` files to version control and optionally generates `.env.example` files. + - Use `--create-example` to generate a `.env.example` file with variable names but no values. + - Automatically adds `.env` to `.gitignore` if not already present. + - Helps prevent accidental exposure of secrets and sensitive configuration. + #### `check-case-conflict` Check for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT. diff --git a/pre_commit_hooks/catch_dotenv.py b/pre_commit_hooks/catch_dotenv.py index f85c23b..fedbe4c 100644 --- a/pre_commit_hooks/catch_dotenv.py +++ b/pre_commit_hooks/catch_dotenv.py @@ -57,7 +57,7 @@ def _read_gitignore(gitignore_file: str) -> tuple[str, list[str]]: file=sys.stderr, ) raise - return original_text if lines else '', lines + return original_text, lines def _normalize_gitignore_lines( diff --git a/tests/catch_dotenv_test.py b/tests/catch_dotenv_test.py index 4f0363d..399cffd 100644 --- a/tests/catch_dotenv_test.py +++ b/tests/catch_dotenv_test.py @@ -95,7 +95,7 @@ def test_gitignore_with_existing_content_preserved( g = tmp_path / DEFAULT_GITIGNORE_FILE g.write_text( 'node_modules/\n# comment line\n', - ) # no trailing newline section markers + ) # existing content with trailing newline run_hook(tmp_path, [DEFAULT_ENV_FILE]) lines = g.read_text().splitlines() # original content should still be at top @@ -372,7 +372,7 @@ def test_subdirectory_invocation( os.chdir(sub) try: ret = main( - ['../' + DEFAULT_ENV_FILE], + [str(Path('..') / DEFAULT_ENV_FILE)], ) # staged path relative to subdir gi = (sub / DEFAULT_GITIGNORE_FILE).read_text().splitlines() finally: