/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
2
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
17
18
"""Black-box tests for bzr-git."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
22
from dulwich.repo import (
23
    Repo as GitRepo,
24
    )
25
0.200.89 by Jelmer Vernooij
Support sprouting branches.
26
import os
27
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
28
from ...controldir import (
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
29
    ControlDir,
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
30
    )
31
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
32
from ...tests.blackbox import ExternalBase
7143.18.1 by Jelmer Vernooij
Fix 'bzr switch' in git repositories.
33
from ...workingtree import WorkingTree
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
34
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
35
from .. import (
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
36
    tests,
37
    )
7290.26.1 by Jelmer Vernooij
Fix switching in git repositories.
38
from ...tests.script import TestCaseWithTransportAndScript
7211.8.1 by Jelmer Vernooij
Fix stats in Python3 git repositories.
39
from ...tests.features import PluginLoadedFeature
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
40
41
42
class TestGitBlackBox(ExternalBase):
43
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
44
    def simple_commit(self):
45
        # Create a git repository with a revision.
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
46
        repo = GitRepo.init(self.test_dir)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
47
        builder = tests.GitBranchBuilder()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
48
        builder.set_file('a', b'text for a\n', False)
49
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
50
        return repo, builder.finish()[r1]
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
51
0.200.294 by Jelmer Vernooij
Add test for nick.
52
    def test_nick(self):
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
53
        r = GitRepo.init(self.test_dir)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
54
        dir = ControlDir.open(self.test_dir)
0.200.769 by Jelmer Vernooij
Cope with open_branch() actually checking whether there is a branch present.
55
        dir.create_branch()
0.200.294 by Jelmer Vernooij
Add test for nick.
56
        output, error = self.run_bzr(['nick'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
57
        self.assertEqual("master\n", output)
0.200.294 by Jelmer Vernooij
Add test for nick.
58
0.327.1 by Jelmer Vernooij
Add test for branches command.
59
    def test_branches(self):
60
        self.simple_commit()
61
        output, error = self.run_bzr(['branches'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
62
        self.assertEqual("* master\n", output)
0.327.1 by Jelmer Vernooij
Add test for branches command.
63
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
64
    def test_info(self):
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
65
        self.simple_commit()
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
66
        output, error = self.run_bzr(['info'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
67
        self.assertEqual(error, '')
7211.9.1 by Jelmer Vernooij
Report colocated branch name in 'brz info'.
68
        self.assertEqual(
7211.9.2 by Jelmer Vernooij
Fix formatting.
69
            output,
70
            'Standalone tree (format: git)\n'
71
            'Location:\n'
72
            '            light checkout root: .\n'
73
            '  checkout of co-located branch: master\n')
0.200.68 by Jelmer Vernooij
Add blackbox test for info.
74
7199.4.1 by Jelmer Vernooij
Fix 'brz ignore' in Git working trees.
75
    def test_ignore(self):
76
        self.simple_commit()
77
        output, error = self.run_bzr(['ignore', 'foo'])
78
        self.assertEqual(error, '')
79
        self.assertEqual(output, '')
80
        self.assertFileEqual("foo\n", ".gitignore")
81
7290.7.1 by Jelmer Vernooij
Print proper error when running `brz cat-revision` on Git repositories.
82
    def test_cat_revision(self):
83
        self.simple_commit()
84
        output, error = self.run_bzr(['cat-revision', '-r-1'], retcode=3)
85
        self.assertContainsRe(
86
            error,
87
            'brz: ERROR: Repository .* does not support access to raw '
88
            'revision texts')
89
        self.assertEqual(output, '')
90
0.200.89 by Jelmer Vernooij
Support sprouting branches.
91
    def test_branch(self):
92
        os.mkdir("gitbranch")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
93
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
94
        os.chdir('gitbranch')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
95
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
96
        builder.set_file(b'a', b'text for a\n', False)
97
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
98
        builder.finish()
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
99
        os.chdir('..')
0.200.89 by Jelmer Vernooij
Support sprouting branches.
100
101
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
102
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
103
            (error == 'Branched 1 revision(s).\n') or
104
            (error == 'Branched 1 revision.\n'),
0.200.1382 by Jelmer Vernooij
Fix test after i18n fixes in bzr.dev.
105
            error)
0.200.89 by Jelmer Vernooij
Support sprouting branches.
106
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
107
    def test_checkout(self):
108
        os.mkdir("gitbranch")
109
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
110
        os.chdir('gitbranch')
111
        builder = tests.GitBranchBuilder()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
112
        builder.set_file(b'a', b'text for a\n', False)
113
        builder.commit(b'Joe Foo <joe@foo.com>', b'<The commit message>')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
114
        builder.finish()
115
        os.chdir('..')
116
117
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
0.375.1 by Jelmer Vernooij
Fix remote tests, warn when fetching git->bzr and bzr->git.
118
        self.assertEqual(error,
7143.15.2 by Jelmer Vernooij
Run autopep8.
119
                         'Fetching from Git to Bazaar repository. '
120
                         'For better performance, fetch into a Git repository.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
121
        self.assertEqual(output, '')
0.200.1151 by Jelmer Vernooij
Update NEWS, add test for bug fixed earlier.
122
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
123
    def test_branch_ls(self):
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
124
        self.simple_commit()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
125
        output, error = self.run_bzr(['ls', '-r-1'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
126
        self.assertEqual(error, '')
127
        self.assertEqual(output, "a\n")
0.200.78 by Jelmer Vernooij
Add blackbox test for ls.
128
0.200.108 by Jelmer Vernooij
Support bzr init --git.
129
    def test_init(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
130
        self.run_bzr("init --format=git repo")
0.200.108 by Jelmer Vernooij
Support bzr init --git.
131
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
132
    def test_info_verbose(self):
133
        self.simple_commit()
134
135
        output, error = self.run_bzr(['info', '-v'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
136
        self.assertEqual(error, '')
137
        self.assertTrue("Standalone tree (format: git)" in output)
138
        self.assertTrue("control: Local Git Repository" in output)
139
        self.assertTrue("branch: Local Git Branch" in output)
140
        self.assertTrue("repository: Git Repository" in output)
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
141
0.200.1325 by Jelmer Vernooij
More test fixes.
142
    def test_push_roundtripping(self):
0.267.1 by Martin
Don't raise the deprecated KnownFailure from tests
143
        self.knownFailure("roundtripping is not yet supported")
0.200.1325 by Jelmer Vernooij
More test fixes.
144
        self.with_roundtripping()
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
145
        os.mkdir("bla")
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
146
        GitRepo.init(os.path.join(self.test_dir, "bla"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
147
        self.run_bzr(['init', 'foo'])
148
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
0.200.1156 by Jelmer Vernooij
Disable push.
149
        # when roundtripping is supported
0.252.12 by Jelmer Vernooij
Fix push blackbox test.
150
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
151
        self.assertEqual(b"", output)
152
        self.assertTrue(error.endswith(b"Created new branch.\n"))
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
153
7296.4.1 by Jelmer Vernooij
Fix pushing non-mainline revisions from bzr to git.
154
    def test_push_lossy_non_mainline(self):
155
        self.run_bzr(['init', '--git', 'bla'])
156
        self.run_bzr(['init', 'foo'])
157
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
158
        self.run_bzr(['branch', 'foo', 'foo1'])
159
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
160
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
161
        self.run_bzr(['merge', '-d', 'foo', 'foo1'])
162
        self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
163
        output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
7296.4.2 by Jelmer Vernooij
Fix test.
164
        self.assertEqual("", output)
7296.4.1 by Jelmer Vernooij
Fix pushing non-mainline revisions from bzr to git.
165
        self.assertEqual(
7296.4.2 by Jelmer Vernooij
Fix test.
166
            'Pushing from a Bazaar to a Git repository. For better '
167
            'performance, push into a Bazaar repository.\n'
7350.1.3 by Vincent Ladeuil
Fix test_push_lossy_non_mainline failure.
168
            'All changes applied successfully.\n'
7296.4.2 by Jelmer Vernooij
Fix test.
169
            'Pushed up to revision 2.\n', error)
7296.4.1 by Jelmer Vernooij
Fix pushing non-mainline revisions from bzr to git.
170
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
171
    def test_log(self):
172
        # Smoke test for "bzr log" in a git repository.
0.200.76 by Jelmer Vernooij
Add blackbox test for info -v
173
        self.simple_commit()
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
174
175
        # Check that bzr log does not fail and includes the revision.
176
        output, error = self.run_bzr(['log'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
177
        self.assertEqual(error, '')
0.200.39 by David Allouche
Black-box text for "bzr log" in a git tree. Further simplification of GitRevisionTree.
178
        self.assertTrue(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
179
            '<The commit message>' in output,
180
            "Commit message was not found in output:\n%s" % (output,))
0.200.80 by Jelmer Vernooij
Add blackbox test for bzr log -v.
181
182
    def test_log_verbose(self):
183
        # Smoke test for "bzr log -v" in a git repository.
184
        self.simple_commit()
185
186
        # Check that bzr log does not fail and includes the revision.
187
        output, error = self.run_bzr(['log', '-v'])
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
188
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
189
    def test_tags(self):
0.200.444 by Jelmer Vernooij
Stop running git in blackbox tests.
190
        git_repo, commit_sha1 = self.simple_commit()
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
191
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
192
193
        output, error = self.run_bzr(['tags'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
194
        self.assertEqual(error, '')
195
        self.assertEqual(output, "foo                  1\n")
0.200.83 by Jelmer Vernooij
Add blackbox test for 'bzr tags'
196
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
197
    def test_tag(self):
198
        self.simple_commit()
199
200
        output, error = self.run_bzr(["tag", "bar"])
201
0.258.1 by Max Bowsher
Make tests tolerant to bzr <= 2.2.
202
        # bzr <= 2.2 emits this message in the output stream
203
        # bzr => 2.3 emits this message in the error stream
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
204
        self.assertEqual(error + output, 'Created tag bar.\n')
0.200.85 by Jelmer Vernooij
Add test for creating new tags.
205
0.200.288 by Jelmer Vernooij
Add test for init-repo.
206
    def test_init_repo(self):
0.200.1653 by Jelmer Vernooij
--git is now --format=git.
207
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
208
        self.assertEqual(error, '')
209
        self.assertEqual(output, 'Created a standalone tree (format: git)\n')
0.200.288 by Jelmer Vernooij
Add test for init-repo.
210
0.200.1332 by Jelmer Vernooij
Add smoke test for 'bzr diff --format=git'.
211
    def test_diff_format(self):
212
        tree = self.make_branch_and_tree('.')
213
        self.build_tree(['a'])
214
        tree.add(['a'])
215
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
216
        self.assertEqual(error, '')
7290.27.1 by Vincent Ladeuil
Backport dulwich fix.
217
        # Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
218
        # differently.
7324.1.1 by Jelmer Vernooij
Fix compatibility with pre-0.19.12 versions of Dulwich.
219
        from dulwich import __version__ as dulwich_version
220
        if dulwich_version < (0, 19, 12):
221
            self.assertEqual(output,
222
                             'diff --git /dev/null b/a\n'
223
                             'old mode 0\n'
224
                             'new mode 100644\n'
225
                             'index 0000000..c197bd8 100644\n'
226
                             '--- /dev/null\n'
227
                             '+++ b/a\n'
228
                             '@@ -0,0 +1 @@\n'
229
                             '+contents of a\n')
230
        else:
231
            self.assertEqual(output,
232
                             'diff --git a/a b/a\n'
233
                             'old file mode 0\n'
234
                             'new file mode 100644\n'
235
                             'index 0000000..c197bd8 100644\n'
236
                             '--- /dev/null\n'
237
                             '+++ b/a\n'
238
                             '@@ -0,0 +1 @@\n'
239
                             '+contents of a\n')
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
240
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
241
    def test_git_import_uncolocated(self):
242
        r = GitRepo.init("a", mkdir=True)
243
        self.build_tree(["a/file"])
244
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
245
        r.do_commit(ref=b"refs/heads/abranch",
246
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
247
        r.do_commit(ref=b"refs/heads/bbranch",
248
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
249
        self.run_bzr(["git-import", "a", "b"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
250
        self.assertEqual(
251
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
252
0.200.1450 by Jelmer Vernooij
Fix git-import after branch refactoring.
253
    def test_git_import(self):
254
        r = GitRepo.init("a", mkdir=True)
255
        self.build_tree(["a/file"])
256
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
257
        r.do_commit(ref=b"refs/heads/abranch",
258
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
259
        r.do_commit(ref=b"refs/heads/bbranch",
260
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
261
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
262
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
263
        self.assertEqual(set(["abranch", "bbranch"]),
7143.15.2 by Jelmer Vernooij
Run autopep8.
264
                         set(ControlDir.open("b").get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
265
266
    def test_git_import_incremental(self):
267
        r = GitRepo.init("a", mkdir=True)
268
        self.build_tree(["a/file"])
269
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
270
        r.do_commit(ref=b"refs/heads/abranch",
271
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
272
        self.run_bzr(["git-import", "--colocated", "a", "b"])
273
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
274
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
275
        b = ControlDir.open("b")
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
276
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
0.200.1451 by Jelmer Vernooij
Add some more tests for git-import.
277
278
    def test_git_import_tags(self):
279
        r = GitRepo.init("a", mkdir=True)
280
        self.build_tree(["a/file"])
281
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
282
        cid = r.do_commit(ref=b"refs/heads/abranch",
283
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
284
        r[b"refs/tags/atag"] = cid
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
285
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
286
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
287
        b = ControlDir.open("b")
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
288
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
6964.2.3 by Jelmer Vernooij
Review comments.
289
        self.assertEqual(["atag"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
290
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
0.200.1452 by Jelmer Vernooij
Support colocated branches in 'bzr git-import', flatten namespace.
291
292
    def test_git_import_colo(self):
293
        r = GitRepo.init("a", mkdir=True)
294
        self.build_tree(["a/file"])
295
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
296
        r.do_commit(ref=b"refs/heads/abranch",
297
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
298
        r.do_commit(ref=b"refs/heads/bbranch",
299
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
300
        self.make_controldir("b", format="development-colo")
0.200.1609 by Jelmer Vernooij
Only create colocated branches in git-import if the --colocated option is specified.
301
        self.run_bzr(["git-import", "--colocated", "a", "b"])
6964.2.3 by Jelmer Vernooij
Review comments.
302
        self.assertEqual(
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
303
            set([b.name for b in ControlDir.open("b").list_branches()]),
0.200.1501 by Jelmer Vernooij
Provide ControlDir.get_branches.
304
            set(["abranch", "bbranch"]))
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
305
306
    def test_git_refs_from_git(self):
307
        r = GitRepo.init("a", mkdir=True)
308
        self.build_tree(["a/file"])
309
        r.stage("file")
7143.15.2 by Jelmer Vernooij
Run autopep8.
310
        cid = r.do_commit(ref=b"refs/heads/abranch",
311
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
312
        r[b"refs/tags/atag"] = cid
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
313
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
314
        self.assertEqual(stderr, "")
6964.2.3 by Jelmer Vernooij
Review comments.
315
        self.assertEqual(stdout,
7143.15.2 by Jelmer Vernooij
Run autopep8.
316
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
317
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
318
319
    def test_git_refs_from_bzr(self):
320
        tree = self.make_branch_and_tree('a')
321
        self.build_tree(["a/file"])
322
        tree.add(["file"])
7143.15.2 by Jelmer Vernooij
Run autopep8.
323
        revid = tree.commit(
324
            committer=b"Joe <joe@example.com>", message=b"Dummy")
0.200.1521 by Jelmer Vernooij
Fix git-refs command.
325
        tree.branch.tags.set_tag("atag", revid)
326
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
327
        self.assertEqual(stderr, "")
328
        self.assertTrue("refs/tags/atag -> " in stdout)
329
        self.assertTrue("HEAD -> " in stdout)
0.200.1591 by Jelmer Vernooij
Add basic test for dpush.
330
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
331
    def test_check(self):
332
        r = GitRepo.init("gitr", mkdir=True)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
333
        self.build_tree_contents([("gitr/foo", b"hello from git")])
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
334
        r.stage("foo")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
335
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
336
        out, err = self.run_bzr(["check", "gitr"])
337
        self.maxDiff = None
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
338
        self.assertEqual(out, '')
339
        self.assertTrue(err.endswith, '3 objects\n')
6965.1.2 by Jelmer Vernooij
Add test.
340
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
341
342
class ShallowTests(ExternalBase):
343
344
    def setUp(self):
345
        super(ShallowTests, self).setUp()
346
        # Smoke test for "bzr log" in a git repository with shallow depth.
347
        self.repo = GitRepo.init('gitr', mkdir=True)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
348
        self.build_tree_contents([("gitr/foo", b"hello from git")])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
349
        self.repo.stage("foo")
350
        self.repo.do_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
351
            b"message", committer=b"Somebody <user@example.com>",
7268.1.1 by Jelmer Vernooij
Fix compatibility with newer versions of Dulwich.
352
            author=b"Somebody <user@example.com>",
7143.15.2 by Jelmer Vernooij
Run autopep8.
353
            commit_timestamp=1526330165, commit_timezone=0,
354
            author_timestamp=1526330165, author_timezone=0,
355
            merge_heads=[b'aa' * 20])
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
356
6965.1.2 by Jelmer Vernooij
Add test.
357
    def test_log_shallow(self):
358
        # Check that bzr log does not fail and includes the revision.
359
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
7143.15.2 by Jelmer Vernooij
Run autopep8.
360
        self.assertEqual(
361
            error, 'brz: ERROR: Further revision history missing.\n')
6965.1.2 by Jelmer Vernooij
Add test.
362
        self.assertEqual(output,
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
                         '------------------------------------------------------------\n'
364
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
365
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
366
                         'committer: Somebody <user@example.com>\n'
367
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
368
                         'message:\n'
369
                         '  message\n')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
370
371
    def test_version_info_rio(self):
372
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
373
        self.assertEqual(error, '')
374
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
375
376
    def test_version_info_python(self):
377
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
378
        self.assertEqual(error, '')
379
        self.assertNotIn('revno:', output)
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
380
381
    def test_version_info_custom_with_revno(self):
382
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
383
            ['version-info', '--custom',
384
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
385
        self.assertEqual(
386
            error, 'brz: ERROR: Variable {revno} is not available.\n')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
387
        self.assertEqual(output, 'VERSION_INFO r')
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
388
389
    def test_version_info_custom_without_revno(self):
390
        output, error = self.run_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
391
            ['version-info', '--custom', '--template=VERSION_INFO \n',
392
             'gitr'])
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
393
        self.assertEqual(error, '')
394
        self.assertEqual(output, 'VERSION_INFO \n')
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
395
396
7143.18.1 by Jelmer Vernooij
Fix 'bzr switch' in git repositories.
397
class SwitchTests(ExternalBase):
398
399
    def test_switch_branch(self):
400
        # Create a git repository with a revision.
401
        repo = GitRepo.init(self.test_dir)
402
        builder = tests.GitBranchBuilder()
403
        builder.set_branch(b'refs/heads/oldbranch')
404
        builder.set_file('a', b'text for a\n', False)
405
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
406
        builder.set_branch(b'refs/heads/newbranch')
407
        builder.reset()
408
        builder.set_file('a', b'text for new a\n', False)
409
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
410
        builder.finish()
411
412
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
413
414
        repo.reset_index()
415
416
        output, error = self.run_bzr('switch oldbranch')
417
        self.assertEqual(output, '')
418
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
419
420
        self.assertFileEqual("text for a\n", 'a')
421
        tree = WorkingTree.open('.')
422
        with tree.lock_read():
423
            basis_tree = tree.basis_tree()
424
            with basis_tree.lock_read():
425
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
7143.18.2 by Jelmer Vernooij
Merge trunk.
426
427
7290.26.1 by Jelmer Vernooij
Fix switching in git repositories.
428
class SwitchScriptTests(TestCaseWithTransportAndScript):
429
430
    def test_switch_preserves(self):
431
        # See https://bugs.launchpad.net/brz/+bug/1820606
432
        self.run_script("""
