/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-10-20 23:33:25 UTC
  • mto: (7290.1.39 work)
  • mto: This revision was merged to the branch mainline in revision 7414.
  • Revision ID: jelmer@jelmer.uk-20191020233325-7iec5axnaogpbewz
Fix filegraph operations on Git.

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_log(self):
 
155
        # Smoke test for "bzr log" in a git repository.
 
156
        self.simple_commit()
 
157
 
 
158
        # Check that bzr log does not fail and includes the revision.
 
159
        output, error = self.run_bzr(['log'])
 
160
        self.assertEqual(error, '')
 
161
        self.assertTrue(
 
162
            '<The commit message>' in output,
 
163
            "Commit message was not found in output:\n%s" % (output,))
 
164
 
 
165
    def test_log_verbose(self):
 
166
        # Smoke test for "bzr log -v" in a git repository.
 
167
        self.simple_commit()
 
168
 
 
169
        # Check that bzr log does not fail and includes the revision.
 
170
        output, error = self.run_bzr(['log', '-v'])
 
171
 
 
172
    def test_log_file(self):
 
173
        # Smoke test for "bzr log" in a git repository.
 
174
        repo = GitRepo.init(self.test_dir)
 
175
        builder = tests.GitBranchBuilder()
 
176
        builder.set_file('a', b'text for a\n', False)
 
177
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'First')
 
178
        builder.set_file('a', b'text 3a for a\n', False)
 
179
        r2a = builder.commit(b'Joe Foo <joe@foo.com>', u'Second a', base=r1)
 
180
        builder.set_file('a', b'text 3b for a\n', False)
 
181
        r2b = builder.commit(b'Joe Foo <joe@foo.com>', u'Second b', base=r1)
 
182
        builder.set_file('a', b'text 4 for a\n', False)
 
183
        builder.commit(b'Joe Foo <joe@foo.com>', u'Third', merge=[r2a], base=r2b)
 
184
        builder.finish()
 
185
 
 
186
        # Check that bzr log does not fail and includes the revision.
 
187
        output, error = self.run_bzr(['log', '-n2', 'a'])
 
188
        self.assertEqual(error, '')
 
189
        self.assertIn('Second a', output)
 
190
        self.assertIn('Second b', output)
 
191
        self.assertIn('First', output)
 
192
        self.assertIn('Third', output)
 
193
 
 
194
    def test_tags(self):
 
195
        git_repo, commit_sha1 = self.simple_commit()
 
196
        git_repo.refs[b"refs/tags/foo"] = commit_sha1
 
197
 
 
198
        output, error = self.run_bzr(['tags'])
 
199
        self.assertEqual(error, '')
 
200
        self.assertEqual(output, "foo                  1\n")
 
201
 
 
202
    def test_tag(self):
 
203
        self.simple_commit()
 
204
 
 
205
        output, error = self.run_bzr(["tag", "bar"])
 
206
 
 
207
        # bzr <= 2.2 emits this message in the output stream
 
208
        # bzr => 2.3 emits this message in the error stream
 
209
        self.assertEqual(error + output, 'Created tag bar.\n')
 
210
 
 
211
    def test_init_repo(self):
 
212
        output, error = self.run_bzr(["init", "--format=git", "bla.git"])
 
213
        self.assertEqual(error, '')
 
214
        self.assertEqual(output, 'Created a standalone tree (format: git)\n')
 
215
 
 
216
    def test_diff_format(self):
 
217
        tree = self.make_branch_and_tree('.')
 
218
        self.build_tree(['a'])
 
219
        tree.add(['a'])
 
220
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
 
221
        self.assertEqual(error, '')
 
222
        # Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
 
223
        # differently.
 
224
        from dulwich import __version__ as dulwich_version
 
225
        if dulwich_version < (0, 19, 12):
 
226
            self.assertEqual(output,
 
227
                             'diff --git /dev/null b/a\n'
 
228
                             'old mode 0\n'
 
229
                             'new mode 100644\n'
 
230
                             'index 0000000..c197bd8 100644\n'
 
231
                             '--- /dev/null\n'
 
232
                             '+++ b/a\n'
 
233
                             '@@ -0,0 +1 @@\n'
 
234
                             '+contents of a\n')
 
235
        else:
 
236
            self.assertEqual(output,
 
237
                             'diff --git a/a b/a\n'
 
238
                             'old file mode 0\n'
 
239
                             'new file mode 100644\n'
 
240
                             'index 0000000..c197bd8 100644\n'
 
241
                             '--- /dev/null\n'
 
242
                             '+++ b/a\n'
 
243
                             '@@ -0,0 +1 @@\n'
 
244
                             '+contents of a\n')
 
