~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bad_files.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-01 21:56:19 UTC
  • mto: (2255.7.84 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070301215619-wpt6kz8yem3ypu1b
Update to dirstate locking.
Move all of WT4.lock_* functions locally, so that they can
properly interact and cleanup around when we lock/unlock the
dirstate file.
Change all Lock objects to be non-blocking. So that if someone
grabs a lock on the DirState we find out immediately, rather
than blocking.
Change WT4.unlock() so that if the dirstate is dirty, it will
save the contents even if it only has a read lock.
It does this by trying to take a write lock, if it fails
we just ignore it. If it succeeds, then we can flush to disk.
This is more important now that DirState tracks file changes.
It allows 'bzr status' to update the cached stat and sha values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
"""Tests being able to ignore bad filetypes."""
 
19
 
 
20
from cStringIO import StringIO
 
21
import os
 
22
 
 
23
from bzrlib import (
 
24
    add,
 
25
    errors,
 
26
    )
 
27
from bzrlib.status import show_tree_status
 
28
from bzrlib.tests import TestCaseWithTransport
 
29
 
 
30
 
 
31
def verify_status(tester, tree, value):
 
32
    """Verify the output of show_tree_status"""
 
33
    tof = StringIO()
 
34
    show_tree_status(tree, to_file=tof)
 
35
    tof.seek(0)
 
36
    tester.assertEqual(value, tof.readlines())
 
37
 
 
38
 
 
39
class TestBadFiles(TestCaseWithTransport):
 
40
 
 
41
    def test_bad_files(self):
 
42
        """Test that bzr will ignore files it doesn't like"""
 
43
        if getattr(os, 'mkfifo', None) is None:
 
44
            # TODO: Ultimately this should be TestSkipped
 
45
            # or PlatformDeficiency
 
46
            return
 
47
 
 
48
        wt = self.make_branch_and_tree('.')
 
49
        b = wt.branch
 
50
 
 
51
        files = ['one', 'two', 'three']
 
52
        file_ids = ['one-id', 'two-id', 'three-id']
 
53
        self.build_tree(files)
 
54
        wt.add(files, file_ids)
 
55
        wt.commit("Commit one", rev_id="a@u-0-0")
 
56
 
 
57
        # We should now have a few files, lets try to
 
58
        # put some bogus stuff in the tree
 
59
 
 
60
        # status with nothing changed
 
61
        verify_status(self, wt, [])
 
62
 
 
63
        os.mkfifo('a-fifo')
 
64
        self.build_tree(['six'])
 
65
 
 
66
        verify_status(self, wt,
 
67
                          ['unknown:\n',
 
68
                           '  a-fifo\n',
 
69
                           '  six\n'
 
70
                           ])
 
71
 
 
72
        # We should raise an error if we are adding a bogus file
 
73
        self.assertRaises(errors.BadFileKindError,
 
74
                          add.smart_add_tree, wt, ['a-fifo'])
 
75
 
 
76
        # And the list of files shouldn't have been modified
 
77
        verify_status(self, wt,
 
78
                          ['unknown:\n',
 
79
                           '  a-fifo\n',
 
80
                           '  six\n'
 
81
                           ])
 
82
 
 
83
        # Make sure smart_add can handle having a bogus
 
84
        # file in the way
 
85
        add.smart_add_tree(wt, ['.'])
 
86
        verify_status(self, wt,
 
87
                          ['added:\n',
 
88
                           '  six\n',
 
89
                           'unknown:\n',
 
90
                           '  a-fifo\n',
 
91
                           ])
 
92
        wt.commit("Commit four", rev_id="a@u-0-3")
 
93
 
 
94
        verify_status(self, wt,
 
95
                          ['unknown:\n',
 
96
                           '  a-fifo\n',
 
97
                           ])