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
28
class TestFileIdInvolved(TestCaseInTempDir):
30
class TestFileIdInvolved(TestCaseWithTransport):
30
32
def touch(self,filename):
31
33
f = file(filename,"a")
32
34
f.write("appended line\n")
35
def merge( self, branch_from, force=False ):
36
from bzrlib._merge_core import ApplyMerge3
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),
47
wt_to.add_pending_merge(branch_from.last_revision())
42
50
super(TestFileIdInvolved, self).setUp()
49
57
# \---> E---/----> F (branch1)
54
main_branch = Branch.initialize('.')
55
self.build_tree(["a","b","c"])
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"])
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")
66
main_wt.commit("Commit one", rev_id="rev-A")
64
67
#-------- end A -----------
66
main_branch.clone("../branch1")
67
os.chdir("../branch1")
69
#branch1_branch = Branch.open(".")
70
self.build_tree(["d"])
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")
74
74
#-------- end E -----------
78
commit(Branch.open("."), "Commit two", rev_id="rev-B")
77
main_wt.commit("Commit two", rev_id="rev-B")
80
79
#-------- end B -----------
82
Branch.open(".").clone("../branch2")
83
os.chdir("../branch2")
85
branch2_branch = Branch.open(".")
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",
89
86
#-------- end J -----------
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")
96
91
#-------- end C -----------
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")
95
tree.commit("branch1, commit two", rev_id="rev-F")
104
97
#-------- end F -----------
106
os.chdir("../branch2")
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")
111
102
#-------- end K -----------
116
self.merge("../branch1",force=True)
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>")
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")
128
self.branch = Branch.open(".")
115
self.branch = main_branch
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 )
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 \
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 \
197
self.assertEquals( l1, set(l2) )
184
self.assertEquals(l1, set(l2))