~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fileid_involved.py

  • Committer: Martin Pool
  • Date: 2006-02-01 12:24:35 UTC
  • mfrom: (1534.4.32 branch-formats)
  • mto: This revision was merged to the branch mainline in revision 1553.
  • Revision ID: mbp@sourcefrog.net-20060201122435-53f3efb1b5749fe1
[merge] branch-formats branch, and reconcile changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from bzrlib.add import smart_add
20
20
from bzrlib.branch import Branch
21
21
from bzrlib.builtins import merge
22
 
from bzrlib.commit import commit
23
22
from bzrlib.delta import compare_trees
24
 
from bzrlib.tests import TestCaseInTempDir
 
23
from bzrlib.fetch import greedy_fetch
 
24
from bzrlib.merge import merge_inner
 
25
from bzrlib.revision import common_ancestor
 
26
from bzrlib.tests import TestCaseWithTransport
25
27
from bzrlib.workingtree import WorkingTree
26
28
 
27
29
 
28
 
class TestFileIdInvolved(TestCaseInTempDir):
 
30
class TestFileIdInvolved(TestCaseWithTransport):
29
31
 
30
32
    def touch(self,filename):
31
33
        f = file(filename,"a")
32
34
        f.write("appended line\n")
33
35
        f.close( )
34
36
 
35
 
    def merge( self, branch_from, force=False ):
36
 
        from bzrlib._merge_core import ApplyMerge3
37
 
 
38
 
        merge([branch_from,-1],[None,None], merge_type=ApplyMerge3,
39
 
            check_clean=(not force) )
 
37
    def merge(self, branch_from, wt_to):
 
38
        # minimal ui-less merge.
 
39
        greedy_fetch(to_branch=wt_to.branch, from_branch=branch_from,
 
40
                     revision=branch_from.last_revision())
 
41
        base_rev = common_ancestor(branch_from.last_revision(),
 
42
                                    wt_to.branch.last_revision(),
 
43
                                    wt_to.branch.repository)
 
44
        merge_inner(wt_to.branch, branch_from.working_tree(), 
 
45
                    wt_to.branch.repository.revision_tree(base_rev),
 
46
                    this_tree=wt_to)
 
47
        wt_to.add_pending_merge(branch_from.last_revision())
40
48
 
41
49
    def setUp(self):
42
50
        super(TestFileIdInvolved, self).setUp()
48
56
        #  \           /      /
49
57
        #   \---> E---/----> F                 (branch1)
50
58
 
51
 
        os.mkdir("main")
52
 
        os.chdir("main")
53
 
 
54
 
        main_branch = Branch.initialize('.')
55
 
        self.build_tree(["a","b","c"])
56
 
 
57
 
        b = Branch.open('.')
58
 
        wt = b.working_tree()
59
 
        wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
 
59
        main_wt = self.make_branch_and_tree('main')
 
60
        main_branch = main_wt.branch
 
61
        self.build_tree(["main/a","main/b","main/c"])
 
62
 
 
63
        main_wt.add(['a', 'b', 'c'], ['a-file-id-2006-01-01-abcd',
60
64
                                 'b-file-id-2006-01-01-defg',
61
65
                                 'c-funky<file-id> quiji%bo'])
62
 
        commit(b, "Commit one", rev_id="rev-A")
63
 
        del b, wt
 
66
        main_wt.commit("Commit one", rev_id="rev-A")
64
67
        #-------- end A -----------
65
68
 
66
 
        main_branch.clone("../branch1")
67
 
        os.chdir("../branch1")
68
 
 
69
 
        #branch1_branch = Branch.open(".")
70
 
        self.build_tree(["d"])
71
 
        smart_add(".")
72
 
        commit(Branch.open("."), "branch1, Commit one", rev_id="rev-E")
 
69
        b1 = main_branch.clone("branch1")
 
70
        self.build_tree(["branch1/d"])
 
71
        b1.working_tree().add('d')
 
72
        b1.working_tree().commit("branch1, Commit one", rev_id="rev-E")
73
73
 
74
74
        #-------- end E -----------
75
75
 
76
 
        os.chdir("../main")
77
 
        self.touch("a")
