From 0f696d40adb486ed7d7c906decd5b658398d50eb Mon Sep 17 00:00:00 2001 From: Sanket Dasgupta Date: Mon, 4 May 2020 22:42:42 +0530 Subject: [PATCH] Ensure that the virtualenv dir is ignored from Git Fixes https://github.com/pypa/virtualenv/issues/1806 --- docs/changelog/1806.feature.rst | 1 + src/virtualenv/create/creator.py | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 docs/changelog/1806.feature.rst diff --git a/docs/changelog/1806.feature.rst b/docs/changelog/1806.feature.rst new file mode 100644 index 000000000..2d1f1ff95 --- /dev/null +++ b/docs/changelog/1806.feature.rst @@ -0,0 +1 @@ +Ensure that the virtualenv dir created is ignored by Git diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py index d4a2b9360..e7d5a71bd 100644 --- a/src/virtualenv/create/creator.py +++ b/src/virtualenv/create/creator.py @@ -154,6 +154,15 @@ def run(self): safe_delete(self.dest) self.create() self.set_pyenv_cfg() + self._ensure_gitignore() + + def _ensure_gitignore(self): + """ + Ignore the virtualenv directory from git. + """ + self.dest.joinpath(".gitignore").write_text( + "# placed by virtualenv automatically, do not change\n*", encoding="UTF-8" + ) def set_pyenv_cfg(self): self.pyenv_cfg.content = OrderedDict()