/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/git/tests/test_blackbox.py

  • Committer: Jelmer Vernooij
  • Date: 2019-07-12 01:01:45 UTC
  • mto: This revision was merged to the branch mainline in revision 7375.
  • Revision ID: jelmer@jelmer.uk-20190712010145-m7224qumb8w068zw
Fix importing from remote git repositories.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 David Allouche <ddaa@ddaa.net>
 
2
# Copyright (C) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
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
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 
 
18
"""Black-box tests for bzr-git."""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from dulwich.repo import (
 
23
    Repo as GitRepo,
 
24
    )
 
25
 
 
26
import os
 
27
 
 
28
from ...controldir import (
 
29
    ControlDir,
 
30
    )
 
31
 
 
32
from ...tests.blackbox import ExternalBase
 
33
from ...workingtree import WorkingTree
 
34
 
 
35
from .. import (
 
36
    tests,
 
37
    )
 
38
from ...tests.script import TestCaseWithTransportAndScript
 
39
from ...tests.features import PluginLoadedFeature
 
40
 
 
41
 
 
42
class TestGitBlackBox(ExternalBase):
 
43
 
 
44
    def simple_commit(self):
 
45
        # Create a git repository with a revision.
 
46
        repo = GitRepo.init(self.test_dir)
 
47
        builder = tests.GitBranchBuilder()
 
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>')
 
50
        return repo, builder.finish()[r1]
 
51
 
 
52
    def test_nick(self):
 
53
        r = GitRepo.init(self.test_dir)
 
54
        dir = ControlDir.open(self.test_dir)
 
55
        dir.create_branch()
 
56
        output, error = self.run_bzr(['nick'])
 
57
        self.assertEqual("master\n", output)
 
58
 
 
59
    def test_branches(self):
 
60
        self.simple_commit()
 
61
        output, error = self.run_bzr(['branches'])
 
62
        self.assertEqual("* master\n", output)
 
63
 
 
64
    def test_info(self):
 
65
        self.simple_commit()
 
66
        output, error = self.run_bzr(['info'])
 
67
        self.assertEqual(error, '')
 
68
        self.assertEqual(
 
69
            output,
 
70
            'Standalone tree (format: git)\n'
 
71
            'Location:\n'
 
72
            '            light checkout root: .\n'
 
73
            '  checkout of co-located branch: master\n')
 
74
 
 
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
 
 
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
 
 
91
    def test_branch(self):
 
92
        os.mkdir("gitbranch")
 
93
        GitRepo.init(os.path.join(self.test_dir, "gitbranch"))
 
94
        os.chdir('gitbranch')
 
95
        builder = tests.GitBranchBuilder()
 
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>')
 
98
        builder.finish()
 
99
        os.chdir('..')
 
100
 
 
101
        output, error = self.run_bzr(['branch', 'gitbranch', 'bzrbranch'])
 
102
        self.assertTrue(
 
103
            (error == 'Branched 1 revision(s).\n') or
 
104
            (error == 'Branched 1 revision.\n'),
 
105
            error)
 
106
 
 
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()
 
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>')
 
114
        builder.finish()
 
115
        os.chdir('..')
 
116
 
 
117
        output, error = self.run_bzr(['checkout', 'gitbranch', 'bzrbranch'])
 
118
        self.assertEqual(error,
 
119
                         'Fetching from Git to Bazaar repository. '
 
120
                         'For better performance, fetch into a Git repository.\n')
 
121
        self.assertEqual(output, '')
 
122
 
 
123
    def test_branch_ls(self):
 
124
        self.simple_commit()
 
125
        output, error = self.run_bzr(['ls', '-r-1'])
 
126
        self.assertEqual(error, '')
 
127
        self.assertEqual(output, "a\n")
 
128
 
 
129
    def test_init(self):
 
130
        self.run_bzr("init --format=git repo")
 
131
 
 
132
    def test_info_verbose(self):
 
133
        self.simple_commit()
 
134
 
 
135
        output, error = self.run_bzr(['info', '-v'])
 
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)
 
141
 
 
142
    def test_push_roundtripping(self):
 
143
        self.knownFailure("roundtripping is not yet supported")
 
144
        self.with_roundtripping()
 
145
        os.mkdir("bla")
 
146
        GitRepo.init(os.path.join(self.test_dir, "bla"))
 
147
        self.run_bzr(['init', 'foo'])
 
148
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
149
        # when roundtripping is supported
 
150
        output, error = self.run_bzr(['push', '-d', 'foo', 'bla'])
 
