188
189
# read in the existing ignores set
189
190
ifn = tree.abspath(bzrlib.IGNORE_FILENAME)
190
191
if tree.has_filename(ifn):
193
# grab a copy of the raw contents of the file
194
file_contents = StringIO(f.read())
194
file_contents = f.read()
195
195
# figure out what kind of line endings are used
196
196
newline = getattr(f, 'newlines', None)
197
197
if type(newline) is tuple:
198
198
newline = newline[0]
199
199
elif newline is None:
204
file_contents = StringIO()
208
ignores = parse_ignore_file(file_contents)
210
# write out the updated ignores set
211
f = atomicfile.AtomicFile(ifn, 'wb')
213
s = file_contents.getvalue()
215
if len(s) > 0 and not s.endswith(newline):
207
sio = StringIO(file_contents)
209
ignores = parse_ignore_file(sio)
213
# write out the updated ignores set
214
f = atomicfile.AtomicFile(ifn, 'wb')
216
# write the original contents, preserving original line endings
217
f.write(newline.join(file_contents.split('\n')))
218
if len(file_contents) > 0 and not file_contents.endswith('\n'):
220
for pattern in name_pattern_list:
221
if not pattern in ignores:
222
f.write(pattern.encode('utf-8'))
217
for pattern in name_pattern_list:
218
if not pattern in ignores:
219
f.write(pattern.encode('utf-8'))
225
file_contents.close()
227
228
if not tree.path2id(bzrlib.IGNORE_FILENAME):
228
229
tree.add([bzrlib.IGNORE_FILENAME])