~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: Vincent Ladeuil
  • Date: 2010-04-12 16:54:35 UTC
  • mto: (5148.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5151.
  • Revision ID: v.ladeuil+lp@free.fr-20100412165435-gzdnwuybj9rvddiz
Fix bug #519319 by defaulting to a warning for dirty trees.

* bzrlib/mutabletree.py:
(MutableTree.warn_if_changed_or_out_of_date): Factor out the
checks done by send, push and dpush.

* bzrlib/send.py:
(send): Use warn_if_changed_or_out_of_date().

* bzrlib/foreign.py:
(cmd_dpush.run): Use warn_if_changed_or_out_of_date().

* bzrlib/builtins.py:
(cmd_push.run): Use warn_if_changed_or_out_of_date().

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
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
258
258
            return False
259
259
 
260
260
    @needs_read_lock
 
261
    def warn_if_changed_or_out_of_date(self, strict, opt_name, more_msg):
 
262
        """Check the tree for uncommitted changes and branch synchronization.
 
263
 
 
264
        If strict is None and not set in the config files, a warning is issued.
 
265
        If strict is True, an error is raised.
 
266
        If strict is False, no checks are done and no warning is issued.
 
267
 
 
268
        :param strict: True, False or None, searched in branch config if None.
 
269
 
 
270
        :param opt_name: strict option name to search in config file.
 
271
 
 
272
        :param more_msg: Details about how to avoid the warnings.
 
273
        """
 
274
        if strict is None:
 
275
            strict = self.branch.get_config().get_user_option_as_bool(opt_name)
 
276
        if strict is not False:
 
277
            err = None
 
278
            if (self.has_changes()):
 
279
                err = errors.UncommittedChanges(self, more=more_msg)
 
280
            elif self.last_revision() != self.branch.last_revision():
 
281
                # The tree has lost sync with its branch, there is little
 
282
                # chance that the user is aware of it but he can still force
 
283
                # the action with --no-strict
 
284
                err = errors.OutOfDateTree(self, more=more_msg)
 
285
            if err is not None:
 
286
                if strict is None:
 
287
                    # We don't want to interrupt the user if he expressed no
 
288
                    # preference about strict.
 
289
                    trace.warning('%s', (err._format(),))
 
290
                else:
 
291
                    raise err
 
292
 
 
293
    @needs_read_lock
261
294
    def last_revision(self):
262
295
        """Return the revision id of the last commit performed in this tree.
263
296