433
$ brz init --git r
434
Created a standalone tree (format: git)
435
$ cd r
436
$ echo original > file.txt
437
$ brz add
438
adding file.txt
439
$ brz ci -q -m "Initial"
440
$ echo "entered on master branch" > file.txt
441
$ brz stat
442
modified:
443
  file.txt
444
$ brz switch -b other
445
2>Tree is up to date at revision 1.
446
2>Switched to branch other
447
$ cat file.txt
448
entered on master branch
449
""")
450
451
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
452
class GrepTests(ExternalBase):
453
454
    def test_simple_grep(self):
455
        tree = self.make_branch_and_tree('.', format='git')
456
        self.build_tree_contents([('a', 'text for a\n')])
457
        tree.add(['a'])
458
        output, error = self.run_bzr('grep text')
459
        self.assertEqual(output, 'a:text for a\n')
460
        self.assertEqual(error, '')
7211.8.1 by Jelmer Vernooij
Fix stats in Python3 git repositories.
461
462
7206.6.4 by Jelmer Vernooij
Move reconcile logic to breezy.bzr.reconcile.
463
class ReconcileTests(ExternalBase):
464
465
    def test_simple_reconcile(self):
466
        tree = self.make_branch_and_tree('.', format='git')
467
        self.build_tree_contents([('a', 'text for a\n')])
468
        tree.add(['a'])
469
        output, error = self.run_bzr('reconcile')
470
        self.assertContainsRe(
471
            output,
472
            'Reconciling branch file://.*\n'
473
            'Reconciling repository file://.*\n'
474
            'Reconciliation complete.\n')
475
        self.assertEqual(error, '')
7206.6.6 by Jelmer Vernooij
Merge trunk.
476
477
7211.10.1 by Jelmer Vernooij
Add test for status with an empty dir.
478
class StatusTests(ExternalBase):
479
480
    def test_empty_dir(self):
481
        tree = self.make_branch_and_tree('.', format='git')
482
        self.build_tree(['a/', 'a/foo'])
483
        self.build_tree_contents([('.gitignore', 'foo\n')])
484
        tree.add(['.gitignore'])
485
        tree.commit('add ignore')
486
        output, error = self.run_bzr('st')
7211.10.5 by Jelmer Vernooij
Fix handling of directories.
487
        self.assertEqual(output, '')
7211.10.1 by Jelmer Vernooij
Add test for status with an empty dir.
488
        self.assertEqual(error, '')
7211.10.6 by Jelmer Vernooij
Merge trunk.
489
490
7211.8.1 by Jelmer Vernooij
Fix stats in Python3 git repositories.
491
class StatsTests(ExternalBase):
492
493
    def test_simple_stats(self):
494
        self.requireFeature(PluginLoadedFeature('stats'))
495
        tree = self.make_branch_and_tree('.', format='git')
496
        self.build_tree_contents([('a', 'text for a\n')])
497
        tree.add(['a'])
498
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
499
        output, error = self.run_bzr('stats')
500
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
7233.2.1 by Jelmer Vernooij
Fix import for git-objects.
501
502
503
class GitObjectsTests(ExternalBase):
504
505
    def run_simple(self, format):
506
        tree = self.make_branch_and_tree('.', format=format)
507
        self.build_tree(['a/', 'a/foo'])
508
        tree.add(['a'])
509
        tree.commit('add a')
510
        output, error = self.run_bzr('git-objects')
511
        shas = list(output.splitlines())
512
        self.assertEqual([40, 40], [len(s) for s in shas])
513
        self.assertEqual(error, '')
514
515
        output, error = self.run_bzr('git-object %s' % shas[0])
516
        self.assertEqual('', error)
517
518
    def test_in_native(self):
519
        self.run_simple(format='git')
520
521
    def test_in_bzr(self):
522
        self.run_simple(format='2a')
7268.7.1 by Jelmer Vernooij
Fix git-apply.
523
524
525
class GitApplyTests(ExternalBase):
526
527
    def test_apply(self):
528
        b = self.make_branch_and_tree('.')
529
530
        with open('foo.patch', 'w') as f:
531
            f.write("""\
532
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
533
From: Dmitry Bogatov <KAction@debian.org>
534
Date: Fri, 8 Feb 2019 23:28:30 +0000
535
Subject: [PATCH] Add fixed for out-of-date-standards-version
536
537
---
538
 message           | 3 +++
539
 1 files changed, 14 insertions(+)
540
 create mode 100644 message
541
542
diff --git a/message b/message
543
new file mode 100644
544
index 0000000..05ec0b1
545
--- /dev/null
546
+++ b/message
547
@@ -0,0 +1,3 @@
548
+Update standards version, no changes needed.
549
+Certainty: certain
550
+Fixed-Lintian-Tags: out-of-date-standards-version
551
""")
552
        output, error = self.run_bzr('git-apply foo.patch')
553
        self.assertContainsRe(
554
            error,
555
            'Committing to: .*\n'
556
            'Committed revision 1.\n')