예제 #1
0
    def test_lock_file(self):
        # old format branches use a special lock file on sftp.
        b = self.make_branch('', format=bzrdir.BzrDirFormat6())
        b = bzrlib.branch.Branch.open(self.get_url())
        self.failUnlessExists('.bzr/')
        self.failUnlessExists('.bzr/branch-format')
        self.failUnlessExists('.bzr/branch-lock')

        self.failIf(lexists('.bzr/branch-lock.write-lock'))
        b.lock_write()
        self.failUnlessExists('.bzr/branch-lock.write-lock')
        b.unlock()
        self.failIf(lexists('.bzr/branch-lock.write-lock'))
예제 #2
0
    def test_lock_file(self):
        # old format branches use a special lock file on sftp.
        b = self.make_branch('', format=bzrdir.BzrDirFormat6())
        b = bzrlib.branch.Branch.open(self.get_url())
        self.failUnlessExists('.bzr/')
        self.failUnlessExists('.bzr/branch-format')
        self.failUnlessExists('.bzr/branch-lock')

        self.failIf(lexists('.bzr/branch-lock.write-lock'))
        b.lock_write()
        self.failUnlessExists('.bzr/branch-lock.write-lock')
        b.unlock()
        self.failIf(lexists('.bzr/branch-lock.write-lock'))
예제 #3
0
    def test_sftp_locks(self):
        from bzrlib.errors import LockError
        t = self.get_transport()

        l = t.lock_write('bogus')
        self.assertPathExists('bogus.write-lock')

        # Don't wait for the lock, locking an already locked
        # file should raise an assert
        self.assertRaises(LockError, t.lock_write, 'bogus')

        l.unlock()
        self.assertFalse(lexists('bogus.write-lock'))

        with open('something.write-lock', 'wb') as f:
            f.write('fake lock\n')
        self.assertRaises(LockError, t.lock_write, 'something')
        os.remove('something.write-lock')

        l = t.lock_write('something')

        l2 = t.lock_write('bogus')

        l.unlock()
        l2.unlock()
예제 #4
0
def complete_revert(wt, newparents):
    """Simple helper that reverts to specified new parents and makes sure none
    of the extra files are left around.

    :param wt: Working tree to use for rebase
    :param newparents: New parents of the working tree
    """
    newtree = wt.branch.repository.revision_tree(newparents[0])
    delta = wt.changes_from(newtree)
    wt.branch.generate_revision_history(newparents[0])
    wt.set_parent_ids([r for r in newparents[:1] if r != NULL_REVISION])
    for (f, _, _) in delta.added:
        abs_path = wt.abspath(f)
        if osutils.lexists(abs_path):
            if osutils.isdir(abs_path):
                osutils.rmtree(abs_path)
            else:
                os.unlink(abs_path)
    wt.revert(None, old_tree=newtree, backups=False)
    assert not wt.changes_from(wt.basis_tree()).has_changed(), "Rev changed"
    wt.set_parent_ids([r for r in newparents if r != NULL_REVISION])
예제 #5
0
파일: test_move.py 프로젝트: c0ns0le/cygwin
 def test_move_fail_consistent(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree(['a', 'b/', 'b/a', 'c'])
     tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
     tree.commit('initial', rev_id='rev-1')
     root_id = tree.get_root_id()
     # Target already exists
     self.assertRaises(errors.RenameFailedFilesExist,
                       tree.move, ['c', 'a'], 'b')
     # 'c' may or may not have been moved, but either way the tree should
     # maintain a consistent state.
     if osutils.lexists('c'):
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('c', 'c-id')], tree)
     else:
         self.failUnlessExists('b/c')
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('b/c', 'c-id')], tree)
     self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                            ('c', 'c-id')], tree.basis_tree())
     tree._validate()
예제 #6
0
 def test_move_fail_consistent(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree(['a', 'b/', 'b/a', 'c'])
     tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
     tree.commit('initial', rev_id='rev-1')
     root_id = tree.get_root_id()
     # Target already exists
     self.assertRaises(errors.RenameFailedFilesExist, tree.move, ['c', 'a'],
                       'b')
     # 'c' may or may not have been moved, but either way the tree should
     # maintain a consistent state.
     if osutils.lexists('c'):
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('c', 'c-id')], tree)
     else:
         self.failUnlessExists('b/c')
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                                ('b/c', 'c-id')], tree)
     self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('b', 'b-id'),
                            ('c', 'c-id')], tree.basis_tree())
     tree._validate()
예제 #7
0
파일: test_move.py 프로젝트: c0ns0le/cygwin
 def test_move_multi_unversioned(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree(['a/', 'b', 'c', 'd'])
     tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id'])
     tree.commit('initial', rev_id='rev-1')
     root_id = tree.get_root_id()
     self.assertRaises(errors.BzrMoveFailedError,
                       tree.move, ['c', 'b', 'd'], 'a')
     self.assertRaises(errors.BzrMoveFailedError,
                       tree.move, ['b', 'c', 'd'], 'a')
     self.assertRaises(errors.BzrMoveFailedError,
                       tree.move, ['d', 'c', 'b'], 'a')
     if osutils.lexists('a/c'):
         # If 'c' was actually moved, then 'd' should have also been moved
         self.assertTreeLayout([('', root_id), ('a', 'a-id'),
                                ('a/c', 'c-id'),  ('a/d', 'd-id')], tree)
     else:
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                                ('d', 'd-id')], tree)
     self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                            ('d', 'd-id')], tree.basis_tree())
     tree._validate()
예제 #8
0
 def test_move_multi_unversioned(self):
     tree = self.make_branch_and_tree('.')
     self.build_tree(['a/', 'b', 'c', 'd'])
     tree.add(['a', 'c', 'd'], ['a-id', 'c-id', 'd-id'])
     tree.commit('initial', rev_id='rev-1')
     root_id = tree.get_root_id()
     self.assertRaises(errors.BzrMoveFailedError, tree.move,
                       ['c', 'b', 'd'], 'a')
     self.assertRaises(errors.BzrMoveFailedError, tree.move,
                       ['b', 'c', 'd'], 'a')
     self.assertRaises(errors.BzrMoveFailedError, tree.move,
                       ['d', 'c', 'b'], 'a')
     if osutils.lexists('a/c'):
         # If 'c' was actually moved, then 'd' should have also been moved
         self.assertTreeLayout([('', root_id), ('a', 'a-id'),
                                ('a/c', 'c-id'), ('a/d', 'd-id')], tree)
     else:
         self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                                ('d', 'd-id')], tree)
     self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
                            ('d', 'd-id')], tree.basis_tree())
     tree._validate()
예제 #9
0
    def test_sftp_locks(self):
        from bzrlib.errors import LockError
        t = self.get_transport()

        l = t.lock_write('bogus')
        self.assertPathExists('bogus.write-lock')

        # Don't wait for the lock, locking an already locked
        # file should raise an assert
        self.assertRaises(LockError, t.lock_write, 'bogus')

        l.unlock()
        self.assertFalse(lexists('bogus.write-lock'))

        with open('something.write-lock', 'wb') as f: f.write('fake lock\n')
        self.assertRaises(LockError, t.lock_write, 'something')
        os.remove('something.write-lock')

        l = t.lock_write('something')

        l2 = t.lock_write('bogus')

        l.unlock()
        l2.unlock()