/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-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Black-box tests for bzr-git."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
from dulwich.repo import (
21
23
    Repo as GitRepo,
22
24
    )
33
35
from .. import (
34
36
    tests,
35
37
    )
36
 
from ...tests.script import TestCaseWithTransportAndScript
37
38
from ...tests.features import PluginLoadedFeature
38
39
 
39
40
 
47
48
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'<The commit message>')
48
49
        return repo, builder.finish()[r1]
49
50
 
50
 
    def test_add(self):
51
 
        r = GitRepo.init(self.test_dir)
52
 
        dir = ControlDir.open(self.test_dir)
53
 
        dir.create_branch()
54
 
        self.build_tree(['a', 'b'])
55
 
        output, error = self.run_bzr(['add', 'a'])
56
 
        self.assertEqual('adding a\n', output)
57
 
        self.assertEqual('', error)
58
 
        output, error = self.run_bzr(
59
 
            ['add', '--file-ids-from=../othertree', 'b'])
60
 
        self.assertEqual('adding b\n', output)
61
 
        self.assertEqual(
62
 
            'Ignoring --file-ids-from, since the tree does not support '
63
 
            'setting file ids.\n', error)
64
 
 
65
51
    def test_nick(self):
66
52
        r = GitRepo.init(self.test_dir)
67
53
        dir = ControlDir.open(self.test_dir)
164
150
        self.assertEqual(b"", output)
165
151
        self.assertTrue(error.endswith(b"Created new branch.\n"))
166
152
 
167
 
    def test_push_without_calculate_revnos(self):
168
 
        self.run_bzr(['init', '--git', 'bla'])
169
 
        self.run_bzr(['init', '--git', 'foo'])
170
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
171
 
        output, error = self.run_bzr(
172
 
            ['push', '-Ocalculate_revnos=no', '-d', 'foo', 'bla'])
173
 
        self.assertEqual("", output)
174
 
        self.assertContainsRe(
175
 
            error,
176
 
            'Pushed up to revision id git(.*).\n')
177
 
 
178
 
    def test_push_lossy_non_mainline(self):
179
 
        self.run_bzr(['init', '--git', 'bla'])
180
 
        self.run_bzr(['init', 'foo'])
181
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
182
 
        self.run_bzr(['branch', 'foo', 'foo1'])
183
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo1'])
184
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
185
 
        self.run_bzr(['merge', '-d', 'foo', 'foo1'])
186
 
        self.run_bzr(['commit', '--unchanged', '-m', 'merge', 'foo'])
187
 
        output, error = self.run_bzr(['push', '--lossy', '-r1.1.1', '-d', 'foo', 'bla'])
188
 
        self.assertEqual("", output)
189
 
        self.assertEqual(
190
 
            'Pushing from a Bazaar to a Git repository. For better '
191
 
            'performance, push into a Bazaar repository.\n'
192
 
            'All changes applied successfully.\n'
193
 
            'Pushed up to revision 2.\n', error)
194
 
 
195
 
    def test_push_lossy_non_mainline_incremental(self):
196
 
        self.run_bzr(['init', '--git', 'bla'])
197
 
        self.run_bzr(['init', 'foo'])
198
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
199
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
200
 
        output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
201
 
        self.assertEqual("", output)
202
 
        self.assertEqual(
203
 
            'Pushing from a Bazaar to a Git repository. For better '
204
 
            'performance, push into a Bazaar repository.\n'
205
 
            'All changes applied successfully.\n'
206
 
            'Pushed up to revision 2.\n', error)
207
 
        self.run_bzr(['commit', '--unchanged', '-m', 'bla', 'foo'])
208
 
        output, error = self.run_bzr(['push', '--lossy', '-d', 'foo', 'bla'])
209
 
        self.assertEqual("", output)
210
 
        self.assertEqual(
211
 
            'Pushing from a Bazaar to a Git repository. For better '
212
 
            'performance, push into a Bazaar repository.\n'
213
 
            'All changes applied successfully.\n'
214
 
            'Pushed up to revision 3.\n', error)
215
 
 
216
153
    def test_log(self):
217
154
        # Smoke test for "bzr log" in a git repository.
218
155
        self.simple_commit()
230
167
 
231
168
        # Check that bzr log does not fail and includes the revision.
232
169
        output, error = self.run_bzr(['log', '-v'])
233
 
        self.assertContainsRe(output, 'revno: 1')
234
 
 
235
 
    def test_log_without_revno(self):
236
 
        # Smoke test for "bzr log -v" in a git repository.
237
 
        self.simple_commit()
