Mercurial > hgsubversion
comparison tests/test_push_command.py @ 1106:5cb6c95e0283 stable
Merge default and stable so I can do stable releases again.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 11 Feb 2014 12:48:49 -0500 |
parents | 2d7398fffd0d |
children | cccc7a50f66d |
comparison
equal
deleted
inserted
replaced
1020:b5b1fce26f1f | 1106:5cb6c95e0283 |
---|---|
15 from mercurial import hg | 15 from mercurial import hg |
16 from mercurial import node | 16 from mercurial import node |
17 from mercurial import revlog | 17 from mercurial import revlog |
18 from mercurial import util as hgutil | 18 from mercurial import util as hgutil |
19 | 19 |
20 from hgsubversion import util | |
21 | |
20 import time | 22 import time |
21 | 23 |
22 | 24 |
23 class PushTests(test_util.TestBase): | 25 class PushTests(test_util.TestBase): |
26 obsolete_mode_tests = True | |
27 | |
24 def setUp(self): | 28 def setUp(self): |
25 test_util.TestBase.setUp(self) | 29 test_util.TestBase.setUp(self) |
26 self.repo_path = self.load_and_fetch('simple_branch.svndump')[1] | 30 self.repo_path = self.load_and_fetch('simple_branch.svndump')[1] |
27 | 31 |
28 def test_cant_push_empty_ctx(self): | 32 def test_cant_push_empty_ctx(self): |
45 {'branch': 'default', }) | 49 {'branch': 'default', }) |
46 new_hash = repo.commitctx(ctx) | 50 new_hash = repo.commitctx(ctx) |
47 hg.update(repo, repo['tip'].node()) | 51 hg.update(repo, repo['tip'].node()) |
48 old_tip = repo['tip'].node() | 52 old_tip = repo['tip'].node() |
49 self.pushrevisions() | 53 self.pushrevisions() |
54 tip = self.repo['tip'] | |
55 self.assertEqual(tip.node(), old_tip) | |
56 | |
57 def test_push_add_of_added_upstream_gives_sane_error(self): | |
58 repo = self.repo | |
59 def file_callback(repo, memctx, path): | |
60 if path == 'adding_file': | |
61 return context.memfilectx(path=path, | |
62 data='foo', | |
63 islink=False, | |
64 isexec=False, | |
65 copied=False) | |
66 raise IOError() | |
67 p1 = repo['default'].node() | |
68 ctx = context.memctx(repo, | |
69 (p1, node.nullid), | |
70 'automated test', | |
71 ['adding_file'], | |
72 file_callback, | |
73 'an_author', | |
74 '2008-10-07 20:59:48 -0500', | |
75 {'branch': 'default', }) | |
76 new_hash = repo.commitctx(ctx) | |
77 hg.update(repo, repo['tip'].node()) | |
78 old_tip = repo['tip'].node() | |
79 self.pushrevisions() | |
80 tip = self.repo['tip'] | |
81 self.assertNotEqual(tip.node(), old_tip) | |
82 | |
83 # This node adds the same file as the first one we added, and | |
84 # will be refused by the server for adding a file that already | |
85 # exists. We should respond with an error suggesting the user | |
86 # rebase. | |
87 ctx = context.memctx(repo, | |
88 (p1, node.nullid), | |
89 'automated test', | |
90 ['adding_file'], | |
91 file_callback, | |
92 'an_author', | |
93 '2008-10-07 20:59:48 -0500', | |
94 {'branch': 'default', }) | |
95 new_hash = repo.commitctx(ctx) | |
96 hg.update(repo, repo['tip'].node()) | |
97 old_tip = repo['tip'].node() | |
98 try: | |
99 self.pushrevisions() | |
100 except hgutil.Abort, e: | |
101 assert "pull again and rebase" in str(e) | |
50 tip = self.repo['tip'] | 102 tip = self.repo['tip'] |
51 self.assertEqual(tip.node(), old_tip) | 103 self.assertEqual(tip.node(), old_tip) |
52 | 104 |
53 def test_cant_push_with_changes(self): | 105 def test_cant_push_with_changes(self): |
54 repo = self.repo | 106 repo = self.repo |
520 ] | 572 ] |
521 self.commitchanges(changes, parent=self.repo['tip'].rev()) | 573 self.commitchanges(changes, parent=self.repo['tip'].rev()) |
522 self.pushrevisions() | 574 self.pushrevisions() |
523 self.assertEqual(['alpha'], list(self.repo['tip'].manifest())) | 575 self.assertEqual(['alpha'], list(self.repo['tip'].manifest())) |
524 | 576 |
525 def suite(): | 577 def test_push_without_pushing_children(self): |
526 test_classes = [PushTests, ] | 578 ''' |
527 all_tests = [] | 579 Verify that a push of a nontip node, keeps the tip child |
528 # This is the quickest hack I could come up with to load all the tests from | 580 on top of the pushed commit. |
529 # both classes. Would love a patch that simplifies this without adding | 581 ''' |
530 # dependencies. | 582 |
531 for tc in test_classes: | 583 oldlen = test_util.repolen(self.repo) |
532 for attr in dir(tc): | 584 oldtiphash = self.repo['default'].node() |
533 if attr.startswith('test_'): | 585 |
534 all_tests.append(tc(attr)) | 586 changes = [('gamma', 'gamma', 'sometext')] |
535 return unittest.TestSuite(all_tests) | 587 newhash1 = self.commitchanges(changes) |
588 | |
589 changes = [('delta', 'delta', 'sometext')] | |
590 newhash2 = self.commitchanges(changes) | |
591 | |
592 # push only the first commit | |
593 repo = self.repo | |
594 hg.update(repo, newhash1) | |
595 commands.push(repo.ui, repo) | |
596 self.assertEqual(test_util.repolen(self.repo), oldlen + 2) | |
597 | |
598 # verify that the first commit is pushed, and the second is not | |
599 commit2 = self.repo['tip'] | |
600 self.assertEqual(commit2.files(), ['delta', ]) | |
601 self.assertEqual(util.getsvnrev(commit2), None) | |
602 commit1 = commit2.parents()[0] | |
603 self.assertEqual(commit1.files(), ['gamma', ]) | |
604 prefix = 'svn:' + self.repo.svnmeta().uuid | |
605 self.assertEqual(util.getsvnrev(commit1), | |
606 prefix + '/branches/the_branch@5') | |
607 | |
608 def test_push_two_that_modify_same_file(self): | |
609 ''' | |
610 Push performs a rebase if two commits touch the same file. | |
611 This test verifies that code path works. | |
612 ''' | |
613 | |
614 oldlen = test_util.repolen(self.repo) | |
615 oldtiphash = self.repo['default'].node() | |
616 | |
617 changes = [('gamma', 'gamma', 'sometext')] | |
618 newhash = self.commitchanges(changes) | |
619 changes = [('gamma', 'gamma', 'sometext\n moretext'), | |
620 ('delta', 'delta', 'sometext\n moretext'), | |
621 ] | |
622 newhash = self.commitchanges(changes) | |
623 | |
624 repo = self.repo | |
625 hg.update(repo, newhash) | |
626 commands.push(repo.ui, repo) | |
627 self.assertEqual(test_util.repolen(self.repo), oldlen + 2) | |
628 | |
629 # verify that both commits are pushed | |
630 commit1 = self.repo['tip'] | |
631 self.assertEqual(commit1.files(), ['delta', 'gamma']) | |
632 | |
633 prefix = 'svn:' + self.repo.svnmeta().uuid | |
634 self.assertEqual(util.getsvnrev(commit1), | |
635 prefix + '/branches/the_branch@6') | |
636 commit2 = commit1.parents()[0] | |
637 self.assertEqual(commit2.files(), ['gamma']) | |
638 self.assertEqual(util.getsvnrev(commit2), | |
639 prefix + '/branches/the_branch@5') | |
640 | |
641 def test_push_in_subdir(self, commit=True): | |
642 repo = self.repo | |
643 old_tip = repo['tip'].node() | |
644 def file_callback(repo, memctx, path): | |
645 if path == 'adding_file' or path == 'newdir/new_file': | |
646 testData = 'fooFirstFile' | |
647 if path == 'newdir/new_file': | |
648 testData = 'fooNewFile' | |
649 return context.memfilectx(path=path, | |
650 data=testData, | |
651 islink=False, | |
652 isexec=False, | |
653 copied=False) | |
654 raise IOError(errno.EINVAL, 'Invalid operation: ' + path) | |
655 ctx = context.memctx(repo, | |
656 (repo['default'].node(), node.nullid), | |
657 'automated test', | |
658 ['adding_file'], | |
659 file_callback, | |
660 'an_author', | |
661 '2012-12-13 20:59:48 -0500', | |
662 {'branch': 'default', }) | |
663 new_hash = repo.commitctx(ctx) | |
664 p = os.path.join(repo.root, "newdir") | |
665 os.mkdir(p) | |
666 ctx = context.memctx(repo, | |
667 (repo['default'].node(), node.nullid), | |
668 'automated test', | |
669 ['newdir/new_file'], | |
670 file_callback, | |
671 'an_author', | |
672 '2012-12-13 20:59:48 -0500', | |
673 {'branch': 'default', }) | |
674 os.chdir(p) | |
675 new_hash = repo.commitctx(ctx) | |
676 hg.update(repo, repo['tip'].node()) | |
677 self.pushrevisions() | |
678 tip = self.repo['tip'] | |
679 self.assertNotEqual(tip.node(), old_tip) | |
680 self.assertEqual(p, os.getcwd()) | |
681 self.assertEqual(tip['adding_file'].data(), 'fooFirstFile') | |
682 self.assertEqual(tip['newdir/new_file'].data(), 'fooNewFile') | |
683 self.assertEqual(tip.branch(), 'default') |