bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
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 |
"""Tests for interfacing with a Git Branch"""
|
|
18 |
||
|
0.200.270
by Jelmer Vernooij
add tests for branch sprouting. |
19 |
import dulwich as git |
20 |
import os |
|
21 |
||
22 |
from bzrlib import ( |
|
23 |
revision, |
|
24 |
)
|
|
25 |
from bzrlib.branch import ( |
|
26 |
Branch, |
|
27 |
)
|
|
28 |
from bzrlib.bzrdir import ( |
|
29 |
BzrDir, |
|
30 |
)
|
|
31 |
from bzrlib.repository import ( |
|
32 |
Repository, |
|
33 |
)
|
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
34 |
|
|
0.200.27
by David Allouche
Flat is better than nested, remove the gitlib hierarchy. |
35 |
from bzrlib.plugins.git import ( |
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
36 |
branch, |
|
0.200.97
by Jelmer Vernooij
use mapping object. |
37 |
tests, |
|
0.200.20
by John Arbash Meinel
All tests are passing again |
38 |
)
|
|
0.200.97
by Jelmer Vernooij
use mapping object. |
39 |
from bzrlib.plugins.git.mapping import default_mapping |
|
0.200.123
by Jelmer Vernooij
Use central git module. |
40 |
|
|
0.200.18
by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc. |
41 |
|
42 |
class TestGitBranch(tests.TestCaseInTempDir): |
|
43 |
||
44 |
_test_needs_features = [tests.GitCommandFeature] |
|
45 |
||
46 |
def test_open_existing(self): |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
47 |
tests.run_git('init') |
48 |
||
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
49 |
thebranch = Branch.open('.') |
50 |
self.assertIsInstance(thebranch, branch.GitBranch) |
|
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
51 |
|
52 |
def test_last_revision_is_null(self): |
|
53 |
tests.run_git('init') |
|
54 |
||
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
55 |
thebranch = Branch.open('.') |
|
0.200.19
by John Arbash Meinel
More refactoring. Add some direct tests for GitModel. |
56 |
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision()) |
57 |
self.assertEqual((0, revision.NULL_REVISION), |
|
58 |
thebranch.last_revision_info()) |
|
|
0.200.20
by John Arbash Meinel
All tests are passing again |
59 |
|
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
60 |
def simple_commit_a(self): |
61 |
tests.run_git('init') |
|
62 |
self.build_tree(['a']) |
|
63 |
tests.run_git('add', 'a') |
|
64 |
tests.run_git('commit', '-m', 'a') |
|
65 |
||
|
0.200.20
by John Arbash Meinel
All tests are passing again |
66 |
def test_last_revision_is_valid(self): |
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
67 |
self.simple_commit_a() |
|
0.200.20
by John Arbash Meinel
All tests are passing again |
68 |
head = tests.run_git('rev-parse', 'HEAD').strip() |
69 |
||
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
70 |
thebranch = Branch.open('.') |
|
0.200.104
by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids. |
71 |
self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head), |
|
0.200.20
by John Arbash Meinel
All tests are passing again |
72 |
thebranch.last_revision()) |
|
0.200.58
by Jelmer Vernooij
Fix remaining tests. |
73 |
|
74 |
def test_revision_history(self): |
|
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
75 |
self.simple_commit_a() |
|
0.200.59
by Jelmer Vernooij
Add more tests, fix revision history. |
76 |
reva = tests.run_git('rev-parse', 'HEAD').strip() |
77 |
self.build_tree(['b']) |
|
78 |
tests.run_git('add', 'b') |
|
79 |
tests.run_git('commit', '-m', 'b') |
|
80 |
revb = tests.run_git('rev-parse', 'HEAD').strip() |
|
|
0.200.58
by Jelmer Vernooij
Fix remaining tests. |
81 |
|
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
82 |
thebranch = Branch.open('.') |
|
0.200.104
by Jelmer Vernooij
Use bzr-foreign function names for converting between git and bzr revids. |
83 |
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)], |
|
0.200.58
by Jelmer Vernooij
Fix remaining tests. |
84 |
thebranch.revision_history()) |
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
85 |
|
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
86 |
def test_tag_annotated(self): |
|
0.200.82
by Jelmer Vernooij
Support listing tags. |
87 |
self.simple_commit_a() |
88 |
reva = tests.run_git('rev-parse', 'HEAD').strip() |
|
89 |
tests.run_git('tag', '-a', '-m', 'add tag', 'foo') |
|
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
90 |
thebranch = Branch.open('.') |
91 |
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)}, |
|
92 |
thebranch.tags.get_tag_dict()) |
|
93 |
||
94 |
def test_tag(self): |
|
95 |
self.simple_commit_a() |
|
96 |
reva = tests.run_git('rev-parse', 'HEAD').strip() |
|
97 |
tests.run_git('tag', '-m', 'add tag', 'foo') |
|
98 |
thebranch = Branch.open('.') |
|
99 |
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)}, |
|
100 |
thebranch.tags.get_tag_dict()) |
|
101 |
||
|
0.200.58
by Jelmer Vernooij
Fix remaining tests. |
102 |
|
|
0.200.66
by Jelmer Vernooij
Implement branch.get_parent(). |
103 |
|
104 |
class TestWithGitBranch(tests.TestCaseWithTransport): |
|
105 |
||
106 |
def setUp(self): |
|
107 |
tests.TestCaseWithTransport.setUp(self) |
|
108 |
git.repo.Repo.create(self.test_dir) |
|
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
109 |
self.git_branch = Branch.open(self.test_dir) |
|
0.200.66
by Jelmer Vernooij
Implement branch.get_parent(). |
110 |
|
111 |
def test_get_parent(self): |
|
112 |
self.assertIs(None, self.git_branch.get_parent()) |
|
|
0.200.67
by Jelmer Vernooij
Implement Branch.get_stacked_on_url. |
113 |
|
114 |
def test_get_stacked_on_url(self): |
|
115 |
self.assertIs(None, self.git_branch.get_stacked_on_url()) |
|
|
0.200.70
by Jelmer Vernooij
Implement GitBranchFormat.get_format_description. |
116 |
|
|
0.200.72
by Jelmer Vernooij
Implement Branch.get_physical_lock_status. |
117 |
def test_get_physical_lock_status(self): |
118 |
self.assertFalse(self.git_branch.get_physical_lock_status()) |
|
119 |
||
|
0.200.70
by Jelmer Vernooij
Implement GitBranchFormat.get_format_description. |
120 |
|
121 |
class TestGitBranchFormat(tests.TestCase): |
|
122 |
||
123 |
def setUp(self): |
|
124 |
super(TestGitBranchFormat, self).setUp() |
|
|
0.200.94
by Jelmer Vernooij
Eliminate (duplicate) git_ prefix. |
125 |
self.format = branch.GitBranchFormat() |
|
0.200.70
by Jelmer Vernooij
Implement GitBranchFormat.get_format_description. |
126 |
|
127 |
def test_get_format_description(self): |
|
128 |
self.assertEquals("Git Branch", self.format.get_format_description()) |
|
|
0.200.270
by Jelmer Vernooij
add tests for branch sprouting. |
129 |
|
130 |
||
131 |
||
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
132 |
class BranchTests(tests.TestCaseInTempDir): |
|
0.200.270
by Jelmer Vernooij
add tests for branch sprouting. |
133 |
|
134 |
def make_onerev_branch(self): |
|
135 |
os.mkdir("d") |
|
136 |
os.chdir("d") |
|
137 |
tests.run_git("init") |
|
138 |
bb = tests.GitBranchBuilder() |
|
139 |
bb.set_file("foobar", "foo\nbar\n", False) |
|
140 |
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg") |
|
141 |
gitsha = bb.finish()[mark] |
|
142 |
os.chdir("..") |
|
143 |
return "d", gitsha |
|
144 |
||
145 |
def clone_git_branch(self, from_url, to_url): |
|
146 |
from_dir = BzrDir.open(from_url) |
|
147 |
to_dir = from_dir.sprout(to_url) |
|
148 |
return to_dir.open_branch() |
|
149 |
||
150 |
def test_single_rev(self): |
|
151 |
path, gitsha = self.make_onerev_branch() |
|
152 |
oldrepo = Repository.open(path) |
|
153 |
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) |
|
154 |
newbranch = self.clone_git_branch(path, "f") |
|
155 |
self.assertEquals([revid], newbranch.repository.all_revision_ids()) |
|
|
0.200.271
by Jelmer Vernooij
Stop importing tags as branches as part of git-import. |
156 |
|
157 |
def test_sprouted_tags(self): |
|
158 |
path, gitsha = self.make_onerev_branch() |
|
159 |
os.chdir(path) |
|
160 |
tests.run_git("tag", "lala") |
|
161 |
os.chdir(self.test_dir) |
|
162 |
oldrepo = Repository.open(path) |
|
163 |
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha) |
|
164 |
newbranch = self.clone_git_branch(path, "f") |
|
165 |
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict()) |
|
166 |
self.assertEquals([revid], newbranch.repository.all_revision_ids()) |