Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,20 @@ def test_scm_ignore_files_git(self):
file_lines = self.get_text_file_contents('.gitignore').splitlines()
self.assertIn('*', file_lines)

@requireVenvCreate
def test_scm_ignore_files_git_appends_to_existing_file(self):
"""Test that an existing .gitignore file is appended to."""
gitignore_path = self.get_env_file('.gitignore')
with open(gitignore_path, 'w', encoding='utf-8') as fp:
fp.write("# Existing comment\n")

self.run_with_capture(venv.create, self.env_dir,
scm_ignore_files={'git'})

file_lines = self.get_text_file_contents('.gitignore').splitlines()
self.assertIn('# Existing comment', file_lines)
self.assertIn('*', file_lines)

@requireVenvCreate
def test_create_scm_ignore_files_multiple(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def create_git_ignore_file(self, context):
ignored by git.
"""
gitignore_path = os.path.join(context.env_dir, '.gitignore')
with open(gitignore_path, 'w', encoding='utf-8') as file:
file.write('# Created by venv; '
with open(gitignore_path, 'a', encoding='utf-8') as file:
file.write('# Added by venv; '
'see https://docs.python.org/3/library/venv.html\n')
file.write('*\n')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change ``venv`` to append ``*`` to ``.gitignore`` instead of overwriting it.
Loading