Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Unit tests for git_rebase_update.py""" | |
| 7 | |
| 8 import os | |
| 9 import sys | |
| 10 | |
| 11 DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| 12 sys.path.insert(0, DEPOT_TOOLS_ROOT) | |
| 13 | |
| 14 from testing_support import coverage_utils | |
| 15 from testing_support import git_test_utils | |
| 16 | |
| 17 class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase): | |
| 18 REPO_SCHEMA = """ | |
| 19 A B C D E F G | |
| 20 B H I J K | |
| 21 J L | |
| 22 """ | |
| 23 | |
| 24 @classmethod | |
| 25 def getRepoContent(cls, commit): | |
| 26 # Every commit X gets a file X with the content X | |
| 27 return {commit: {'data': commit}} | |
| 28 | |
| 29 @classmethod | |
| 30 def setUpClass(cls): | |
| 31 super(GitRebaseUpdateTest, cls).setUpClass() | |
| 32 import git_rebase_update | |
| 33 cls.reup = git_rebase_update | |
| 34 | |
| 35 def setUp(self): | |
| 36 super(GitRebaseUpdateTest, self).setUp() | |
| 37 # Include branch_K, branch_L to make sure that ABCDEFG all get the | |
| 38 # same commit hashes as self.repo. Otherwise they get committed with the | |
| 39 # wrong timestamps, due to commit ordering. | |
| 40 # TODO(iannucci): Make commit timestamps deterministic in left to right, top | |
| 41 # to bottom order, not in lexi-topographical order. | |
| 42 origin_schema = git_test_utils.GitRepoSchema(""" | |
| 43 A B C D E F G M N O | |
| 44 B H I J K | |
| 45 J L | |
| 46 """, self.getRepoContent) | |
| 47 self.origin = origin_schema.reify() | |
| 48 self.origin.git('checkout', 'master') | |
| 49 self.origin.git('branch', '-d', *['branch_'+l for l in 'KLG']) | |
| 50 | |
| 51 self.repo.git('remote', 'add', 'origin', self.origin.repo_path) | |
| 52 self.repo.git('update-ref', 'refs/remotes/origin/master', 'master') | |
| 53 self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') | |
| 54 self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') | |
| 55 self.repo.git('branch', '--set-upstream-to', 'origin/master', 'branch_G') | |
| 56 | |
| 57 def tearDown(self): | |
| 58 self.origin.nuke() | |
| 59 super(GitRebaseUpdateTest, self).tearDown() | |
| 60 | |
| 61 def testRebaseUpdate(self): | |
| 62 graphlines = lambda: [ | |
| 63 l.strip() for l in self.repo.git( | |
| 64 'log', '--graph', '--format=%s', '--branches').stdout.splitlines() | |
| 65 ] | |
| 66 self.assertEqual( | |
| 67 graphlines(), [ | |
| 68 '* G', | |
| 69 '* F', | |
| 70 '* E', | |
| 71 '* D', | |
| 72 '* C', | |
| 73 '| * L', | |
| 74 '| | * K', | |
| 75 '| |/', | |
| 76 '| * J', | |
| 77 '| * I', | |
| 78 '| * H', | |
| 79 '|/', | |
| 80 '* B', | |
| 81 '* A', | |
| 82 ] | |
| 83 ) | |
| 84 self.assertEquals(self.repo['A'], self.origin['A']) | |
| 85 self.assertEquals(self.repo['G'], self.origin['G']) | |
| 86 | |
| 87 with open(os.path.join(self.repo.repo_path, 'bob'), 'w') as f: | |
| 88 f.write('testing auto-freeze/thaw') | |
| 89 | |
| 90 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 91 self.assertIn('Cannot rebase-update', output) | |
| 92 | |
| 93 self.repo.git('checkout', 'branch_K') | |
| 94 | |
| 95 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 96 | |
| 97 self.assertIn('Rebasing: branch_G', output) | |
| 98 self.assertIn('Rebasing: branch_K', output) | |
| 99 self.assertIn('Rebasing: branch_L', output) | |
| 100 self.assertIn('Deleted branch branch_G', output) | |
| 101 | |
| 102 self.assertEqual( | |
| 103 graphlines(), [ | |
| 104 '* L', | |
| 105 '* K', | |
| 106 '* J', | |
| 107 '* I', | |
| 108 '* H', | |
| 109 '* O', | |
| 110 '* N', | |
| 111 '* M', | |
| 112 '* G', | |
| 113 '* F', | |
| 114 '* E', | |
| 115 '* D', | |
| 116 '* C', | |
| 117 '* B', | |
| 118 '* A', | |
| 119 ] | |
| 120 ) | |
| 121 | |
| 122 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 123 self.assertIn('branch_K up-to-date', output) | |
| 124 self.assertIn('branch_L up-to-date', output) | |
| 125 | |
| 126 with open(os.path.join(self.repo.repo_path, 'bob'), 'r') as f: | |
| 127 self.assertEquals('testing auto-freeze/thaw', f.read()) | |
| 128 | |
| 129 self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n') | |
| 130 | |
| 131 def testRebaseConflicts(self): | |
| 132 # Pretend that branch_L landed | |
| 133 self.origin.git('checkout', 'master') | |
| 134 with open(os.path.join(self.origin.repo_path, 'L'), 'w') as f: | |
| 135 f.write('L') | |
| 136 self.origin.git('add', 'L') | |
| 137 self.origin.git('commit', '-m', 'L') | |
| 138 | |
| 139 # Add a commit to branch_K so that things fail | |
| 140 self.repo.git('checkout', 'branch_K') | |
| 141 with open(os.path.join(self.repo.repo_path, 'M'), 'w') as f: | |
| 142 f.write('NOPE') | |
| 143 self.repo.git('add', 'M') | |
| 144 self.repo.git('commit', '-m', 'K NOPE') | |
| 145 | |
| 146 # Add a commits to branch_L which will work when squashed | |
| 147 self.repo.git('checkout', 'branch_L') | |
| 148 self.repo.git('reset', 'branch_L~') | |
| 149 with open(os.path.join(self.repo.repo_path, 'L'), 'w') as f: | |
| 150 f.write('NOPE') | |
| 151 self.repo.git('add', 'L') | |
| 152 self.repo.git('commit', '-m', 'L NOPE') | |
| 153 with open(os.path.join(self.repo.repo_path, 'L'), 'w') as f: | |
| 154 f.write('L') | |
| 155 self.repo.git('add', 'L') | |
| 156 self.repo.git('commit', '-m', 'L YUP') | |
| 157 | |
| 158 # start on a branch which will be deleted | |
| 159 self.repo.git('checkout', 'branch_G') | |
| 160 | |
| 161 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 162 self.assertIn('Failure :(', output) | |
| 163 | |
| 164 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 165 self.assertIn('Rebase in progress', output) | |
| 166 | |
| 167 self.repo.git('checkout', '--theirs', 'M') | |
| 168 self.repo.git('rebase', '--skip') | |
| 169 | |
| 170 output, _ = self.repo.capture_stdio(self.reup.main) | |
| 171 self.assertIn('Failed! Attempting to squash', output) | |
| 172 self.assertIn('Deleted branch branch_G', output) | |
| 173 self.assertIn('Deleted branch branch_L', output) | |
| 174 self.assertIn('\'branch_G\' was merged', output) | |
| 175 self.assertIn('checking out \'origin/master\'', output) | |
| 176 | |
| 177 | |
| 178 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.
| |
| 179 self.origin.git('tag', 'lkgr', self.origin['M']) | |
| 180 self.repo.git('tag', 'lkgr', self.repo['D']) | |
| 181 self.repo.git('config', 'branch.branch_G.remote', '.') | |
| 182 self.repo.git('config', 'branch.branch_G.merge', 'refs/tags/lkgr') | |
| 183 | |
| 184 graphlines = lambda: [ | |
| 185 l.strip() for l in self.repo.git( | |
| 186 'log', '--graph', '--format=%s', '--branches', 'origin/master' | |
| 187 ).stdout.splitlines() | |
| 188 ] | |
| 189 self.assertEqual( | |
| 190 graphlines(), [ | |
| 191 '* G', | |
| 192 '* F', | |
| 193 '* E', | |
| 194 '* D', | |
| 195 '* C', | |
| 196 '| * L', | |
| 197 '| | * K', | |
| 198 '| |/', | |
| 199 '| * J', | |
| 200 '| * I', | |
| 201 '| * H', | |
| 202 '|/', | |
| 203 '* B', | |
| 204 '* A', | |
| 205 ] | |
| 206 ) | |
| 207 self.assertEquals(self.repo['A'], self.origin['A']) | |
| 208 self.assertEquals(self.repo['G'], self.origin['G']) | |
| 209 | |
| 210 output, _ = self.repo.capture_stdio(self.reup.main, []) | |
| 211 self.assertIn('Rebasing: branch_G', output) | |
| 212 self.assertIn('Rebasing: branch_K', output) | |
| 213 self.assertIn('Rebasing: branch_L', output) | |
| 214 | |
| 215 self.assertEqual( | |
| 216 graphlines(), [ | |
| 217 '* L', | |
| 218 '* K', | |
| 219 '* J', | |
| 220 '* I', | |
| 221 '* H', | |
| 222 '| * O', | |
| 223 '| * N', | |
| 224 '|/', | |
| 225 '* M', | |
| 226 '* G', | |
| 227 '* F', | |
| 228 '* E', | |
| 229 '* D', | |
| 230 '* C', | |
| 231 '* B', | |
| 232 '* A', | |
| 233 ] | |
| 234 ) | |
| 235 | |
| 236 | |
| 237 if __name__ == '__main__': | |
| 238 sys.exit(coverage_utils.covered_main( | |
| 239 os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py') | |
| 240 )) | |
| OLD | NEW |