~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testworkingtree.py

[merge] much integrated work from robert and john

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
from bzrlib.branch import Branch
 
20
from bzrlib.errors import NotVersionedError
20
21
from bzrlib.selftest import TestCaseInTempDir
21
22
from bzrlib.trace import mutter
22
23
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
96
97
        self.build_tree(['from/', 'from/file', 'to/'])
97
98
        br_a = Branch.initialize('from')
98
99
        br_a.add('file')
99
 
        br_a.commit('foo', rev_id='A')
 
100
        br_a.working_tree().commit('foo', rev_id='A')
100
101
        br_b = Branch.initialize('to')
101
102
        return br_a, br_b
102
103
 
108
109
 
109
110
    def test_pull_overwrites(self):
110
111
        br_a, br_b = self.get_pullable_branches()
111
 
        br_b.commit('foo', rev_id='B')
 
112
        br_b.working_tree().commit('foo', rev_id='B')
112
113
        self.assertEqual(['B'], br_b.revision_history())
113
114
        br_b.working_tree().pull(br_a, overwrite=True)
114
115
        self.failUnless(br_b.has_revision('A'))
115
116
        self.failUnless(br_b.has_revision('B'))
116
117
        self.assertEqual(['A'], br_b.revision_history())
 
118
 
 
119
    def test_revert(self):
 
120
        """Test selected-file revert"""
 
121
        b = Branch.initialize('.')
 
122
 
 
123
        self.build_tree(['hello.txt'])
 
124
        file('hello.txt', 'w').write('initial hello')
 
125
 
 
126
        self.assertRaises(NotVersionedError,
 
127
                          b.working_tree().revert, ['hello.txt'])
 
128
        
 
129
        b.add(['hello.txt'])
 
130
        b.working_tree().commit('create initial hello.txt')
 
131
 
 
132
        self.check_file_contents('hello.txt', 'initial hello')
 
133
        file('hello.txt', 'w').write('new hello')
 
134
        self.check_file_contents('hello.txt', 'new hello')
 
135
 
 
136
        wt = b.working_tree()
 
137
 
 
138
        # revert file modified since last revision
 
139
        wt.revert(['hello.txt'])
 
140
        self.check_file_contents('hello.txt', 'initial hello')
 
141
        self.check_file_contents('hello.txt~', 'new hello')
 
142
 
 
143
        # reverting again does not clobber the backup
 
144
        wt.revert(['hello.txt'])
 
145
        self.check_file_contents('hello.txt', 'initial hello')
 
146
        self.check_file_contents('hello.txt~', 'new hello')