151
        self.assertEqual(b"", output)
 
152
        self.assertTrue(error.endswith(b"Created new branch.\n"))
 
153
 
 
154
    def test_push_without_calculate_revnos(self):
 
155
        self.run_bzr(['init', '--git', 'bla'])
 
156
        self.run_bzr(['init', '--git', 'foo'])
 
157
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
158
        output, error = self.run_bzr(
 
159
            ['push', '-Ocalculate_revnos=no', '-d', 'foo', 'bla'])
 
160
        self.assertEqual("", output)
 
161
        self.assertContainsRe(
 
162
            error,
 
163
            'Pushed up to revision id git(.*).\n')
 
164
 
 
165
    def test_push_lossy_non_mainline(self):
 
166
        self.run_bzr(['init', '--git', 'bla'])
 
167
        self.run_bzr(['init', 'foo'])
 
168
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
169
        self.run_bzr(['branch', 'foo', 'foo1'])
 
170
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
 
171
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
 
172
        self.run_bzr(['merge', '-d', 'foo', 'foo1'])
 
173
        self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
 
174
        output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
 
175
        self.assertEqual("", output)
 
176
        self.assertEqual(
 
177
            'Pushing from a Bazaar to a Git repository. For better '
 
178
            'performance, push into a Bazaar repository.\n'
 
179
            'All changes applied successfully.\n'
 
180
            'Pushed up to revision 2.\n', error)
 
181
 
 
182
    def test_log(self):
 
183
        # Smoke test for "bzr log" 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'])
 
188
        self.assertEqual(error, '')
 
189
        self.assertTrue(
 
190
            '<The commit message>' in output,
 
191
            "Commit message was not found in output:\n%s" % (output,))
 
192
 
 
193
    def test_log_verbose(self):
 
194
        # Smoke test for "bzr log -v" in a git repository.
 
195
        self.simple_commit()
 
196
 
 
197
        # Check that bzr log does not fail and includes the revision.
 
198
        output, error = self.run_bzr(['log', '-v'])
 
199
        self.assertContainsRe(output, 'revno: 1')
 
200
 
 
201
    def test_log_without_revno(self):
 
202
        # Smoke test for "bzr log -v" in a git repository.
 
203
        self.simple_commit()
 
204
 
 
205
        # Check that bzr log does not fail and includes the revision.
 
206
        output, error = self.run_bzr(['log', '-Ocalculate_revnos=no'])
 
207
        self.assertNotContainsRe(output, 'revno: 1')
 
208
 
 
209
    def test_commit_without_revno(self):
 
210
        repo = GitRepo.init(self.test_dir)
 
211
        output, error = self.run_bzr(
 
212
            ['commit', '-Ocalculate_revnos=yes', '--unchanged', '-m', 'one'])
 
213
        self.assertContainsRe(error, 'Committed revision 1.')
 
214
        output, error = self.run_bzr(
 
215
            ['commit', '-Ocalculate_revnos=no', '--unchanged', '-m', 'two'])
 
216
        self.assertNotContainsRe(error, 'Committed revision 2.')
 
217
        self.assertContainsRe(error, 'Committed revid .*.')
 
218
 
 
219
    def test_tags(self):
 
220
        git_repo, commit_sha1 = self.simple_commit()
 
221
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
 
222
 
 
223
        output, error = self.run_bzr(['tags'])
 
224
        self.assertEqual(error, '')
 
225
        self.assertEqual(output, "foo                  1\n")
 
226
 
 
227
    def test_tag(self):
 
228
        self.simple_commit()
 
229
 
 
230
        output, error = self.run_bzr(["tag", "bar"])
 
231
 
 
232
        # bzr <= 2.2 emits this message in the output stream
 
233
        # bzr => 2.3 emits this message in the error stream
 
234
        self.assertEqual(error + output, 'Created tag bar.\n')
 
235
 
 
236
    def test_init_repo(self):
 
237
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
 
238
        self.assertEqual(error, '')
 
239
        self.assertEqual(output, 'Created a standalone tree (format: git)\n')
 
240
 
 
241
    def test_diff_format(self):
 
242
        tree = self.make_branch_and_tree('.')
 
243
        self.build_tree(['a'])
 
244
        tree.add(['a'])
 
245
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
 
246
        self.assertEqual(error, '')
 
247
        # Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
 
248
        # differently.
 
249
        from dulwich import __version__ as dulwich_version
 
250
        if dulwich_version < (0, 19, 12):
 