238
 
 
239
 
        # Check that bzr log does not fail and includes the revision.
240
 
        output, error = self.run_bzr(['log', '-Ocalculate_revnos=no'])
241
 
        self.assertNotContainsRe(output, 'revno: 1')
242
 
 
243
 
    def test_commit_without_revno(self):
244
 
        repo = GitRepo.init(self.test_dir)
245
 
        output, error = self.run_bzr(
246
 
            ['commit', '-Ocalculate_revnos=yes', '--unchanged', '-m', 'one'])
247
 
        self.assertContainsRe(error, 'Committed revision 1.')
248
 
        output, error = self.run_bzr(
249
 
            ['commit', '-Ocalculate_revnos=no', '--unchanged', '-m', 'two'])
250
 
        self.assertNotContainsRe(error, 'Committed revision 2.')
251
 
        self.assertContainsRe(error, 'Committed revid .*.')
252
 
 
253
 
    def test_log_file(self):
254
 
        # Smoke test for "bzr log" in a git repository.
255
 
        repo = GitRepo.init(self.test_dir)
256
 
        builder = tests.GitBranchBuilder()
257
 
        builder.set_file('a', b'text for a\n', False)
258
 
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'First')
259
 
        builder.set_file('a', b'text 3a for a\n', False)
260
 
        r2a = builder.commit(b'Joe Foo <joe@foo.com>', u'Second a', base=r1)
261
 
        builder.set_file('a', b'text 3b for a\n', False)
262
 
        r2b = builder.commit(b'Joe Foo <joe@foo.com>', u'Second b', base=r1)
263
 
        builder.set_file('a', b'text 4 for a\n', False)
264
 
        builder.commit(b'Joe Foo <joe@foo.com>', u'Third', merge=[r2a], base=r2b)
265
 
        builder.finish()
266
 
 
267
 
        # Check that bzr log does not fail and includes the revision.
268
 
        output, error = self.run_bzr(['log', '-n2', 'a'])
269
 
        self.assertEqual(error, '')
270
 
        self.assertIn('Second a', output)
271
 
        self.assertIn('Second b', output)
272
 
        self.assertIn('First', output)
273
 
        self.assertIn('Third', output)
274
170
 
275
171
    def test_tags(self):
276
172
        git_repo, commit_sha1 = self.simple_commit()
300
196
        tree.add(['a'])
301
197
        output, error = self.run_bzr(['diff', '--format=git'], retcode=1)
302
198
        self.assertEqual(error, '')
303
 
        # Some older versions of Dulwich (< 0.19.12) formatted diffs slightly
304
 
        # differently.
305
 
        from dulwich import __version__ as dulwich_version
306
 
        if dulwich_version < (0, 19, 12):
307
 
            self.assertEqual(output,
308
 
                             'diff --git /dev/null b/a\n'
309
 
                             'old mode 0\n'
310
 
                             'new mode 100644\n'
311
 
                             'index 0000000..c197bd8 100644\n'
312
 
                             '--- /dev/null\n'
313
 
                             '+++ b/a\n'
314
 
                             '@@ -0,0 +1 @@\n'
315
 
                             '+contents of a\n')
316
 
        else:
317
 
            self.assertEqual(output,
318
 
                             'diff --git a/a b/a\n'
319
 
                             'old file mode 0\n'
320
 
                             'new file mode 100644\n'
321
 
                             'index 0000000..c197bd8 100644\n'
322
 
                             '--- /dev/null\n'
323
 
                             '+++ b/a\n'
324
 
                             '@@ -0,0 +1 @@\n'
325
 
                             '+contents of a\n')
 
199
        self.assertEqual(output,
 
200
                         'diff --git /dev/null b/a\n'
 
201
                         'old mode 0\n'
 
202
                         'new mode 100644\n'
 
203
                         'index 0000000..c197bd8 100644\n'
 
204
                         '--- /dev/null\n'
 
205
                         '+++ b/a\n'
 
206
                         '@@ -0,0 +1 @@\n'
 
207
                         '+contents of a\n')
326
208
 
327
209
    def test_git_import_uncolocated(self):
328
210
        r = GitRepo.init("a", mkdir=True)
347
229
        self.run_bzr(["git-import", "--colocated", "a", "b"])
348
230
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
349
231
        self.assertEqual(set(["abranch", "bbranch"]),
350
 
                         set(ControlDir.open("b").branch_names()))
 
232
                         set(ControlDir.open("b").get_branches().keys()))
351
233
 
352
234
    def test_git_import_incremental(self):
353
235
        r = GitRepo.init("a", mkdir=True)