245
 
 
246
    def test_git_import_uncolocated(self):
 
247
        r = GitRepo.init("a", mkdir=True)
 
248
        self.build_tree(["a/file"])
 
249
        r.stage("file")
 
250
        r.do_commit(ref=b"refs/heads/abranch",
 
251
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
252
        r.do_commit(ref=b"refs/heads/bbranch",
 
253
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
254
        self.run_bzr(["git-import", "a", "b"])
 
255
        self.assertEqual(
 
256
            set([".bzr", "abranch", "bbranch"]), set(os.listdir("b")))
 
257
 
 
258
    def test_git_import(self):
 
259
        r = GitRepo.init("a", mkdir=True)
 
260
        self.build_tree(["a/file"])
 
261
        r.stage("file")
 
262
        r.do_commit(ref=b"refs/heads/abranch",
 
263
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
264
        r.do_commit(ref=b"refs/heads/bbranch",
 
265
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
266
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
267
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
268
        self.assertEqual(set(["abranch", "bbranch"]),
 
269
                         set(ControlDir.open("b").get_branches().keys()))
 
270
 
 
271
    def test_git_import_incremental(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
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
278
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
279
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
280
        b = ControlDir.open("b")
 
281
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
282
 
 
283
    def test_git_import_tags(self):
 
284
        r = GitRepo.init("a", mkdir=True)
 
285
        self.build_tree(["a/file"])
 
286
        r.stage("file")
 
287
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
288
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
289
        r[b"refs/tags/atag"] = cid
 
290
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
291
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
 
292
        b = ControlDir.open("b")
 
293
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
 
294
        self.assertEqual(["atag"],
 
295
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
 
296
 
 
297
    def test_git_import_colo(self):
 
298
        r = GitRepo.init("a", mkdir=True)
 
299
        self.build_tree(["a/file"])
 
300
        r.stage("file")
 
301
        r.do_commit(ref=b"refs/heads/abranch",
 
302
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
303
        r.do_commit(ref=b"refs/heads/bbranch",
 
304
                    committer=b"Joe <joe@example.com>", message=b"Dummy")
 
305
        self.make_controldir("b", format="development-colo")
 
306
        self.run_bzr(["git-import", "--colocated", "a", "b"])
 
307
        self.assertEqual(
 
308
            set([b.name for b in ControlDir.open("b").list_branches()]),
 
309
            set(["abranch", "bbranch"]))
 
310
 
 
311
    def test_git_refs_from_git(self):
 
312
        r = GitRepo.init("a", mkdir=True)
 
313
        self.build_tree(["a/file"])
 
314
        r.stage("file")
 
315
        cid = r.do_commit(ref=b"refs/heads/abranch",
 
316
                          committer=b"Joe <joe@example.com>", message=b"Dummy")
 
317
        r[b"refs/tags/atag"] = cid
 
318
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
319
        self.assertEqual(stderr, "")
 
320
        self.assertEqual(stdout,
 
321
                         'refs/heads/abranch -> ' + cid.decode('ascii') + '\n'
 
322
                         'refs/tags/atag -> ' + cid.decode('ascii') + '\n')
 
323
 
 
324
    def test_git_refs_from_bzr(self):
 
325
        tree = self.make_branch_and_tree('a')
 
326
        self.build_tree(["a/file"])
 
327
        tree.add(["file"])
 
328
        revid = tree.commit(
 
329
            committer=b"Joe <joe@example.com>", message=b"Dummy")
 
330
        tree.branch.tags.set_tag("atag", revid)
 
331
        (stdout, stderr) = self.run_bzr(["git-refs", "a"])
 
332
        self.assertEqual(stderr, "")
 
333
        self.assertTrue("refs/tags/atag -> " in stdout)
 
334
        self.assertTrue("HEAD -> " in stdout)
 
335
 
 
336
    def test_check(self):
 
337
        r = GitRepo.init("gitr", mkdir=True)
 
338
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
339
        r.stage("foo")
 
340
        r.do_commit(b"message", committer=b"Somebody <user@example.com>")
 
341
        out, err = self.run_bzr(["check", "gitr"])
 
342
        self.maxDiff = None
 
343
        self.assertEqual(out, '')
 
344
        self.assertTrue(err.endswith, '3 objects\n')
 
345
 
 
346
 
 
347
class ShallowTests(ExternalBase):
 
348
 
 
349
    def setUp(self):
 
350
        super(ShallowTests, self).setUp()
 
351
        # Smoke test for "bzr log" in a git repository with shallow depth.
 
352
        self.repo = GitRepo.init('gitr', mkdir=True)
 
353
        self.build_tree_contents([("gitr/foo", b"hello from git")])
 
354
        self.repo.stage("foo")
 
355
        self.repo.do_commit(
 
356
            b"message", committer=b"Somebody <user@example.com>",
 
357
            author=b"Somebody <user@example.com>",
 
358
            commit_timestamp=1526330165, commit_timezone=0,
 
359
            author_timestamp=1526330165, author_timezone=0,
 
360
            merge_heads=[b'aa' * 20])
 
361
 
 
362
    def test_log_shallow(self):
 
363
        # Check that bzr log does not fail and includes the revision.
 
364
        output, error = self.run_bzr(['log', 'gitr'], retcode=3)
 
365
        self.assertEqual(
 
366
            error, 'brz: ERROR: Further revision history missing.\n')
 
367
        self.assertEqual(output,
 
368
                         '------------------------------------------------------------\n'
 
369
                         'revision-id: git-v1:' + self.repo.head().decode('ascii') + '\n'
 
370
                         'git commit: ' + self.repo.head().decode('ascii') + '\n'
 
371
                         'committer: Somebody <user@example.com>\n'
 
372
                         'timestamp: Mon 2018-05-14 20:36:05 +0000\n'
 
373
                         'message:\n'
 
374
                         '  message\n')
 
375
 
 
376
    def test_version_info_rio(self):
 
377
        output, error = self.run_bzr(['version-info', '--rio', 'gitr'])
 
378
        self.assertEqual(error, '')
 
379
        self.assertNotIn('revno:', output)
 
380
 
 
381
    def test_version_info_python(self):
 
382
        output, error = self.run_bzr(['version-info', '--python', 'gitr'])
 
383
        self.assertEqual(error, '')
 
384
        self.assertNotIn('revno:', output)
 
385
 
 
386
    def test_version_info_custom_with_revno(self):
 
387
        output, error = self.run_bzr(
 
388
            ['version-info', '--custom',
 
389
             '--template=VERSION_INFO r{revno})\n', 'gitr'], retcode=3)
 
390
        self.assertEqual(
 
391
            error, 'brz: ERROR: Variable {revno} is not available.\n')
 
392
        self.assertEqual(output, 'VERSION_INFO r')
 
393
 
 
394
    def test_version_info_custom_without_revno(self):
 
395
        output, error = self.run_bzr(
 
396
            ['version-info', '--custom', '--template=VERSION_INFO \n',
 
397
             'gitr'])
 
398
        self.assertEqual(error, '')
 
399
        self.assertEqual(output, 'VERSION_INFO \n')
 
400
 
 
401
 
 
402
class SwitchTests(ExternalBase):
 
403
 
 
404
    def test_switch_branch(self):
 
405
        # Create a git repository with a revision.
 
406
        repo = GitRepo.init(self.test_dir)
 
407
        builder = tests.GitBranchBuilder()
 
408
        builder.set_branch(b'refs/heads/oldbranch')
 
409
        builder.set_file('a', b'text for a\n', False)
 
410
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
411
        builder.set_branch(b'refs/heads/newbranch')
 
412
        builder.reset()
 
413
        builder.set_file('a', b'text for new a\n', False)
 
414
        builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
 
415
        builder.finish()
 
416
 
 
417
        repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/newbranch')
 
418
 
 
419
        repo.reset_index()
 
420
 
 
421
        output, error = self.run_bzr('switch oldbranch')
 
422
        self.assertEqual(output, '')
 
423
        self.assertTrue(error.startswith('Updated to revision 1.\n'), error)
 
424
 
 
425
        self.assertFileEqual("text for a\n", 'a')
 
426
        tree = WorkingTree.open('.')
 
427
        with tree.lock_read():
 
428
            basis_tree = tree.basis_tree()
 
429
            with basis_tree.lock_read():
 
430
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
 
431
 
 
432
 
 
433
class SwitchScriptTests(TestCaseWithTransportAndScript):
 
434
 
 
435
    def test_switch_preserves(self):
 
436
        # See https://bugs.launchpad.net/brz/+bug/1820606
 
437
        self.run_script("""
 
438
$ brz init --git r
 
439
Created a standalone tree (format: git)
 
440
$ cd r
 
441
$ echo original > file.txt
 
442
$ brz add
 
443
adding file.txt
 
444
$ brz ci -q -m "Initial"
 
445
$ echo "entered on master branch" > file.txt
 
446
$ brz stat
 
447
modified:
 
448
  file.txt
 
449
$ brz switch -b other
 
450
2>Tree is up to date at revision 1.
 
451
2>Switched to branch other
 
452
$ cat file.txt
 
453
entered on master branch
 
454
""")
 
455
 
 
456
 
 
457
class GrepTests(ExternalBase):
 
458
 
 
459
    def test_simple_grep(self):
 
460
        tree = self.make_branch_and_tree('.', format='git')
 
461
        self.build_tree_contents([('a', 'text for a\n')])
 
462
        tree.add(['a'])
 
463
        output, error = self.run_bzr('grep text')
 
464
        self.assertEqual(output, 'a:text for a\n')
 
465
        self.assertEqual(error, '')
 
466
 
 
467
 
 
468
class ReconcileTests(ExternalBase):
 
469
 
 
470
    def test_simple_reconcile(self):
 
471
        tree = self.make_branch_and_tree('.', format='git')
 
472
        self.build_tree_contents([('a', 'text for a\n')])
 
473
        tree.add(['a'])
 
474
        output, error = self.run_bzr('reconcile')
 
475
        self.assertContainsRe(
 
476
            output,
 
477
            'Reconciling branch file://.*\n'
 
478
            'Reconciling repository file://.*\n'
 
479
            'Reconciliation complete.\n')
 
480
        self.assertEqual(error, '')
 
481
 
 
482
 
 
483
class StatusTests(ExternalBase):
 
484
 
 
485
    def test_empty_dir(self):
 
486
        tree = self.make_branch_and_tree('.', format='git')
 
487
        self.build_tree(['a/', 'a/foo'])
 
488
        self.build_tree_contents([('.gitignore', 'foo\n')])
 
489
        tree.add(['.gitignore'])
 
490
        tree.commit('add ignore')
 
491
        output, error = self.run_bzr('st')
 
492
        self.assertEqual(output, '')
 
493
        self.assertEqual(error, '')
 
494
 
 
495
 
 
496
class StatsTests(ExternalBase):
 
497
 
 
498
    def test_simple_stats(self):
 
499
        self.requireFeature(PluginLoadedFeature('stats'))
 
500
        tree = self.make_branch_and_tree('.', format='git')
 
501
        self.build_tree_contents([('a', 'text for a\n')])
 
502
        tree.add(['a'])
 
503
        tree.commit('a commit', committer='Somebody <somebody@example.com>')
 
504
        output, error = self.run_bzr('stats')
 
505
        self.assertEqual(output, '   1 Somebody <somebody@example.com>\n')
 
506
 
 
507
 
 
508
class GitObjectsTests(ExternalBase):
 
509
 
 
510
    def run_simple(self, format):
 
511
        tree = self.make_branch_and_tree('.', format=format)
 
512
        self.build_tree(['a/', 'a/foo'])
 
513
        tree.add(['a'])
 
514
        tree.commit('add a')
 
515
        output, error = self.run_bzr('git-objects')
 
516
        shas = list(output.splitlines())
 
517
        self.assertEqual([40, 40], [len(s) for s in shas])
 
518
        self.assertEqual(error, '')
 
519
 
 
520
        output, error = self.run_bzr('git-object %s' % shas[0])
 
521
        self.assertEqual('', error)
 
522
 
 
523
    def test_in_native(self):
 
524
        self.run_simple(format='git')
 
525
 
 
526
    def test_in_bzr(self):
 
527
        self.run_simple(format='2a')
 
528
 
 
529
 
 
530
class GitApplyTests(ExternalBase):
 
531
 
 
532
    def test_apply(self):
 
533
        b = self.make_branch_and_tree('.')
 
534
 
 
535
        with open('foo.patch', 'w') as f:
 
536
            f.write("""\
 
537
From bdefb25fab801e6af0a70e965f60cb48f2b759fa Mon Sep 17 00:00:00 2001
 
538
From: Dmitry Bogatov <KAction@debian.org>
 
539
Date: Fri, 8 Feb 2019 23:28:30 +0000
 
540
Subject: [PATCH] Add fixed for out-of-date-standards-version
 
541
 
 
542
---
 
543
 message           | 3 +++
 
544
 1 files changed, 14 insertions(+)
 
545
 create mode 100644 message
 
546
 
 
547
diff --git a/message b/message
 
548
new file mode 100644
 
549
index 0000000..05ec0b1
 
550
--- /dev/null
 
551
+++ b/message
 
552
@@ -0,0 +1,3 @@
 
553
+Update standards version, no changes needed.
 
554
+Certainty: certain
 
555
+Fixed-Lintian-Tags: out-of-date-standards-version
 
556
""")
 
557
        output, error = self.run_bzr('git-apply foo.patch')
 
558
        self.assertContainsRe(
 
559
            error,
 
560
            'Committing to: .*\n'
 
561
            'Committed revision 1.\n')