251
            self.assertEqual(output,
 
252
                             'diff --git /dev/null b/a\n'
 
253
                             'old mode 0\n'
 
254
                             'new mode 100644\n'
 
255
                             'index 0000000..c197bd8 100644\n'
 
256
                             '--- /dev/null\n'
 
257
                             '+++ b/a\n'
 
258
                             '@@ -0,0 +1 @@\n'
 
259
                             '+contents of a\n')
 
260
        else:
 
261
            self.assertEqual(output,
 
262
                             'diff --git a/a b/a\n'
 
263
                             'old file mode 0\n'
 
264
                             'new file mode 100644\n'
 
265
                             'index 0000000..c197bd8 100644\n'
 
266
                             '--- /dev/null\n'
 
267
                             '+++ b/a\n'
 
268
                             '@@ -0,0 +1 @@\n'
 
269
                             '+contents of a\n')
 
270
 
 
271
    def test_git_import_uncolocated(self):
 
272
        r = GitRepo.init("a", mkdir=True)
 
273
        self.build_tree(["a/file"])
 
274
        r.stage("file")
 
275
        r.do_commit(ref=b"refs/heads/abranch",
 
276
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
277
        r.do_commit(ref=b"refs/heads/bbranch",
 
278
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
279
        self.run_bzr(["git-import", "a", "b"])
 
280
        self.assertEqual(
 
281
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
 
282
 
 
283
    def test_git_import(self):
 
284
        r = GitRepo.init("a", mkdir=True)
 
285
        self.build_tree(["a/file"])
 
286
        r.stage("file")
 
287
        r.do_commit(ref=b"refs/heads/abranch",
 
288
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
289
        r.do_commit(ref=b"refs/heads/bbranch",
 
290
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
291
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
292
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
293
        self.assertEqual(set(["abranch", "bbranch"]),
 
294
                         set(ControlDir.open("b").get_branches().keys()))
 
295
 
 
296
    def test_git_import_incremental(self):
 
297
        r = GitRepo.init("a", mkdir=True)
 
298
        self.build_tree(["a/file"])
 
299
        r.stage("file")
 
300
        r.do_commit(ref=b"refs/heads/abranch",
 
301
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
302
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
303
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
304
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
305
        b = ControlDir.open("b")
 
306
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
307
 
 
308
    def test_git_import_tags(self):
 
309
        r = GitRepo.init("a", mkdir=True)
 
310
        self.build_tree(["a/file"])
 
311
        r.stage("file")
 
312
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
313
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
314
        r[b"refs/tags/atag"] = cid
 
315
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
316
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
317
        b = ControlDir.open("b")
 
318
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
319
        self.assertEqual(["atag"],
 
320
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
 
321
 
 
322
    def test_git_import_colo(self):
 
323
        r = GitRepo.init("a", mkdir=True)
 
324
        self.build_tree(["a/file"])
 
325
        r.stage("file")
 
326
        r.do_commit(ref=b"refs/heads/abranch",
 
327
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
328
        r.do_commit(ref=b"refs/heads/bbranch",
 
329
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
330
        self.make_controldir("b", format="development-colo")
 
331
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
332
        self.assertEqual(
 
333
            set([b.name for b in ControlDir.open("b").list_branches()]),
 
334
            set(["abranch", "bbranch"]))
 
335
 
 
336
    def test_git_refs_from_git(self):
 
337
        r = GitRepo.init("a", mkdir=True)
 
338
        self.build_tree(["a/file"])
 
339
        r.stage("file")
 
340
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
341
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
342
        r[b"refs/tags/atag"] = cid
 
343
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
344
        self.assertEqual(stderr, "")
 
345
        self.assertEqual(stdout,
 
346
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
 
347
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
 
348
 
 
349
    def test_git_refs_from_bzr(self):
 
350
        tree = self.make_branch_and_tree('a')
 
351
        self.build_tree(["a/file"])
 
352
        tree.add(["file"])
 
353
        revid = tree.commit(
 
354
            committer=b"Joe <joe@example.com>", message=b"Dummy")
 
355
        tree.branch.tags.set_tag("atag", revid)
 
356
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
357
        self.assertEqual(stderr, "")
 
358
        self.assertTrue("refs/tags/atag -> " in stdout)
 
359
        self.assertTrue("HEAD -> " in stdout)
 
360
 
 
361
    def test_check(self):
 
362
        r = GitRepo.init("gitr", mkdir=True)
 
363
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
364
        r.stage("foo")
 
365
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
 
366
        out, err = self.run_bzr(["check", "gitr"])
 
367
        self.maxDiff = None
 
368
        self.assertEqual(out, '')
 
369
        self.assertTrue(err.endswith, '3 objects\n')
 
370
 
 
371
 
 
372
class ShallowTests(ExternalBase):
 
373
 
 
374
    def setUp(self):
 
375
        super(ShallowTests, self).setUp()
 
376
        # Smoke test for "bzr log" in a git repository with shallow depth.
 
377
        self.repo = GitRepo.init('gitr', mkdir=True)
 
378
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
379
        self.repo.stage("foo")
 
380
        self.repo.do_commit(
 
381
            b"message", committer=b"Somebody <user@example.com>",
 
382
            author=b"Somebody <user@example.com>",
 
383
            commit_timestamp=1526330165, commit_timezone=0,
 
384
            author_timestamp=1526330165, author_timezone=0,
 
385
            merge_heads=[b'aa' * 20])
 
386
 
 
387
    def test_log_shallow(self):
 
388
        # Check that bzr log does not fail and includes the revision.
 
389
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
 
390
        self.assertEqual(
 
391
            error, 'brz: ERROR: Further revision history missing.\n')
 
392
        self.assertEqual(output,
 
393
                         '------------------------------------------------------------\n'
 
394
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
 
395
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
 
396
                         'committer: Somebody <user@example.com>\n'
 
397
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
 
398
                         'message:\n'
 
399
                         '  message\n')
 
400
 
 
401
    def test_version_info_rio(self):
 
402
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
 
403
        self.assertEqual(error, '')
 
404
        self.assertNotIn('revno:', output)
 
405
 
 
406
    def test_version_info_python(self):
 
407
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
 
408
        self.assertEqual(error, '')
 
409
        self.assertNotIn('revno:', output)
 
410
 
 
411
    def test_version_info_custom_with_revno(self):
 
412
        output, error = self.run_bzr(
 
413
            ['version-info', '--custom',
 
414
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
 
415
        self.assertEqual(
 
416
            error, 'brz: ERROR: Variable {revno} is not available.\n')
 
417
        self.assertEqual(output, 'VERSION_INFO r')
 
418
 
 
419
    def test_version_info_custom_without_revno(self):
 
420
        output, error = self.run_bzr(
 
421
            ['version-info', '--custom', '--template=VERSION_INFO \n',
 
422
             'gitr'])
 
423
        self.assertEqual(error, '')
 
424
        self.assertEqual(output, 'VERSION_INFO \n')
 
425
 
 
426
 
 
427
class SwitchTests(ExternalBase):
 
428
 
 
429
    def test_switch_branch(self):
 
430
        # Create a git repository with a revision.
 
431
        repo = GitRepo.init(self.test_dir)
 
432
        builder = tests.GitBranchBuilder()
 
433
        builder.set_branch(b'refs/heads/oldbranch')
 
434
        builder.set_file('a', b'text for a\n', False)
 
435
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
436
        builder.set_branch(b'refs/heads/newbranch')
 
437
        builder.reset()
 
438
        builder.set_file('a', b'text for new a\n', False)
 
439
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
440
        builder.finish()
 
441
 
 
442
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
 
443
 
 
444
        repo.reset_index()
 
445
 
 
446
        output, error = self.run_bzr('switch oldbranch')
 
447
        self.assertEqual(output, '')
 
448
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
 
449
 
 
450
        self.assertFileEqual("text for a\n", 'a')
 
451
        tree = WorkingTree.open('.')
 
452
        with tree.lock_read():
 
453
            basis_tree = tree.basis_tree()
 
454
            with basis_tree.lock_read():
 
455
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
 
456
 
 
457
 
 
458
class SwitchScriptTests(TestCaseWithTransportAndScript):
 
459
 
 
460
    def test_switch_preserves(self):
 
461
        # See https://bugs.launchpad.net/brz/+bug/1820606
 
462
        self.run_script("""
 
463
$ brz init --git r
 
464
Created a standalone tree (format: git)
 
465
$ cd r
 
466
$ echo original > file.txt
 
467
$ brz add
 
468
adding file.txt
 
469
$ brz ci -q -m "Initial"
 
470
$ echo "entered on master branch" > file.txt
 
471
$ brz stat
 
472
modified:
 
473
  file.txt
 
474
$ brz switch -b other
 
475
2>Tree is up to date at revision 1.
 
476
2>Switched to branch other
 
477
$ cat file.txt
 
478
entered on master branch
 
479
""")
 
480
 
 
481
 
 
482
class GrepTests(ExternalBase):
 
483
 
 
484
    def test_simple_grep(self):
 
485
        tree = self.make_branch_and_tree('.', format='git')
 
486
        self.build_tree_contents([('a', 'text for a\n')])
 
487
        tree.add(['a'])
 
488
        output, error = self.run_bzr('grep text')
 
489
        self.assertEqual(output, 'a:text for a\n')
 
490
        self.assertEqual(error, '')
 
491
 
 
492
 
 
493
class ReconcileTests(ExternalBase):
 
494
 
 
495
    def test_simple_reconcile(self):
 
496
        tree = self.make_branch_and_tree('.', format='git')
 
497
        self.build_tree_contents([('a', 'text for a\n')])
 
498
        tree.add(['a'])
 
499
        output, error = self.run_bzr('reconcile')
 
500
        self.assertContainsRe(
 
501
            output,
 
502
            'Reconciling branch file://.*\n'
 
503
            'Reconciling repository file://.*\n'
 
504
            'Reconciliation complete.\n')
 
505
        self.assertEqual(error, '')
 
506
 
 
507
 
 
508
class StatusTests(ExternalBase):
 
509
 
 
510
    def test_empty_dir(self):
 
511
        tree = self.make_branch_and_tree('.', format='git')
 
512
        self.build_tree(['a/', 'a/foo'])
 
513
        self.build_tree_contents([('.gitignore', 'foo\n')])
 
514
        tree.add(['.gitignore'])
 
515
        tree.commit('add ignore')
 
516
        output, error = self.run_bzr('st')
 
517
        self.assertEqual(output, '')
 
518
        self.assertEqual(error, '')
 
519
 
 
520
 
 
521
class StatsTests(ExternalBase):
 
522
 
 
523
    def test_simple_stats(self):
 
524
        self.requireFeature(PluginLoadedFeature('stats'))
 
525
        tree = self.make_branch_and_tree('.', format='git')
 
526
        self.build_tree_contents([('a', 'text for a\n')])
 
527
        tree.add(['a'])
 
528
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
 
529
        output, error = self.run_bzr('stats')
 
530
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
 
531
 
 
532
 
 
533
class GitObjectsTests(ExternalBase):
 
534
 
 
535
    def run_simple(self, format):
 
536
        tree = self.make_branch_and_tree('.', format=format)
 
537
        self.build_tree(['a/', 'a/foo'])
 
538
        tree.add(['a'])
 
539
        tree.commit('add a')
 
540
        output, error = self.run_bzr('git-objects')
 
541
        shas = list(output.splitlines())
 
542
        self.assertEqual([40, 40], [len(s) for s in shas])
 
543
        self.assertEqual(error, '')
 
544
 
 
545
        output, error = self.run_bzr('git-object %s' % shas[0])
 
546
        self.assertEqual('', error)
 
547
 
 
548
    def test_in_native(self):
 
549
        self.run_simple(format='git')
 
550
 
 
551
    def test_in_bzr(self):
 
552
        self.run_simple(format='2a')
 
553
 
 
554
 
 
555
class GitApplyTests(ExternalBase):
 
556
 
 
557
    def test_apply(self):
 
558
        b = self.make_branch_and_tree('.')
 
559
 
 
560
        with open('foo.patch', 'w') as f:
 
561
            f.write("""\
 
562
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
 
563
From: Dmitry Bogatov <KAction@debian.org>
 
564
Date: Fri, 8 Feb 2019 23:28:30 +0000
 
565
Subject: [PATCH] Add fixed for out-of-date-standards-version
 
566
 
 
567
---
 
568
 message           | 3 +++
 
569
 1 files changed, 14 insertions(+)
 
570
 create mode 100644 message
 
571
 
 
572
diff --git a/message b/message
 
573
new file mode 100644
 
574
index 0000000..05ec0b1
 
575
--- /dev/null
 
576
+++ b/message
 
577
@@ -0,0 +1,3 @@
 
578
+Update standards version, no changes needed.
 
579
+Certainty: certain
 
580
+Fixed-Lintian-Tags: out-of-date-standards-version
 
581
""")
 
582
        output, error = self.run_bzr('git-apply foo.patch')
 
583
        self.assertContainsRe(
 
584
            error,
 
585
            'Committing to: .*\n'
 
586
            'Committed revision 1.\n')