359
241
        self.run_bzr(["git-import", "--colocated", "a", "b"])
360
242
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
361
243
        b = ControlDir.open("b")
362
 
        self.assertEqual(["abranch"], b.branch_names())
 
244
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
363
245
 
364
246
    def test_git_import_tags(self):
365
247
        r = GitRepo.init("a", mkdir=True)
371
253
        self.run_bzr(["git-import", "--colocated", "a", "b"])
372
254
        self.assertEqual(set([".bzr"]), set(os.listdir("b")))
373
255
        b = ControlDir.open("b")
374
 
        self.assertEqual(["abranch"], b.branch_names())
 
256
        self.assertEqual(["abranch"], list(b.get_branches().keys()))
375
257
        self.assertEqual(["atag"],
376
258
                         list(b.open_branch("abranch").tags.get_tag_dict().keys()))
377
259
 
424
306
        self.assertEqual(out, '')
425
307
        self.assertTrue(err.endswith, '3 objects\n')
426
308
 
427
 
    def test_local_whoami(self):
428
 
        r = GitRepo.init("gitr", mkdir=True)
429
 
        self.build_tree_contents([('gitr/.git/config', """\
430
 
[user]
431
 
  email = some@example.com
432
 
  name = Test User
433
 
""")])
434
 
        out, err = self.run_bzr(["whoami", "-d", "gitr"])
435
 
        self.assertEqual(out, "Test User <some@example.com>\n")
436
 
        self.assertEqual(err, "")
437
 
 
438
 
        self.build_tree_contents([('gitr/.git/config', """\
439
 
[user]
440
 
  email = some@example.com
441
 
""")])
442
 
        out, err = self.run_bzr(["whoami", "-d", "gitr"])
443
 
        self.assertEqual(out, "some@example.com\n")
444
 
        self.assertEqual(err, "")
445
 
 
446
 
    def test_local_signing_key(self):
447
 
        r = GitRepo.init("gitr", mkdir=True)
448
 
        self.build_tree_contents([('gitr/.git/config', """\
449
 
[user]
450
 
  email = some@example.com
451
 
  name = Test User
452
 
  signingkey = D729A457
453
 
""")])
454
 
        out, err = self.run_bzr(["config", "-d", "gitr", "gpg_signing_key"])
455
 
        self.assertEqual(out, "D729A457\n")
456
 
        self.assertEqual(err, "")
457
 
 
458
309
 
459
310
class ShallowTests(ExternalBase):
460
311
 
541
392
            with basis_tree.lock_read():
542
393
                self.assertEqual([], list(tree.iter_changes(basis_tree)))
543
394
 
544
 
    def test_branch_with_nested_trees(self):
545
 
        orig = self.make_branch_and_tree('source', format='git')
546
 
        subtree = self.make_branch_and_tree('source/subtree', format='git')
547
 
        self.build_tree(['source/subtree/a'])
548
 
        self.build_tree_contents([('source/.gitmodules', """\
549
 
[submodule "subtree"]
550
 
    path = subtree
551
 
    url = %s
552
 
""" % subtree.user_url)])
553
 
        subtree.add(['a'])
554
 
        subtree.commit('add subtree contents')
555
 
        orig.add_reference(subtree)
556
 
        orig.add(['.gitmodules'])
557
 
        orig.commit('add subtree')
558
 
 
559
 
        self.run_bzr('branch source target')
560
 
 
561
 
        target = WorkingTree.open('target')
562
 
        target_subtree = WorkingTree.open('target/subtree')
563
 
        self.assertTreesEqual(orig, target)
564
 
        self.assertTreesEqual(subtree, target_subtree)
565
 
 
566
 
 
567
 
class SwitchScriptTests(TestCaseWithTransportAndScript):
568
 
 
569
 
    def test_switch_preserves(self):
570
 
        # See https://bugs.launchpad.net/brz/+bug/1820606
571
 
        self.run_script("""
572
 
$ brz init --git r
573
 
Created a standalone tree (format: git)
574
 
$ cd r
575
 
$ echo original > file.txt
576
 
$ brz add
577
 
adding file.txt
578
 
$ brz ci -q -m "Initial"
579
 
$ echo "entered on master branch" > file.txt
580
 
$ brz stat
581
 
modified:
582
 
  file.txt
583
 
$ brz switch -b other
584
 
2>Tree is up to date at revision 1.
585
 
2>Switched to branch other
586
 
$ cat file.txt
587
 
entered on master branch
588
 
""")
589
 
 
590
395
 
591
396
class GrepTests(ExternalBase):
592
397