diff --git a/news/1800.bugfix.md b/news/1800.bugfix.md new file mode 100644 index 0000000000..a38723ff0f --- /dev/null +++ b/news/1800.bugfix.md @@ -0,0 +1 @@ +Avoid duplicate .pdm-python in .gitignore. \ No newline at end of file diff --git a/src/pdm/cli/commands/fix/fixers.py b/src/pdm/cli/commands/fix/fixers.py index c09cdf8d84..8c635e7f6f 100644 --- a/src/pdm/cli/commands/fix/fixers.py +++ b/src/pdm/cli/commands/fix/fixers.py @@ -48,8 +48,9 @@ def _fix_gitignore(self) -> None: if not gitignore.exists(): return content = gitignore.read_text("utf8") - content = re.sub(r"^\.pdm\.toml$", ".pdm-python", content, flags=re.M) - gitignore.write_text(content, "utf8") + if ".pdm-python" not in content: + content = re.sub(r"^\.pdm\.toml$", ".pdm-python", content, flags=re.M) + gitignore.write_text(content, "utf8") def fix(self) -> None: old_file = self.project.root.joinpath(".pdm.toml")