[merge] portability fixes.
[jelmer/subvertpy.git] / tests / test_branch.py
1 # Copyright (C) 2006 Jelmer Vernooij <jelmer@samba.org>
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 from bzrlib.branch import Branch
18 from bzrlib.bzrdir import BzrDir, BzrDirTestProviderAdapter, BzrDirFormat
19 from bzrlib.repository import Repository
20
21 import os
22
23 import svn.core, svn.client
24
25 import format
26 from tests import TestCaseWithSubversionRepository
27
28 class WorkingSubversionBranch(TestCaseWithSubversionRepository):
29     def test_num_revnums(self):
30         repos_url = self.make_client('a', 'dc')
31         bzrdir = BzrDir.open("svn+"+repos_url)
32         branch = bzrdir.open_branch()
33         self.assertEqual(None, branch.last_revision())
34
35         self.build_tree({'dc/foo': "data"})
36         self.client_add("dc/foo")
37         self.client_commit("dc", "My Message")
38         
39         bzrdir = BzrDir.open("svn+"+repos_url)
40         branch = bzrdir.open_branch()
41         repos = bzrdir.open_repository()
42
43         self.assertEqual("svn-v1:1@%s-" % repos.uuid, branch.last_revision())
44
45         self.build_tree({'dc/foo': "data2"})
46         self.client_commit("dc", "My Message")
47
48         branch = Branch.open("svn+"+repos_url)
49         repos = Repository.open("svn+"+repos_url)
50
51         self.assertEqual("svn-v1:2@%s-" % repos.uuid, branch.last_revision())
52
53     def test_revision_history(self):
54         repos_url = self.make_client('a', 'dc')
55
56         branch = Branch.open("svn+"+repos_url)
57         self.assertEqual([], branch.revision_history())
58
59         self.build_tree({'dc/foo': "data"})
60         self.client_add("dc/foo")
61         self.client_commit("dc", "My Message")
62         
63         branch = Branch.open("svn+"+repos_url)
64         repos = Repository.open("svn+"+repos_url)
65
66         self.assertEqual(["svn-v1:1@%s-" % repos.uuid], branch.revision_history())
67
68         self.build_tree({'dc/foo': "data34"})
69         self.client_commit("dc", "My Message")
70
71         branch = Branch.open("svn+"+repos_url)
72         repos = Repository.open("svn+"+repos_url)
73
74         self.assertEqual([
75             "svn-v1:1@%s-" % repos.uuid, 
76             "svn-v1:2@%s-" % repos.uuid],
77             branch.revision_history())
78
79     def test_get_nick(self):
80         repos_url = self.make_client('a', 'dc')
81
82         self.build_tree({'dc/foo': "data"})
83         self.client_add("dc/foo")
84         self.client_commit("dc", "My Message")
85
86         branch = Branch.open("svn+"+repos_url)
87
88         self.assertIs(None, branch.nick)
89  
90     def test_fetch_branch(self):
91         repos_url = self.make_client('d', 'sc')
92
93         self.build_tree({'sc/foo/bla': "data"})
94         self.client_add("sc/foo")
95         self.client_commit("sc", "foo")
96
97         olddir = BzrDir.open("sc")
98
99         os.mkdir("dc")
100         
101         newdir = olddir.sprout('dc')
102
103         self.assertEqual(
104                 olddir.open_branch().last_revision(),
105                 newdir.open_branch().last_revision())
106
107     def test_ghost_workingtree(self):
108         # Looks like bazaar has trouble creating a working tree of a 
109         # revision that has ghost parents
110         repos_url = self.make_client('d', 'sc')
111
112         self.build_tree({'sc/foo/bla': "data"})
113         self.client_add("sc/foo")
114         self.client_set_prop("sc", "bzr:merge", "some-ghost\n")
115         self.client_commit("sc", "foo")
116
117         olddir = BzrDir.open("sc")
118
119         os.mkdir("dc")
120         
121         newdir = olddir.sprout('dc')
122         newdir.open_repository().get_revision(
123                 newdir.open_branch().last_revision())
124         newdir.open_repository().get_revision_inventory(
125                 newdir.open_branch().last_revision())