Chromium Code Reviews| Index: tests/git_rebase_update_test.py |
| diff --git a/tests/git_rebase_update_test.py b/tests/git_rebase_update_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..5ded20a5fa5f499253b190ceffecc4b2f1cff686 |
| --- /dev/null |
| +++ b/tests/git_rebase_update_test.py |
| @@ -0,0 +1,240 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Unit tests for git_rebase_update.py""" |
| + |
| +import os |
| +import sys |
| + |
| +DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| +sys.path.insert(0, DEPOT_TOOLS_ROOT) |
| + |
| +from testing_support import coverage_utils |
| +from testing_support import git_test_utils |
| + |
| +class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase): |
| + REPO_SCHEMA = """ |
| + A B C D E F G |
| + B H I J K |
| + J L |
| + """ |
| + |
| + @classmethod |
| + def getRepoContent(cls, commit): |
| + # Every commit X gets a file X with the content X |
| + return {commit: {'data': commit}} |
| + |
| + @classmethod |
| + def setUpClass(cls): |
| + super(GitRebaseUpdateTest, cls).setUpClass() |
| + import git_rebase_update |
| + cls.reup = git_rebase_update |
| + |
| + def setUp(self): |
| + super(GitRebaseUpdateTest, self).setUp() |
| + # Include branch_K, branch_L to make sure that ABCDEFG all get the |
| + # same commit hashes as self.repo. Otherwise they get committed with the |
| + # wrong timestamps, due to commit ordering. |
| + # TODO(iannucci): Make commit timestamps deterministic in left to right, top |
| + # to bottom order, not in lexi-topographical order. |
| + origin_schema = git_test_utils.GitRepoSchema(""" |
| + A B C D E F G M N O |
| + B H I J K |
| + J L |
| + """, self.getRepoContent) |
| + self.origin = origin_schema.reify() |
| + self.origin.git('checkout', 'master') |
| + self.origin.git('branch', '-d', *['branch_'+l for l in 'KLG']) |
| + |
| + self.repo.git('remote', 'add', 'origin', self.origin.repo_path) |
| + self.repo.git('update-ref', 'refs/remotes/origin/master', 'master') |
| + self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') |
| + self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') |
| + self.repo.git('branch', '--set-upstream-to', 'origin/master', 'branch_G') |
| + |
| + def tearDown(self): |
| + self.origin.nuke() |
| + super(GitRebaseUpdateTest, self).tearDown() |
| + |
| + def testRebaseUpdate(self): |
| + graphlines = lambda: [ |
| + l.strip() for l in self.repo.git( |
| + 'log', '--graph', '--format=%s', '--branches').stdout.splitlines() |
| + ] |
| + self.assertEqual( |
| + graphlines(), [ |
| + '* G', |
| + '* F', |
| + '* E', |
| + '* D', |
| + '* C', |
| + '| * L', |
| + '| | * K', |
| + '| |/', |
| + '| * J', |
| + '| * I', |
| + '| * H', |
| + '|/', |
| + '* B', |
| + '* A', |
| + ] |
| + ) |
| + self.assertEquals(self.repo['A'], self.origin['A']) |
| + self.assertEquals(self.repo['G'], self.origin['G']) |
| + |
| + with open(os.path.join(self.repo.repo_path, 'bob'), 'w') as f: |
| + f.write('testing auto-freeze/thaw') |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + self.assertIn('Cannot rebase-update', output) |
| + |
| + self.repo.git('checkout', 'branch_K') |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + |
| + self.assertIn('Rebasing: branch_G', output) |
| + self.assertIn('Rebasing: branch_K', output) |
| + self.assertIn('Rebasing: branch_L', output) |
| + self.assertIn('Deleted branch branch_G', output) |
| + |
| + self.assertEqual( |
| + graphlines(), [ |
| + '* L', |
| + '* K', |
| + '* J', |
| + '* I', |
| + '* H', |
| + '* O', |
| + '* N', |
| + '* M', |
| + '* G', |
| + '* F', |
| + '* E', |
| + '* D', |
| + '* C', |
| + '* B', |
| + '* A', |
| + ] |
| + ) |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + self.assertIn('branch_K up-to-date', output) |
| + self.assertIn('branch_L up-to-date', output) |
| + |
| + with open(os.path.join(self.repo.repo_path, 'bob'), 'r') as f: |
| + self.assertEquals('testing auto-freeze/thaw', f.read()) |
| + |
| + self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n') |
| + |
| + def testRebaseConflicts(self): |
| + # Pretend that branch_L landed |
| + self.origin.git('checkout', 'master') |
| + with open(os.path.join(self.origin.repo_path, 'L'), 'w') as f: |
| + f.write('L') |
| + self.origin.git('add', 'L') |
| + self.origin.git('commit', '-m', 'L') |
| + |
| + # Add a commit to branch_K so that things fail |
| + self.repo.git('checkout', 'branch_K') |
| + with open(os.path.join(self.repo.repo_path, 'M'), 'w') as f: |
| + f.write('NOPE') |
| + self.repo.git('add', 'M') |
| + self.repo.git('commit', '-m', 'K NOPE') |
| + |
| + # Add a commits to branch_L which will work when squashed |
| + self.repo.git('checkout', 'branch_L') |
| + self.repo.git('reset', 'branch_L~') |
| + with open(os.path.join(self.repo.repo_path, 'L'), 'w') as f: |
| + f.write('NOPE') |
| + self.repo.git('add', 'L') |
| + self.repo.git('commit', '-m', 'L NOPE') |
| + with open(os.path.join(self.repo.repo_path, 'L'), 'w') as f: |
| + f.write('L') |
| + self.repo.git('add', 'L') |
| + self.repo.git('commit', '-m', 'L YUP') |
| + |
| + # start on a branch which will be deleted |
| + self.repo.git('checkout', 'branch_G') |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + self.assertIn('Failure :(', output) |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + self.assertIn('Rebase in progress', output) |
| + |
| + self.repo.git('checkout', '--theirs', 'M') |
| + self.repo.git('rebase', '--skip') |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main) |
| + self.assertIn('Failed! Attempting to squash', output) |
| + self.assertIn('Deleted branch branch_G', output) |
| + self.assertIn('Deleted branch branch_L', output) |
| + self.assertIn('\'branch_G\' was merged', output) |
| + self.assertIn('checking out \'origin/master\'', output) |
| + |
| + |
| + def testTrackTag(self): |
|
agable
2014/03/21 01:14:21
use git-new-branch --lkgr in this test?
iannucci
2014/03/22 04:17:35
Done.
|
| + self.origin.git('tag', 'lkgr', self.origin['M']) |
| + self.repo.git('tag', 'lkgr', self.repo['D']) |
| + self.repo.git('config', 'branch.branch_G.remote', '.') |
| + self.repo.git('config', 'branch.branch_G.merge', 'refs/tags/lkgr') |
| + |
| + graphlines = lambda: [ |
| + l.strip() for l in self.repo.git( |
| + 'log', '--graph', '--format=%s', '--branches', 'origin/master' |
| + ).stdout.splitlines() |
| + ] |
| + self.assertEqual( |
| + graphlines(), [ |
| + '* G', |
| + '* F', |
| + '* E', |
| + '* D', |
| + '* C', |
| + '| * L', |
| + '| | * K', |
| + '| |/', |
| + '| * J', |
| + '| * I', |
| + '| * H', |
| + '|/', |
| + '* B', |
| + '* A', |
| + ] |
| + ) |
| + self.assertEquals(self.repo['A'], self.origin['A']) |
| + self.assertEquals(self.repo['G'], self.origin['G']) |
| + |
| + output, _ = self.repo.capture_stdio(self.reup.main, []) |
| + self.assertIn('Rebasing: branch_G', output) |
| + self.assertIn('Rebasing: branch_K', output) |
| + self.assertIn('Rebasing: branch_L', output) |
| + |
| + self.assertEqual( |
| + graphlines(), [ |
| + '* L', |
| + '* K', |
| + '* J', |
| + '* I', |
| + '* H', |
| + '| * O', |
| + '| * N', |
| + '|/', |
| + '* M', |
| + '* G', |
| + '* F', |
| + '* E', |
| + '* D', |
| + '* C', |
| + '* B', |
| + '* A', |
| + ] |
| + ) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(coverage_utils.covered_main( |
| + os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py') |
| + )) |