78
 
        commit(Branch.open("."), "Commit two", rev_id="rev-B")
 
76
        self.touch("main/a")
 
77
        main_wt.commit("Commit two", rev_id="rev-B")
79
78
 
80
79
        #-------- end B -----------
81
80
 
82
 
        Branch.open(".").clone("../branch2")
83
 
        os.chdir("../branch2")
84
 
 
85
 
        branch2_branch = Branch.open(".")
86
 
        os.chmod("b",0770)
87
 
        commit(Branch.open("."), "branch2, Commit one", rev_id="rev-J")
 
81
        branch2_branch = main_branch.clone("branch2")
 
82
        os.chmod("branch2/b",0770)
 
83
        branch2_branch.working_tree().commit("branch2, Commit one", 
 
84
                                             rev_id="rev-J")
88
85
 
89
86
        #-------- end J -----------
90
87
 
91
 
        os.chdir("../main")
92
 
 
93
 
        self.merge("../branch1")
94
 
        commit(Branch.open("."), "merge branch1, rev-11", rev_id="rev-C")
 
88
        self.merge(b1, main_wt)
 
89
        main_wt.commit("merge branch1, rev-11", rev_id="rev-C")
95
90
 
96
91
        #-------- end C -----------
97
92
 
98
 
        os.chdir("../branch1")
99
 
        tree = WorkingTree('.', Branch.open("."))
 
93
        tree = WorkingTree('branch1', b1)
100
94
        tree.rename_one("d","e")
101
 
        commit(Branch.open("."), "branch1, commit two", rev_id="rev-F")
102
 
 
 
95
        tree.commit("branch1, commit two", rev_id="rev-F")
103
96
 
104
97
        #-------- end F -----------
105
98
 
106
 
        os.chdir("../branch2")
107
 
 
108
 
        self.touch("c")
109
 
        commit(Branch.open("."), "branch2, commit two", rev_id="rev-K")
 
99
        self.touch("branch2/c")
 
100
        branch2_branch.working_tree().commit("branch2, commit two", rev_id="rev-K")
110
101
 
111
102
        #-------- end K -----------
112
103
 
113
 
        os.chdir("../main")
114
 
 
115
 
        self.touch("b")
116
 
        self.merge("../branch1",force=True)
117
 
 
 
104
        self.touch("main/b")
 
105
        self.merge(b1, main_wt)
118
106
        # D gets some funky characters to make sure the unescaping works
119
 
        commit(Branch.open("."), "merge branch1, rev-12", rev_id="rev-<D>")
 
107
        main_wt.commit("merge branch1, rev-12", rev_id="rev-<D>")
120
108
 
121
109
        # end D
122
110
 
123
 
        self.merge("../branch2")
124
 
        commit(Branch.open("."), "merge branch1, rev-22",  rev_id="rev-G")
 
111
        self.merge(branch2_branch, main_wt)
 
112
        main_wt.commit("merge branch1, rev-22",  rev_id="rev-G")
125
113
 
126
114
        # end G
127
 
        os.chdir("../main")
128
 
        self.branch = Branch.open(".")
 
115
        self.branch = main_branch
129
116
 
130
117
 
131
118
    def test_fileid_involved_all_revs(self):
188
175
                new_tree = self.branch.repository.revision_tree(history[end])
189
176
                delta = compare_trees(old_tree, new_tree )
190
177
 
191
 
                l2 = [ id for path, id, kind in delta.added ] + \
192
 
                     [ id for oldpath, newpath, id, kind, text_modified, \
193
 
                            meta_modified in delta.renamed ] + \
194
 
                     [ id for path, id, kind, text_modified, meta_modified in \
195
 
                            delta.modified ]
 
178
                l2 = [id for path, id, kind in delta.added] + \
 
179
                     [id for oldpath, newpath, id, kind, text_modified, \
 
180
                        meta_modified in delta.renamed] + \
 
181
                     [id for path, id, kind, text_modified, meta_modified in \
 
182
                        delta.modified]
196
183
 
197
 
                self.assertEquals( l1, set(l2) )
 
184
                self.assertEquals(l1, set(l2))
198
185
 
199
186