Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit tests for git_rebase_update.py""" | 6 """Unit tests for git_rebase_update.py""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') | 61 self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') |
| 62 self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') | 62 self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') |
| 63 self.repo.git('branch', '--set-upstream-to', 'origin/master', 'branch_G') | 63 self.repo.git('branch', '--set-upstream-to', 'origin/master', 'branch_G') |
| 64 | 64 |
| 65 self.repo.to_schema_refs += ['origin/master'] | 65 self.repo.to_schema_refs += ['origin/master'] |
| 66 | 66 |
| 67 def tearDown(self): | 67 def tearDown(self): |
| 68 self.origin.nuke() | 68 self.origin.nuke() |
| 69 super(GitRebaseUpdateTest, self).tearDown() | 69 super(GitRebaseUpdateTest, self).tearDown() |
| 70 | 70 |
| 71 def testRebaseUpdate(self): | 71 def testRebaseUpdate(self): |
|
iannucci
2015/12/02 18:08:51
I've created a monster (unit test)!
I think I'm g
sdefresne
2015/12/02 18:12:53
:-) BTW, those tests are not independent (i.e. run
| |
| 72 self.repo.git('checkout', 'branch_K') | 72 self.repo.git('checkout', 'branch_K') |
| 73 | 73 |
| 74 self.repo.run(self.nb.main, ['foobar']) | 74 self.repo.run(self.nb.main, ['foobar']) |
| 75 self.assertEqual(self.repo.git('rev-parse', 'HEAD').stdout, | 75 self.assertEqual(self.repo.git('rev-parse', 'HEAD').stdout, |
| 76 self.repo.git('rev-parse', 'origin/master').stdout) | 76 self.repo.git('rev-parse', 'origin/master').stdout) |
| 77 | 77 |
| 78 with self.repo.open('foobar', 'w') as f: | 78 with self.repo.open('foobar', 'w') as f: |
| 79 f.write('this is the foobar file') | 79 f.write('this is the foobar file') |
| 80 self.repo.git('add', 'foobar') | 80 self.repo.git('add', 'foobar') |
| 81 self.repo.git_commit('foobar1') | 81 self.repo.git_commit('foobar1') |
| 82 | 82 |
| 83 with self.repo.open('foobar', 'w') as f: | 83 with self.repo.open('foobar', 'w') as f: |
| 84 f.write('totes the Foobar file') | 84 f.write('totes the Foobar file') |
| 85 self.repo.git_commit('foobar2') | 85 self.repo.git_commit('foobar2') |
| 86 | 86 |
| 87 self.repo.run(self.nb.main, ['--upstream-current', 'int1_foobar']) | |
| 88 self.repo.run(self.nb.main, ['--upstream-current', 'int2_foobar']) | |
| 89 self.repo.run(self.nb.main, ['--upstream-current', 'sub_foobar']) | |
| 90 with self.repo.open('foobar', 'w') as f: | |
| 91 f.write('some more foobaring') | |
| 92 self.repo.git('add', 'foobar') | |
| 93 self.repo.git_commit('foobar3') | |
| 94 | |
| 87 self.repo.git('checkout', 'branch_K') | 95 self.repo.git('checkout', 'branch_K') |
| 88 self.repo.run(self.nb.main, ['--upstream-current', 'sub_K']) | 96 self.repo.run(self.nb.main, ['--upstream-current', 'sub_K']) |
| 89 with self.repo.open('K', 'w') as f: | 97 with self.repo.open('K', 'w') as f: |
| 90 f.write('This depends on K') | 98 f.write('This depends on K') |
| 91 self.repo.git_commit('sub_K') | 99 self.repo.git_commit('sub_K') |
| 92 | 100 |
| 93 self.repo.run(self.nb.main, ['old_branch']) | 101 self.repo.run(self.nb.main, ['old_branch']) |
| 94 self.repo.git('reset', '--hard', self.repo['A']) | 102 self.repo.git('reset', '--hard', self.repo['A']) |
| 95 with self.repo.open('old_file', 'w') as f: | 103 with self.repo.open('old_file', 'w') as f: |
| 96 f.write('old_files we want to keep around') | 104 f.write('old_files we want to keep around') |
| 97 self.repo.git('add', 'old_file') | 105 self.repo.git('add', 'old_file') |
| 98 self.repo.git_commit('old_file') | 106 self.repo.git_commit('old_file') |
| 99 self.repo.git('config', 'branch.old_branch.dormant', 'true') | 107 self.repo.git('config', 'branch.old_branch.dormant', 'true') |
| 100 | 108 |
| 101 self.repo.git('checkout', 'origin/master') | 109 self.repo.git('checkout', 'origin/master') |
| 102 | 110 |
| 103 self.assertSchema(""" | 111 self.assertSchema(""" |
| 104 A B H I J K sub_K | 112 A B H I J K sub_K |
| 105 J L | 113 J L |
| 106 B C D E foobar1 foobar2 | 114 B C D E foobar1 foobar2 foobar3 |
| 107 E F G | 115 E F G |
| 108 A old_file | 116 A old_file |
| 109 """) | 117 """) |
| 110 self.assertEquals(self.repo['A'], self.origin['A']) | 118 self.assertEquals(self.repo['A'], self.origin['A']) |
| 111 self.assertEquals(self.repo['E'], self.origin['E']) | 119 self.assertEquals(self.repo['E'], self.origin['E']) |
| 112 | 120 |
| 113 with self.repo.open('bob', 'wb') as f: | 121 with self.repo.open('bob', 'wb') as f: |
| 114 f.write('testing auto-freeze/thaw') | 122 f.write('testing auto-freeze/thaw') |
| 115 | 123 |
| 116 output, _ = self.repo.capture_stdio(self.reup.main) | 124 output, _ = self.repo.capture_stdio(self.reup.main) |
| 117 self.assertIn('Cannot rebase-update', output) | 125 self.assertIn('Cannot rebase-update', output) |
| 118 | 126 |
| 119 self.repo.run(self.nb.main, ['empty_branch']) | 127 self.repo.run(self.nb.main, ['empty_branch']) |
| 120 self.repo.run(self.nb.main, ['--upstream-current', 'empty_branch2']) | 128 self.repo.run(self.nb.main, ['--upstream-current', 'empty_branch2']) |
| 121 | 129 |
| 122 self.repo.git('checkout', 'branch_K') | 130 self.repo.git('checkout', 'branch_K') |
| 123 | 131 |
| 124 output, _ = self.repo.capture_stdio(self.reup.main) | 132 output, _ = self.repo.capture_stdio(self.reup.main) |
| 125 | 133 |
| 126 self.assertIn('Rebasing: branch_G', output) | 134 self.assertIn('Rebasing: branch_G', output) |
| 127 self.assertIn('Rebasing: branch_K', output) | 135 self.assertIn('Rebasing: branch_K', output) |
| 128 self.assertIn('Rebasing: branch_L', output) | 136 self.assertIn('Rebasing: branch_L', output) |
| 129 self.assertIn('Rebasing: foobar', output) | 137 self.assertIn('Rebasing: foobar', output) |
| 130 self.assertIn('Rebasing: sub_K', output) | 138 self.assertIn('Rebasing: sub_K', output) |
| 131 self.assertIn('Deleted branch branch_G', output) | 139 self.assertIn('Deleted branch branch_G', output) |
| 132 self.assertIn('Deleted branch empty_branch', output) | 140 self.assertIn('Deleted branch empty_branch', output) |
| 133 self.assertIn('Deleted branch empty_branch2', output) | 141 self.assertIn('Deleted branch empty_branch2', output) |
| 142 self.assertIn('Deleted branch int1_foobar', output) | |
| 143 self.assertIn('Deleted branch int2_foobar', output) | |
| 134 self.assertIn('Reparented branch_K to track origin/master', output) | 144 self.assertIn('Reparented branch_K to track origin/master', output) |
| 145 self.assertIn('Reparented sub_foobar to track foobar', output) | |
| 135 | 146 |
| 136 self.assertSchema(""" | 147 self.assertSchema(""" |
| 137 A B C D E F G M N O H I J K sub_K | 148 A B C D E F G M N O H I J K sub_K |
| 138 K L | 149 K L |
| 139 O foobar1 foobar2 | 150 O foobar1 foobar2 foobar3 |
| 140 A old_file | 151 A old_file |
| 141 """) | 152 """) |
| 142 | 153 |
| 143 output, _ = self.repo.capture_stdio(self.reup.main) | 154 output, _ = self.repo.capture_stdio(self.reup.main) |
| 144 self.assertIn('branch_K up-to-date', output) | 155 self.assertIn('branch_K up-to-date', output) |
| 145 self.assertIn('branch_L up-to-date', output) | 156 self.assertIn('branch_L up-to-date', output) |
| 146 self.assertIn('foobar up-to-date', output) | 157 self.assertIn('foobar up-to-date', output) |
| 147 self.assertIn('sub_K up-to-date', output) | 158 self.assertIn('sub_K up-to-date', output) |
| 148 | 159 |
| 149 with self.repo.open('bob') as f: | 160 with self.repo.open('bob') as f: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 160 self.repo.git('checkout', 'branch_K') | 171 self.repo.git('checkout', 'branch_K') |
| 161 _, err = self.repo.capture_stdio(self.rp.main, ['origin/master']) | 172 _, err = self.repo.capture_stdio(self.rp.main, ['origin/master']) |
| 162 self.assertIn('Cannot reparent a branch to its existing parent', err) | 173 self.assertIn('Cannot reparent a branch to its existing parent', err) |
| 163 output, _ = self.repo.capture_stdio(self.rp.main, ['foobar']) | 174 output, _ = self.repo.capture_stdio(self.rp.main, ['foobar']) |
| 164 self.assertIn('Rebasing: branch_K', output) | 175 self.assertIn('Rebasing: branch_K', output) |
| 165 self.assertIn('Rebasing: sub_K', output) | 176 self.assertIn('Rebasing: sub_K', output) |
| 166 self.assertIn('Rebasing: branch_L', output) | 177 self.assertIn('Rebasing: branch_L', output) |
| 167 | 178 |
| 168 self.assertSchema(""" | 179 self.assertSchema(""" |
| 169 A B C D E F G M N O foobar1 foobar2 H I J K L | 180 A B C D E F G M N O foobar1 foobar2 H I J K L |
| 181 foobar2 foobar3 | |
| 170 K sub_K | 182 K sub_K |
| 171 A old_file | 183 A old_file |
| 172 """) | 184 """) |
| 173 | 185 |
| 174 self.repo.git('checkout', 'sub_K') | 186 self.repo.git('checkout', 'sub_K') |
| 175 output, _ = self.repo.capture_stdio(self.rp.main, ['foobar']) | 187 output, _ = self.repo.capture_stdio(self.rp.main, ['foobar']) |
| 176 self.assertIn('Squashing failed', output) | 188 self.assertIn('Squashing failed', output) |
| 177 | 189 |
| 178 self.assertTrue(self.repo.run(self.gc.in_rebase)) | 190 self.assertTrue(self.repo.run(self.gc.in_rebase)) |
| 179 | 191 |
| 180 self.repo.git('rebase', '--abort') | 192 self.repo.git('rebase', '--abort') |
| 181 self.assertIsNone(self.repo.run(self.gc.thaw)) | 193 self.assertIsNone(self.repo.run(self.gc.thaw)) |
| 182 | 194 |
| 183 self.assertSchema(""" | 195 self.assertSchema(""" |
| 184 A B C D E F G M N O foobar1 foobar2 H I J K L | 196 A B C D E F G M N O foobar1 foobar2 H I J K L |
| 197 foobar2 foobar3 | |
| 185 A old_file | 198 A old_file |
| 186 K sub_K | 199 K sub_K |
| 187 """) | 200 """) |
| 188 | 201 |
| 189 self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n') | 202 self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n') |
| 190 | 203 |
| 191 branches = self.repo.run(set, self.gc.branches()) | 204 branches = self.repo.run(set, self.gc.branches()) |
| 192 self.assertEqual(branches, {'branch_K', 'master', 'sub_K', 'root_A', | 205 self.assertEqual(branches, {'branch_K', 'master', 'sub_K', 'root_A', |
| 193 'branch_L', 'old_branch', 'foobar'}) | 206 'branch_L', 'old_branch', 'foobar', |
| 207 'sub_foobar'}) | |
| 194 | 208 |
| 195 self.repo.git('checkout', 'branch_K') | 209 self.repo.git('checkout', 'branch_K') |
| 196 self.repo.run(self.mv.main, ['special_K']) | 210 self.repo.run(self.mv.main, ['special_K']) |
| 197 | 211 |
| 198 branches = self.repo.run(set, self.gc.branches()) | 212 branches = self.repo.run(set, self.gc.branches()) |
| 199 self.assertEqual(branches, {'special_K', 'master', 'sub_K', 'root_A', | 213 self.assertEqual(branches, {'special_K', 'master', 'sub_K', 'root_A', |
| 200 'branch_L', 'old_branch', 'foobar'}) | 214 'branch_L', 'old_branch', 'foobar', |
| 215 'sub_foobar'}) | |
| 201 | 216 |
| 202 self.repo.git('checkout', 'origin/master') | 217 self.repo.git('checkout', 'origin/master') |
| 203 _, err = self.repo.capture_stdio(self.mv.main, ['special_K', 'cool branch']) | 218 _, err = self.repo.capture_stdio(self.mv.main, ['special_K', 'cool branch']) |
| 204 self.assertIn('fatal: \'cool branch\' is not a valid branch name.', err) | 219 self.assertIn('fatal: \'cool branch\' is not a valid branch name.', err) |
| 205 | 220 |
| 206 self.repo.run(self.mv.main, ['special_K', 'cool_branch']) | 221 self.repo.run(self.mv.main, ['special_K', 'cool_branch']) |
| 207 branches = self.repo.run(set, self.gc.branches()) | 222 branches = self.repo.run(set, self.gc.branches()) |
| 208 # This check fails with git 2.4 (see crbug.com/487172) | 223 # This check fails with git 2.4 (see crbug.com/487172) |
| 209 self.assertEqual(branches, {'cool_branch', 'master', 'sub_K', 'root_A', | 224 self.assertEqual(branches, {'cool_branch', 'master', 'sub_K', 'root_A', |
| 210 'branch_L', 'old_branch', 'foobar'}) | 225 'branch_L', 'old_branch', 'foobar', |
| 226 'sub_foobar'}) | |
| 211 | 227 |
| 212 _, branch_tree = self.repo.run(self.gc.get_branch_tree) | 228 _, branch_tree = self.repo.run(self.gc.get_branch_tree) |
| 213 self.assertEqual(branch_tree['sub_K'], 'foobar') | 229 self.assertEqual(branch_tree['sub_K'], 'foobar') |
| 214 | 230 |
| 215 | 231 |
| 216 def testRebaseConflicts(self): | 232 def testRebaseConflicts(self): |
| 217 # Pretend that branch_L landed | 233 # Pretend that branch_L landed |
| 218 self.origin.git('checkout', 'master') | 234 self.origin.git('checkout', 'master') |
| 219 with self.origin.open('L', 'w') as f: | 235 with self.origin.open('L', 'w') as f: |
| 220 f.write('L') | 236 f.write('L') |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 """) | 388 """) |
| 373 | 389 |
| 374 | 390 |
| 375 if __name__ == '__main__': | 391 if __name__ == '__main__': |
| 376 sys.exit(coverage_utils.covered_main(( | 392 sys.exit(coverage_utils.covered_main(( |
| 377 os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py'), | 393 os.path.join(DEPOT_TOOLS_ROOT, 'git_rebase_update.py'), |
| 378 os.path.join(DEPOT_TOOLS_ROOT, 'git_new_branch.py'), | 394 os.path.join(DEPOT_TOOLS_ROOT, 'git_new_branch.py'), |
| 379 os.path.join(DEPOT_TOOLS_ROOT, 'git_reparent_branch.py'), | 395 os.path.join(DEPOT_TOOLS_ROOT, 'git_reparent_branch.py'), |
| 380 os.path.join(DEPOT_TOOLS_ROOT, 'git_rename_branch.py') | 396 os.path.join(DEPOT_TOOLS_ROOT, 'git_rename_branch.py') |
| 381 ))) | 397 ))) |
| OLD | NEW |