Skip to content
Merged
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
5 changes: 4 additions & 1 deletion dvc/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def _add_entry_to_gitignore(self, entry, gitignore):
entry = GitWildMatchPattern.escape(entry)

with open(gitignore, "a+", encoding="utf-8") as fobj:
unique_lines = set(fobj.readlines())
fobj.seek(0, os.SEEK_END)
if fobj.tell() == 0:
# Empty file
Expand All @@ -218,7 +219,9 @@ def _add_entry_to_gitignore(self, entry, gitignore):
fobj.seek(fobj.tell() - 1, os.SEEK_SET)
last = fobj.read(1)
prefix = "" if last == "\n" else "\n"
fobj.write(f"{prefix}{entry}\n")
new_entry = f"{prefix}{entry}\n"
if new_entry not in unique_lines:
fobj.write(new_entry)

def ignore_remove(self, path):
entry, gitignore = self._get_gitignore(path)
Expand Down