[patch] #3619 give error on 'bzr st nonexistent'
Martin Pool
mbp at sourcefrog.net
Wed Apr 19 08:13:59 BST 2006
https://launchpad.net/products/bzr/+bug/3619
This is related to the fix for bzr diff, but somewhat different because
you're allowed to run bzr status on unversioned files.
--
Martin
-------------- next part --------------
=== modified file 'a/bzrlib/delta.py'
--- a/bzrlib/delta.py
+++ b/bzrlib/delta.py
@@ -160,7 +160,8 @@
files within them. Any unversioned files given have no effect
(but this might change in the future).
"""
-
+ # NB: show_status depends on being able to pass in non-versioned files and
+ # report them as unknown
old_tree.lock_read()
try:
new_tree.lock_read()
=== modified file 'a/bzrlib/diff.py'
--- a/bzrlib/diff.py
+++ b/bzrlib/diff.py
@@ -313,7 +313,7 @@
def _raise_if_doubly_unversioned(specific_files, old_tree, new_tree):
"""Complain if paths are not versioned in either tree."""
- if not specific_files:
+ if len(specific_files) == 0:
return
old_unversioned = old_tree.filter_unversioned_files(specific_files)
new_unversioned = new_tree.filter_unversioned_files(specific_files)
@@ -321,6 +321,25 @@
if unversioned:
raise errors.PathsNotVersionedError(sorted(unversioned))
+
+def _raise_if_nonexistent(paths, old_tree, new_tree):
+ """Complain if paths are not in either inventory or tree.
+
+ It's OK with the files exist in either tree's inventory, or
+ if they exist in the tree but are not versioned.
+
+ This can be used by operations such as bzr status that can accept
+ unknown or ignored files.
+ """
+ mutter("check paths: %r", paths)
+ if not paths:
+ return
+ s = old_tree.filter_unversioned_files(paths)
+ s = new_tree.filter_unversioned_files(s)
+ s = [path for path in s if not new_tree.has_filename(path)]
+ if s:
+ raise errors.PathsDoNotExist(sorted(s))
+
def get_prop_change(meta_modified):
if meta_modified:
=== modified file 'a/bzrlib/errors.py'
--- a/bzrlib/errors.py
+++ b/bzrlib/errors.py
@@ -280,6 +280,19 @@
self.paths_as_string = ' '.join([quotefn(p) for p in paths])
+class PathsDoNotExist(BzrNewError):
+ # used when reporting that paths are neither versioned nor in the working
+ # tree
+ """Path(s) do not exist: %(paths_as_string)s"""
+
+ def __init__(self, paths):
+ from bzrlib.osutils import quotefn
+ BzrNewError.__init__(self)
+ self.paths = paths
+ self.paths_as_string = ' '.join([quotefn(p) for p in paths])
+
+
+
class BadFileKindError(BzrError):
"""Specified file is of a kind that cannot be added.
=== modified file 'a/bzrlib/status.py'
--- a/bzrlib/status.py
+++ b/bzrlib/status.py
@@ -1,4 +1,4 @@
-# (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2006 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
@@ -17,6 +17,7 @@
import sys
from bzrlib.delta import compare_trees
+from bzrlib.diff import _raise_if_nonexistent
from bzrlib.errors import NoSuchRevision
from bzrlib.log import line_log
from bzrlib.osutils import is_inside_any
@@ -83,11 +84,16 @@
The result is written out as Unicode and to_file should be able
to encode that.
+ If showing the status of a working tree, extra information is included
+ about unknown files, conflicts, and pending merges.
+
show_unchanged
If set, includes unchanged files.
specific_files
- If set, only show the status of files in this list.
+ If set, a list of filenames whose status should be shown.
+ It is an error to give a filename that is not in the working
+ tree, or in the working inventory or in the basis inventory.
show_ids
If set, includes each file's id.
@@ -127,7 +133,7 @@
raise BzrCommandError(str(e))
else:
new = wt
-
+ _raise_if_nonexistent(specific_files, old, new)
delta = compare_trees(old, new, want_unchanged=show_unchanged,
specific_files=specific_files)
delta.show(to_file,
=== modified file 'a/bzrlib/tests/blackbox/test_status.py'
--- a/bzrlib/tests/blackbox/test_status.py
+++ b/bzrlib/tests/blackbox/test_status.py
@@ -178,6 +178,14 @@
' dir2\n'
])
+ def test_status_nonexistent_file(self):
+ # files that don't exist in either the basis tree or working tree
+ # should give an error
+ wt = self.make_branch_and_tree('.')
+ out, err = self.run_bzr('status', 'does-not-exist', retcode=3)
+ self.assertContainsRe(err, r'do not exist.*does-not-exist')
+
+
class CheckoutStatus(BranchStatus):
def setUp(self):
More information about the bazaar
mailing list