1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
261
def check_changed_or_out_of_date(self, strict, opt_name,
262
more_error, more_warning):
263
"""Check the tree for uncommitted changes and branch synchronization.
265
If strict is None and not set in the config files, a warning is issued.
266
If strict is True, an error is raised.
267
If strict is False, no checks are done and no warning is issued.
269
:param strict: True, False or None, searched in branch config if None.
271
:param opt_name: strict option name to search in config file.
273
:param more_error: Details about how to avoid the check.
275
:param more_warning: Details about what is happening.
278
strict = self.branch.get_config().get_user_option_as_bool(opt_name)
279
if strict is not False:
281
if (self.has_changes()):
282
err_class = errors.UncommittedChanges
283
elif self.last_revision() != self.branch.last_revision():
284
# The tree has lost sync with its branch, there is little
285
# chance that the user is aware of it but he can still force
286
# the action with --no-strict
287
err_class = errors.OutOfDateTree
288
if err_class is not None:
290
err = err_class(self, more=more_warning)
291
# We don't want to interrupt the user if he expressed no
292
# preference about strict.
293
trace.warning('%s', err._format())
295
err = err_class(self, more=more_error)
299
262
def last_revision(self):
300
263
"""Return the revision id of the last commit performed in this tree.
400
363
This is designed more towards DWIM for humans than API clarity.
401
364
For the specific behaviour see the help for cmd_add().
366
:param file_list: List of zero or more paths. *NB: these are
367
interpreted relative to the process cwd, not relative to the
368
tree.* (Add and most other tree methods use tree-relative
403
370
:param action: A reporter to be called with the inventory, parent_ie,
404
371
path and kind of the path being added. It may return a file_id if
405
372
a specific one should be used.
429
394
user_dirs = set()
430
conflicts_related = set()
431
# Not all mutable trees can have conflicts
432
if getattr(self, 'conflicts', None) is not None:
433
# Collect all related files without checking whether they exist or
434
# are versioned. It's cheaper to do that once for all conflicts
435
# than trying to find the relevant conflict for each added file.
436
for c in self.conflicts():
437
conflicts_related.update(c.associated_filenames())
396
# expand any symlinks in the directory part, while leaving the
398
file_list = map(osutils.normalizepath, file_list)
439
400
# validate user file paths and convert all paths to tree
440
401
# relative : it's cheaper to make a tree relative path an abspath
501
462
if illegalpath_re.search(directory.raw_path):
502
463
trace.warning("skipping %r (contains \\n or \\r)" % abspath)
504
if directory.raw_path in conflicts_related:
505
# If the file looks like one generated for a conflict, don't
508
'skipping %s (generated to help resolve conflicts)',
512
466
if parent_ie is not None:
513
467
versioned = directory.base_path in parent_ie.children
740
694
file_id or None to generate a new file id
697
# if the parent exists, but isn't a directory, we have to do the
698
# kind change now -- really the inventory shouldn't pretend to know
699
# the kind of wt files, but it does.
700
if parent_ie.kind != 'directory':
701
# nb: this relies on someone else checking that the path we're using
702
# doesn't contain symlinks.
703
new_parent_ie = inventory.make_entry('directory', parent_ie.name,
704
parent_ie.parent_id, parent_ie.file_id)
705
del inv[parent_ie.file_id]
706
inv.add(new_parent_ie)
707
parent_ie = new_parent_ie
743
708
file_id = file_id_callback(inv, parent_ie, path, kind)
744
709
entry = inv.make_entry(kind, path.base_path, parent_ie.file_id,