Rev 2250: Give a nicer error message if a path has changed its kind in http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/kind_change_error
John Arbash Meinel
john at arbash-meinel.com
Thu Feb 1 16:17:54 GMT 2007
At http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/kind_change_error
------------------------------------------------------------
revno: 2250
revision-id: john at arbash-meinel.com-20070201161746-mk70krrlgzxignam
parent: pqm at pqm.ubuntu.com-20070131184047-424584b0fabcee96
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: kind_change_error
timestamp: Thu 2007-02-01 10:17:46 -0600
message:
Give a nicer error message if a path has changed its kind
modified:
bzrlib/delta.py delta.py-20050729221636-54cf14ef94783d0a
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
-------------- next part --------------
=== modified file 'bzrlib/delta.py'
--- a/bzrlib/delta.py 2006-12-07 17:15:28 +0000
+++ b/bzrlib/delta.py 2007-02-01 16:17:46 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -184,7 +184,8 @@
specific_file_ids):
if not include_root and (None, None) == parent_id:
continue
- assert kind[0] == kind[1] or None in kind
+ if kind[0] != kind[1] and None not in kind:
+ raise errors.KindChangeError(path, kind[0], kind[1])
# the only 'kind change' permitted is creation/deletion
fully_present = tuple((versioned[x] and kind[x] is not None) for
x in range(2))
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-01-30 11:52:30 +0000
+++ b/bzrlib/errors.py 2007-02-01 16:17:46 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -328,6 +328,27 @@
self.extra = ''
+class KindChangeError(PathError):
+ """Raise when we encounter a path that has changed kind."""
+
+ # TODO: jam 20070201 If 'rm' changes to actually remove the entry, and we
+ # introduce an 'unversion' command, the recommended commands should
+ # be changed accordingly.
+
+ _fmt = ("Path %(path)s changed kind from %(orig_kind)s to %(new_kind)s."
+ "\nbzr does not currently support this without doing a delete and an"
+ " add.\n"
+ "Please do:\n"
+ " bzr rm %(path)s\n"
+ " bzr add %(path)s\n"
+ )
+
+ def __init__(self, path, orig_kind, new_kind):
+ PathError.__init__(self, path=path)
+ self.orig_kind = orig_kind
+ self.new_kind = new_kind
+
+
class NoSuchFile(PathError):
_fmt = "No such file: %(path)r%(extra)s"
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2007-01-30 11:52:30 +0000
+++ b/bzrlib/tests/test_errors.py 2007-02-01 16:17:46 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2007 Canonical Ltd
# Authors: Robert Collins <robert.collins at canonical.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -46,6 +46,19 @@
error = errors.InstallFailed([None])
self.assertEqual("Could not install revisions:\nNone", str(error))
+ def test_kind_change(self):
+ error = errors.KindChangeError(u'a/path', 'file', 'directory')
+ # TODO: jam 20070201 If we introduce kind change support, this error
+ # should be dropped. If we introduce the 'unversion' command,
+ # this message should be changed to use it.
+ self.assertEqual('Path a/path changed kind from file to directory.'
+ '\nbzr does not currently support this without doing a'
+ ' delete and an add.\n'
+ 'Please do:\n'
+ ' bzr rm a/path\n'
+ ' bzr add a/path\n',
+ str(error))
+
def test_knit_header_error(self):
error = errors.KnitHeaderError('line foo\n', 'path/to/file')
self.assertEqual("Knit header error: 'line foo\\n' unexpected"
=== modified file 'bzrlib/tests/test_workingtree.py'
--- a/bzrlib/tests/test_workingtree.py 2006-11-13 14:13:56 +0000
+++ b/bzrlib/tests/test_workingtree.py 2007-02-01 16:17:46 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007 Canonical Ltd
# Authors: Robert Collins <robert.collins at canonical.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -156,6 +156,19 @@
# unregister the format
workingtree.WorkingTreeFormat.unregister_format(format)
+ def test_kind_change_errors(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/path'])
+ tree.add(['path'], ['path-id'])
+ tree.commit('added path')
+ os.remove('tree/path')
+ self.build_tree(['tree/path/'])
+ # This is a test that should be replaced in the future. For now it is
+ # working around the fact that we do not support paths changing kind
+ # (files => directories,symlinks) without an rm+add pair.
+ self.assertRaises(errors.KindChangeError,
+ tree.changes_from, tree.basis_tree())
+
class TestWorkingTreeFormat3(TestCaseWithTransport):
"""Tests specific to WorkingTreeFormat3."""
More information about the bazaar-commits
mailing list