| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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_cl.py.""" | 6 """Unit tests for git_cl.py.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import StringIO | 9 import StringIO |
| 10 import stat | 10 import stat |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 @classmethod | 116 @classmethod |
| 117 def _upload_no_rev_calls(cls, similarity, find_copies): | 117 def _upload_no_rev_calls(cls, similarity, find_copies): |
| 118 return (cls._git_base_calls(similarity, find_copies) + | 118 return (cls._git_base_calls(similarity, find_copies) + |
| 119 cls._git_upload_no_rev_calls()) | 119 cls._git_upload_no_rev_calls()) |
| 120 | 120 |
| 121 @classmethod | 121 @classmethod |
| 122 def _git_base_calls(cls, similarity, find_copies): | 122 def _git_base_calls(cls, similarity, find_copies): |
| 123 if similarity is None: | 123 if similarity is None: |
| 124 similarity = '50' | 124 similarity = '50' |
| 125 similarity_call = ((['git', '--no-pager', 'config', '--int', '--get', | 125 similarity_call = ((['git', 'config', '--int', '--get', |
| 126 'branch.master.git-cl-similarity'],), '') | 126 'branch.master.git-cl-similarity'],), '') |
| 127 else: | 127 else: |
| 128 similarity_call = ((['git', '--no-pager', 'config', '--int', | 128 similarity_call = ((['git', 'config', '--int', |
| 129 'branch.master.git-cl-similarity', similarity],), '') | 129 'branch.master.git-cl-similarity', similarity],), '') |
| 130 | 130 |
| 131 if find_copies is None: | 131 if find_copies is None: |
| 132 find_copies = True | 132 find_copies = True |
| 133 find_copies_call = ((['git', '--no-pager', 'config', '--int', '--get', | 133 find_copies_call = ((['git', 'config', '--int', '--get', |
| 134 'branch.master.git-find-copies'],), '') | 134 'branch.master.git-find-copies'],), '') |
| 135 else: | 135 else: |
| 136 val = str(int(find_copies)) | 136 val = str(int(find_copies)) |
| 137 find_copies_call = ((['git', '--no-pager', 'config', '--int', | 137 find_copies_call = ((['git', 'config', '--int', |
| 138 'branch.master.git-find-copies', val],), '') | 138 'branch.master.git-find-copies', val],), '') |
| 139 | 139 |
| 140 if find_copies: | 140 if find_copies: |
| 141 stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat', | 141 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 142 '--find-copies-harder', '-l100000', '-C'+similarity, | 142 '--find-copies-harder', '-l100000', '-C'+similarity, |
| 143 'fake_ancestor_sha', 'HEAD'],), '+dat') | 143 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 144 else: | 144 else: |
| 145 stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat', | 145 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 146 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
| 147 | 147 |
| 148 return [ | 148 return [ |
| 149 ((['git', '--no-pager', 'config', 'rietveld.server'],), | 149 ((['git', 'config', 'rietveld.server'],), |
| 150 'codereview.example.com'), | 150 'codereview.example.com'), |
| 151 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 151 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 152 similarity_call, | 152 similarity_call, |
| 153 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 153 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 154 find_copies_call, | 154 find_copies_call, |
| 155 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''), | 155 ((['git', 'update-index', '--refresh', '-q'],), ''), |
| 156 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), | 156 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), |
| 157 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 157 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 158 ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'), | 158 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 159 ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'), | 159 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 160 ((['git', '--no-pager', 'merge-base', 'master', 'HEAD'],), | 160 ((['git', 'merge-base', 'master', 'HEAD'],), |
| 161 'fake_ancestor_sha'), | 161 'fake_ancestor_sha'), |
| 162 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 162 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 163 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), | 163 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 164 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'), | 164 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 165 ((['git', '--no-pager', 'diff', '--name-status', '--no-renames', '-r', | 165 ((['git', 'diff', '--name-status', '--no-renames', '-r', |
| 166 'fake_ancestor_sha...', '.'],), | 166 'fake_ancestor_sha...', '.'],), |
| 167 'M\t.gitignore\n'), | 167 'M\t.gitignore\n'), |
| 168 ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''), | 168 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 169 ((['git', '--no-pager', 'config', 'branch.master.rietveldpatchset'],), | 169 ((['git', 'config', 'branch.master.rietveldpatchset'],), |
| 170 ''), | 170 ''), |
| 171 ((['git', '--no-pager', 'log', '--pretty=format:%s%n%n%b', | 171 ((['git', 'log', '--pretty=format:%s%n%n%b', |
| 172 'fake_ancestor_sha...'],), | 172 'fake_ancestor_sha...'],), |
| 173 'foo'), | 173 'foo'), |
| 174 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'), | 174 ((['git', 'config', 'user.email'],), 'me@example.com'), |
| 175 stat_call, | 175 stat_call, |
| 176 ((['git', '--no-pager', 'config', 'gerrit.host'],), ''), | 176 ((['git', 'config', 'gerrit.host'],), ''), |
| 177 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', | 177 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 178 'fake_ancestor_sha..HEAD'],), | 178 'fake_ancestor_sha..HEAD'],), |
| 179 'desc\n'), | 179 'desc\n'), |
| 180 ] | 180 ] |
| 181 | 181 |
| 182 @classmethod | 182 @classmethod |
| 183 def _git_upload_no_rev_calls(cls): | 183 def _git_upload_no_rev_calls(cls): |
| 184 return [ | 184 return [ |
| 185 ((['git', '--no-pager', 'config', 'core.editor'],), ''), | 185 ((['git', 'config', 'core.editor'],), ''), |
| 186 ] | 186 ] |
| 187 | 187 |
| 188 @classmethod | 188 @classmethod |
| 189 def _git_upload_calls(cls, private): | 189 def _git_upload_calls(cls, private): |
| 190 if private: | 190 if private: |
| 191 private_call = [] | 191 private_call = [] |
| 192 else: | 192 else: |
| 193 private_call = [ | 193 private_call = [ |
| 194 ((['git', '--no-pager', 'config', 'rietveld.private'],), '')] | 194 ((['git', 'config', 'rietveld.private'],), '')] |
| 195 | 195 |
| 196 return [ | 196 return [ |
| 197 ((['git', '--no-pager', 'config', 'core.editor'],), ''), | 197 ((['git', 'config', 'core.editor'],), ''), |
| 198 ((['git', '--no-pager', 'config', 'rietveld.cc'],), '') | 198 ((['git', 'config', 'rietveld.cc'],), '') |
| 199 ] + private_call + [ | 199 ] + private_call + [ |
| 200 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), | 200 ((['git', 'config', 'branch.master.base-url'],), ''), |
| 201 ((['git', '--no-pager', | 201 ((['git', |
| 202 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 202 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
| 203 (('', None), 0)), | 203 (('', None), 0)), |
| 204 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), | 204 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 205 ((['git', '--no-pager', 'svn', 'info'],), ''), | 205 ((['git', 'svn', 'info'],), ''), |
| 206 ((['git', '--no-pager', | 206 ((['git', |
| 207 'config', 'branch.master.rietveldissue', '1'],), ''), | 207 'config', 'branch.master.rietveldissue', '1'],), ''), |
| 208 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver', | 208 ((['git', 'config', 'branch.master.rietveldserver', |
| 209 'https://codereview.example.com'],), ''), | 209 'https://codereview.example.com'],), ''), |
| 210 ((['git', '--no-pager', | 210 ((['git', |
| 211 'config', 'branch.master.rietveldpatchset', '2'],), ''), | 211 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
| 212 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), | 212 ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
| 213 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), | 213 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
| 214 ((['git', '--no-pager', | 214 ((['git', |
| 215 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), | 215 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), |
| 216 ] | 216 ] |
| 217 | 217 |
| 218 @staticmethod | 218 @staticmethod |
| 219 def _git_sanity_checks(diff_base, working_branch): | 219 def _git_sanity_checks(diff_base, working_branch): |
| 220 fake_ancestor = 'fake_ancestor' | 220 fake_ancestor = 'fake_ancestor' |
| 221 fake_cl = 'fake_cl_for_patch' | 221 fake_cl = 'fake_cl_for_patch' |
| 222 return [ | 222 return [ |
| 223 # Calls to verify branch point is ancestor | 223 # Calls to verify branch point is ancestor |
| 224 ((['git', '--no-pager', | 224 ((['git', |
| 225 'rev-parse', '--verify', diff_base],), fake_ancestor), | 225 'rev-parse', '--verify', diff_base],), fake_ancestor), |
| 226 ((['git', '--no-pager', | 226 ((['git', |
| 227 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), | 227 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), |
| 228 ((['git', '--no-pager', | 228 ((['git', |
| 229 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), | 229 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), |
| 230 # Mock a config miss (error code 1) | 230 # Mock a config miss (error code 1) |
| 231 ((['git', '--no-pager', | 231 ((['git', |
| 232 'config', 'gitcl.remotebranch'],), (('', None), 1)), | 232 'config', 'gitcl.remotebranch'],), (('', None), 1)), |
| 233 # Call to GetRemoteBranch() | 233 # Call to GetRemoteBranch() |
| 234 ((['git', '--no-pager', | 234 ((['git', |
| 235 'config', 'branch.%s.merge' % working_branch],), | 235 'config', 'branch.%s.merge' % working_branch],), |
| 236 'refs/heads/master'), | 236 'refs/heads/master'), |
| 237 ((['git', '--no-pager', | 237 ((['git', |
| 238 'config', 'branch.%s.remote' % working_branch],), 'origin'), | 238 'config', 'branch.%s.remote' % working_branch],), 'origin'), |
| 239 ((['git', '--no-pager', 'rev-list', '^' + fake_ancestor, | 239 ((['git', 'rev-list', '^' + fake_ancestor, |
| 240 'refs/remotes/origin/master'],), ''), | 240 'refs/remotes/origin/master'],), ''), |
| 241 ] | 241 ] |
| 242 | 242 |
| 243 @classmethod | 243 @classmethod |
| 244 def _dcommit_calls_1(cls): | 244 def _dcommit_calls_1(cls): |
| 245 return [ | 245 return [ |
| 246 ((['git', '--no-pager', | 246 ((['git', |
| 247 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 247 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
| 248 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | 248 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
| 249 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | 249 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
| 250 None), | 250 None), |
| 251 0)), | 251 0)), |
| 252 ((['git', '--no-pager', | 252 ((['git', |
| 253 'config', 'rietveld.server'],), 'codereview.example.com'), | 253 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 254 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 254 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 255 ((['git', '--no-pager', 'config', '--int', '--get', | 255 ((['git', 'config', '--int', '--get', |
| 256 'branch.working.git-cl-similarity'],), ''), | 256 'branch.working.git-cl-similarity'],), ''), |
| 257 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 257 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 258 ((['git', '--no-pager', 'config', '--int', '--get', | 258 ((['git', 'config', '--int', '--get', |
| 259 'branch.working.git-find-copies'],), ''), | 259 'branch.working.git-find-copies'],), ''), |
| 260 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 260 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 261 ((['git', '--no-pager', | 261 ((['git', |
| 262 'config', 'branch.working.merge'],), 'refs/heads/master'), | 262 'config', 'branch.working.merge'],), 'refs/heads/master'), |
| 263 ((['git', '--no-pager', 'config', 'branch.working.remote'],), 'origin'), | 263 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
| 264 ((['git', '--no-pager', 'rev-list', '--merges', | 264 ((['git', 'rev-list', '--merges', |
| 265 '--grep=^SVN changes up to revision [0-9]*$', | 265 '--grep=^SVN changes up to revision [0-9]*$', |
| 266 'refs/remotes/origin/master^!'],), ''), | 266 'refs/remotes/origin/master^!'],), ''), |
| 267 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''), | 267 ((['git', 'update-index', '--refresh', '-q'],), ''), |
| 268 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), | 268 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), |
| 269 ((['git', '--no-pager', 'rev-list', '^refs/heads/working', | 269 ((['git', 'rev-list', '^refs/heads/working', |
| 270 'refs/remotes/origin/master'],), | 270 'refs/remotes/origin/master'],), |
| 271 ''), | 271 ''), |
| 272 ((['git', '--no-pager', | 272 ((['git', |
| 273 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), | 273 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), |
| 274 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), | 274 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), |
| 275 ((['git', '--no-pager', | 275 ((['git', |
| 276 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', | 276 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', |
| 277 'refs/remotes/origin/master'],), ''), | 277 'refs/remotes/origin/master'],), ''), |
| 278 ((['git', '--no-pager', | 278 ((['git', |
| 279 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), | 279 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), |
| 280 'fake_ancestor_sha'), | 280 'fake_ancestor_sha'), |
| 281 ] | 281 ] |
| 282 | 282 |
| 283 @classmethod | 283 @classmethod |
| 284 def _dcommit_calls_normal(cls): | 284 def _dcommit_calls_normal(cls): |
| 285 return [ | 285 return [ |
| 286 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), | 286 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 287 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), | 287 ((['git', 'rev-parse', 'HEAD'],), |
| 288 '00ff397798ea57439712ed7e04ab96e13969ef40'), | 288 '00ff397798ea57439712ed7e04ab96e13969ef40'), |
| 289 ((['git', '--no-pager', | 289 ((['git', |
| 290 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', | 290 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', |
| 291 '.'],), | 291 '.'],), |
| 292 'M\tPRESUBMIT.py'), | 292 'M\tPRESUBMIT.py'), |
| 293 ((['git', '--no-pager', | 293 ((['git', |
| 294 'config', 'branch.working.rietveldissue'],), '12345'), | 294 'config', 'branch.working.rietveldissue'],), '12345'), |
| 295 ((['git', '--no-pager', | 295 ((['git', |
| 296 'config', 'branch.working.rietveldpatchset'],), '31137'), | 296 'config', 'branch.working.rietveldpatchset'],), '31137'), |
| 297 ((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],), | 297 ((['git', 'config', 'branch.working.rietveldserver'],), |
| 298 'codereview.example.com'), | 298 'codereview.example.com'), |
| 299 ((['git', '--no-pager', 'config', 'user.email'],), 'author@example.com'), | 299 ((['git', 'config', 'user.email'],), 'author@example.com'), |
| 300 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), | 300 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
| 301 ] | 301 ] |
| 302 | 302 |
| 303 @classmethod | 303 @classmethod |
| 304 def _dcommit_calls_bypassed(cls): | 304 def _dcommit_calls_bypassed(cls): |
| 305 return [ | 305 return [ |
| 306 ((['git', '--no-pager', | 306 ((['git', |
| 307 'config', 'branch.working.rietveldissue'],), '12345'), | 307 'config', 'branch.working.rietveldissue'],), '12345'), |
| 308 ((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],), | 308 ((['git', 'config', 'branch.working.rietveldserver'],), |
| 309 'codereview.example.com'), | 309 'codereview.example.com'), |
| 310 (('GitClHooksBypassedCommit', | 310 (('GitClHooksBypassedCommit', |
| 311 'Issue https://codereview.example.com/12345 bypassed hook when ' | 311 'Issue https://codereview.example.com/12345 bypassed hook when ' |
| 312 'committing'), None), | 312 'committing'), None), |
| 313 ] | 313 ] |
| 314 | 314 |
| 315 @classmethod | 315 @classmethod |
| 316 def _dcommit_calls_3(cls): | 316 def _dcommit_calls_3(cls): |
| 317 return [ | 317 return [ |
| 318 ((['git', '--no-pager', | 318 ((['git', |
| 319 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 319 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
| 320 '-l100000', '-C50', 'fake_ancestor_sha', | 320 '-l100000', '-C50', 'fake_ancestor_sha', |
| 321 'refs/heads/working'],), | 321 'refs/heads/working'],), |
| 322 (' PRESUBMIT.py | 2 +-\n' | 322 (' PRESUBMIT.py | 2 +-\n' |
| 323 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), | 323 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), |
| 324 (('About to commit; enter to confirm.',), None), | 324 (('About to commit; enter to confirm.',), None), |
| 325 ((['git', '--no-pager', 'show-ref', '--quiet', '--verify', | 325 ((['git', 'show-ref', '--quiet', '--verify', |
| 326 'refs/heads/git-cl-commit'],), | 326 'refs/heads/git-cl-commit'],), |
| 327 (('', None), 0)), | 327 (('', None), 0)), |
| 328 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''), | 328 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
| 329 ((['git', '--no-pager', 'show-ref', '--quiet', '--verify', | 329 ((['git', 'show-ref', '--quiet', '--verify', |
| 330 'refs/heads/git-cl-cherry-pick'],), ''), | 330 'refs/heads/git-cl-cherry-pick'],), ''), |
| 331 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), '\n'), | 331 ((['git', 'rev-parse', '--show-cdup'],), '\n'), |
| 332 ((['git', '--no-pager', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | 332 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), |
| 333 ((['git', '--no-pager', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | 333 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), |
| 334 ((['git', '--no-pager', 'commit', '-m', | 334 ((['git', 'commit', '-m', |
| 335 'Issue: 12345\n\nR=john@chromium.org\n\n' | 335 'Issue: 12345\n\nR=john@chromium.org\n\n' |
| 336 'Review URL: https://codereview.example.com/12345'],), | 336 'Review URL: https://codereview.example.com/12345'],), |
| 337 ''), | 337 ''), |
| 338 ((['git', '--no-pager', | 338 ((['git', |
| 339 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), | 339 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), |
| 340 (('', None), 0)), | 340 (('', None), 0)), |
| 341 ((['git', '--no-pager', 'checkout', '-q', 'working'],), ''), | 341 ((['git', 'checkout', '-q', 'working'],), ''), |
| 342 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''), | 342 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
| 343 ] | 343 ] |
| 344 | 344 |
| 345 @staticmethod | 345 @staticmethod |
| 346 def _cmd_line(description, args, similarity, find_copies, private): | 346 def _cmd_line(description, args, similarity, find_copies, private): |
| 347 """Returns the upload command line passed to upload.RealMain().""" | 347 """Returns the upload command line passed to upload.RealMain().""" |
| 348 return [ | 348 return [ |
| 349 'upload', '--assume_yes', '--server', | 349 'upload', '--assume_yes', '--server', |
| 350 'https://codereview.example.com', | 350 'https://codereview.example.com', |
| 351 '--message', description | 351 '--message', description |
| 352 ] + args + [ | 352 ] + args + [ |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 self.calls = ( | 507 self.calls = ( |
| 508 self._dcommit_calls_1() + | 508 self._dcommit_calls_1() + |
| 509 self._dcommit_calls_bypassed() + | 509 self._dcommit_calls_bypassed() + |
| 510 self._dcommit_calls_3()) | 510 self._dcommit_calls_3()) |
| 511 git_cl.main(['dcommit', '--bypass-hooks']) | 511 git_cl.main(['dcommit', '--bypass-hooks']) |
| 512 | 512 |
| 513 | 513 |
| 514 @classmethod | 514 @classmethod |
| 515 def _gerrit_base_calls(cls): | 515 def _gerrit_base_calls(cls): |
| 516 return [ | 516 return [ |
| 517 ((['git', '--no-pager', | 517 ((['git', |
| 518 'config', 'rietveld.server'],), 'codereview.example.com'), | 518 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 519 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 519 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 520 ((['git', '--no-pager', 'config', '--int', '--get', | 520 ((['git', 'config', '--int', '--get', |
| 521 'branch.master.git-cl-similarity'],), ''), | 521 'branch.master.git-cl-similarity'],), ''), |
| 522 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 522 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 523 ((['git', '--no-pager', 'config', '--int', '--get', | 523 ((['git', 'config', '--int', '--get', |
| 524 'branch.master.git-find-copies'],), ''), | 524 'branch.master.git-find-copies'],), ''), |
| 525 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''), | 525 ((['git', 'update-index', '--refresh', '-q'],), ''), |
| 526 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''), | 526 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), |
| 527 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'), | 527 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 528 ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'), | 528 ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 529 ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'), | 529 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 530 ((['git', '--no-pager', | 530 ((['git', |
| 531 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), | 531 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), |
| 532 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 532 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
| 533 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), | 533 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 534 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'), | 534 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 535 ((['git', '--no-pager', | 535 ((['git', |
| 536 'diff', '--name-status', '--no-renames', '-r', | 536 'diff', '--name-status', '--no-renames', '-r', |
| 537 'fake_ancestor_sha...', '.'],), | 537 'fake_ancestor_sha...', '.'],), |
| 538 'M\t.gitignore\n'), | 538 'M\t.gitignore\n'), |
| 539 ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''), | 539 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 540 ((['git', '--no-pager', | 540 ((['git', |
| 541 'config', 'branch.master.rietveldpatchset'],), ''), | 541 'config', 'branch.master.rietveldpatchset'],), ''), |
| 542 ((['git', '--no-pager', | 542 ((['git', |
| 543 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 543 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
| 544 'foo'), | 544 'foo'), |
| 545 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'), | 545 ((['git', 'config', 'user.email'],), 'me@example.com'), |
| 546 ((['git', '--no-pager', | 546 ((['git', |
| 547 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 547 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
| 548 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 548 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
| 549 '+dat'), | 549 '+dat'), |
| 550 ] | 550 ] |
| 551 | 551 |
| 552 @staticmethod | 552 @staticmethod |
| 553 def _gerrit_upload_calls(description, reviewers): | 553 def _gerrit_upload_calls(description, reviewers): |
| 554 calls = [ | 554 calls = [ |
| 555 ((['git', '--no-pager', 'config', 'gerrit.host'],), | 555 ((['git', 'config', 'gerrit.host'],), |
| 556 'gerrit.example.com'), | 556 'gerrit.example.com'), |
| 557 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', | 557 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 558 'fake_ancestor_sha..HEAD'],), | 558 'fake_ancestor_sha..HEAD'],), |
| 559 description) | 559 description) |
| 560 ] | 560 ] |
| 561 if git_cl.CHANGE_ID not in description: | 561 if git_cl.CHANGE_ID not in description: |
| 562 calls += [ | 562 calls += [ |
| 563 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', | 563 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 564 'fake_ancestor_sha..HEAD'],), | 564 'fake_ancestor_sha..HEAD'],), |
| 565 description), | 565 description), |
| 566 ((['git', '--no-pager', 'commit', '--amend', '-m', description],), | 566 ((['git', 'commit', '--amend', '-m', description],), |
| 567 ''), | 567 ''), |
| 568 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b', | 568 ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 569 'fake_ancestor_sha..HEAD'],), | 569 'fake_ancestor_sha..HEAD'],), |
| 570 description) | 570 description) |
| 571 ] | 571 ] |
| 572 calls += [ | 572 calls += [ |
| 573 ((['git', '--no-pager', 'config', 'rietveld.cc'],), '') | 573 ((['git', 'config', 'rietveld.cc'],), '') |
| 574 ] | 574 ] |
| 575 receive_pack = '--receive-pack=git receive-pack ' | 575 receive_pack = '--receive-pack=git receive-pack ' |
| 576 receive_pack += '--cc=joe@example.com' # from watch list | 576 receive_pack += '--cc=joe@example.com' # from watch list |
| 577 if reviewers: | 577 if reviewers: |
| 578 receive_pack += ' ' | 578 receive_pack += ' ' |
| 579 receive_pack += ' '.join( | 579 receive_pack += ' '.join( |
| 580 '--reviewer=' + email for email in sorted(reviewers)) | 580 '--reviewer=' + email for email in sorted(reviewers)) |
| 581 receive_pack += '' | 581 receive_pack += '' |
| 582 calls += [ | 582 calls += [ |
| 583 ((['git', '--no-pager', | 583 ((['git', |
| 584 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), | 584 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), |
| 585 '') | 585 '') |
| 586 ] | 586 ] |
| 587 return calls | 587 return calls |
| 588 | 588 |
| 589 def _run_gerrit_upload_test( | 589 def _run_gerrit_upload_test( |
| 590 self, | 590 self, |
| 591 upload_args, | 591 upload_args, |
| 592 description, | 592 description, |
| 593 reviewers): | 593 reviewers): |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 self.mock(git_cl.os.path, 'abspath', AbsPath) | 642 self.mock(git_cl.os.path, 'abspath', AbsPath) |
| 643 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') | 643 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') |
| 644 def Exists(path): | 644 def Exists(path): |
| 645 if path == commit_msg_path: | 645 if path == commit_msg_path: |
| 646 return False | 646 return False |
| 647 # others paths, such as /usr/share/locale/.... | 647 # others paths, such as /usr/share/locale/.... |
| 648 return True | 648 return True |
| 649 self.mock(git_cl.os.path, 'exists', Exists) | 649 self.mock(git_cl.os.path, 'exists', Exists) |
| 650 self.mock(git_cl, 'urlretrieve', self._mocked_call) | 650 self.mock(git_cl, 'urlretrieve', self._mocked_call) |
| 651 self.calls = [ | 651 self.calls = [ |
| 652 ((['git', '--no-pager', 'config', 'rietveld.server', | 652 ((['git', 'config', 'rietveld.server', |
| 653 'gerrit.chromium.org'],), ''), | 653 'gerrit.chromium.org'],), ''), |
| 654 ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''), | 654 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), |
| 655 ((['git', '--no-pager', 'config', '--unset-all', | 655 ((['git', 'config', '--unset-all', |
| 656 'rietveld.private'],), ''), | 656 'rietveld.private'],), ''), |
| 657 ((['git', '--no-pager', 'config', '--unset-all', | 657 ((['git', 'config', '--unset-all', |
| 658 'rietveld.tree-status-url'],), ''), | 658 'rietveld.tree-status-url'],), ''), |
| 659 ((['git', '--no-pager', 'config', '--unset-all', | 659 ((['git', 'config', '--unset-all', |
| 660 'rietveld.viewvc-url'],), ''), | 660 'rietveld.viewvc-url'],), ''), |
| 661 ((['git', '--no-pager', 'config', 'gerrit.host', | 661 ((['git', 'config', 'gerrit.host', |
| 662 'gerrit.chromium.org'],), ''), | 662 'gerrit.chromium.org'],), ''), |
| 663 ((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''), | 663 ((['git', 'config', 'gerrit.port', '29418'],), ''), |
| 664 # DownloadHooks(False) | 664 # DownloadHooks(False) |
| 665 ((['git', '--no-pager', 'config', 'gerrit.host'],), | 665 ((['git', 'config', 'gerrit.host'],), |
| 666 'gerrit.chromium.org'), | 666 'gerrit.chromium.org'), |
| 667 ((['git', '--no-pager', 'config', 'rietveld.server'],), | 667 ((['git', 'config', 'rietveld.server'],), |
| 668 'gerrit.chromium.org'), | 668 'gerrit.chromium.org'), |
| 669 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), | 669 ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 670 ((commit_msg_path, os.X_OK,), False), | 670 ((commit_msg_path, os.X_OK,), False), |
| 671 (('https://gerrit.chromium.org/tools/hooks/commit-msg', | 671 (('https://gerrit.chromium.org/tools/hooks/commit-msg', |
| 672 commit_msg_path,), ''), | 672 commit_msg_path,), ''), |
| 673 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), | 673 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), |
| 674 # GetCodereviewSettingsInteractively | 674 # GetCodereviewSettingsInteractively |
| 675 ((['git', '--no-pager', 'config', 'rietveld.server'],), | 675 ((['git', 'config', 'rietveld.server'],), |
| 676 'gerrit.chromium.org'), | 676 'gerrit.chromium.org'), |
| 677 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), | 677 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), |
| 678 ''), | 678 ''), |
| 679 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), | 679 ((['git', 'config', 'rietveld.cc'],), ''), |
| 680 (('CC list:',), ''), | 680 (('CC list:',), ''), |
| 681 ((['git', '--no-pager', 'config', 'rietveld.private'],), ''), | 681 ((['git', 'config', 'rietveld.private'],), ''), |
| 682 (('Private flag (rietveld only):',), ''), | 682 (('Private flag (rietveld only):',), ''), |
| 683 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), | 683 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
| 684 (('Tree status URL:',), ''), | 684 (('Tree status URL:',), ''), |
| 685 ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''), | 685 ((['git', 'config', 'rietveld.viewvc-url'],), ''), |
| 686 (('ViewVC URL:',), ''), | 686 (('ViewVC URL:',), ''), |
| 687 # DownloadHooks(True) | 687 # DownloadHooks(True) |
| 688 ((commit_msg_path, os.X_OK,), True), | 688 ((commit_msg_path, os.X_OK,), True), |
| 689 ] | 689 ] |
| 690 git_cl.main(['config']) | 690 git_cl.main(['config']) |
| 691 | 691 |
| 692 def test_update_reviewers(self): | 692 def test_update_reviewers(self): |
| 693 data = [ | 693 data = [ |
| 694 ('foo', [], 'foo'), | 694 ('foo', [], 'foo'), |
| 695 ('foo', ['a@c'], 'foo\n\nR=a@c'), | 695 ('foo', ['a@c'], 'foo\n\nR=a@c'), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 712 obj = git_cl.ChangeDescription(orig) | 712 obj = git_cl.ChangeDescription(orig) |
| 713 obj.update_reviewers(reviewers) | 713 obj.update_reviewers(reviewers) |
| 714 actual.append(obj.description) | 714 actual.append(obj.description) |
| 715 self.assertEqual(expected, actual) | 715 self.assertEqual(expected, actual) |
| 716 | 716 |
| 717 | 717 |
| 718 if __name__ == '__main__': | 718 if __name__ == '__main__': |
| 719 git_cl.logging.basicConfig( | 719 git_cl.logging.basicConfig( |
| 720 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 720 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
| 721 unittest.main() | 721 unittest.main() |
| OLD | NEW |