| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import posixpath | 10 import posixpath |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 result, version = scm.GIT.AssertVersion('1.7') | 208 result, version = scm.GIT.AssertVersion('1.7') |
| 209 if not result: | 209 if not result: |
| 210 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) | 210 raise gclient_utils.Error('Git version is older than 1.7: %s' % version) |
| 211 return result | 211 return result |
| 212 except OSError: | 212 except OSError: |
| 213 return False | 213 return False |
| 214 | 214 |
| 215 def GetCheckoutRoot(self): | 215 def GetCheckoutRoot(self): |
| 216 return scm.GIT.GetCheckoutRoot(self.checkout_path) | 216 return scm.GIT.GetCheckoutRoot(self.checkout_path) |
| 217 | 217 |
| 218 def GetRemoteURL(self, options, cwd=None): |
| 219 try: |
| 220 return self._Capture(['config', 'remote.origin.url'], |
| 221 cwd=cwd or self.checkout_path).rstrip() |
| 222 except (OSError, subprocess2.CalledProcessError): |
| 223 return None |
| 224 |
| 218 def GetRevisionDate(self, _revision): | 225 def GetRevisionDate(self, _revision): |
| 219 """Returns the given revision's date in ISO-8601 format (which contains the | 226 """Returns the given revision's date in ISO-8601 format (which contains the |
| 220 time zone).""" | 227 time zone).""" |
| 221 # TODO(floitsch): get the time-stamp of the given revision and not just the | 228 # TODO(floitsch): get the time-stamp of the given revision and not just the |
| 222 # time-stamp of the currently checked out revision. | 229 # time-stamp of the currently checked out revision. |
| 223 return self._Capture(['log', '-n', '1', '--format=%ai']) | 230 return self._Capture(['log', '-n', '1', '--format=%ai']) |
| 224 | 231 |
| 225 @staticmethod | 232 @staticmethod |
| 226 def cleanup(options, args, file_list): | 233 def cleanup(options, args, file_list): |
| 227 """'Cleanup' the repo. | 234 """'Cleanup' the repo. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 # Not a fatal error, or even very interesting in a non-git-submodule | 272 # Not a fatal error, or even very interesting in a non-git-submodule |
| 266 # world. So just keep it quiet. | 273 # world. So just keep it quiet. |
| 267 pass | 274 pass |
| 268 try: | 275 try: |
| 269 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) | 276 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) |
| 270 except subprocess2.CalledProcessError: | 277 except subprocess2.CalledProcessError: |
| 271 gclient_utils.CheckCallAndFilter(cmd3 + ['always'], **kwargs) | 278 gclient_utils.CheckCallAndFilter(cmd3 + ['always'], **kwargs) |
| 272 | 279 |
| 273 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) | 280 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) |
| 274 | 281 |
| 275 def _FetchAndReset(self, revision, file_list, options): | |
| 276 """Equivalent to git fetch; git reset.""" | |
| 277 quiet = [] | |
| 278 if not options.verbose: | |
| 279 quiet = ['--quiet'] | |
| 280 self._UpdateBranchHeads(options, fetch=False) | |
| 281 | |
| 282 fetch_cmd = [ | |
| 283 '-c', 'core.deltaBaseCacheLimit=2g', 'fetch', 'origin', '--prune'] | |
| 284 self._Run(fetch_cmd + quiet, options, retry=True) | |
| 285 self._Run(['reset', '--hard', revision] + quiet, options) | |
| 286 self.UpdateSubmoduleConfig() | |
| 287 if file_list is not None: | |
| 288 files = self._Capture(['ls-files']).splitlines() | |
| 289 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | |
| 290 | |
| 291 def update(self, options, args, file_list): | 282 def update(self, options, args, file_list): |
| 292 """Runs git to update or transparently checkout the working copy. | 283 """Runs git to update or transparently checkout the working copy. |
| 293 | 284 |
| 294 All updated files will be appended to file_list. | 285 All updated files will be appended to file_list. |
| 295 | 286 |
| 296 Raises: | 287 Raises: |
| 297 Error: if can't get URL for relative path. | 288 Error: if can't get URL for relative path. |
| 298 """ | 289 """ |
| 299 if args: | 290 if args: |
| 300 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) | 291 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 357 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
| 367 | 358 |
| 368 if not os.path.exists(os.path.join(self.checkout_path, '.git')): | 359 if not os.path.exists(os.path.join(self.checkout_path, '.git')): |
| 369 raise gclient_utils.Error('\n____ %s%s\n' | 360 raise gclient_utils.Error('\n____ %s%s\n' |
| 370 '\tPath is not a git repo. No .git dir.\n' | 361 '\tPath is not a git repo. No .git dir.\n' |
| 371 '\tTo resolve:\n' | 362 '\tTo resolve:\n' |
| 372 '\t\trm -rf %s\n' | 363 '\t\trm -rf %s\n' |
| 373 '\tAnd run gclient sync again\n' | 364 '\tAnd run gclient sync again\n' |
| 374 % (self.relpath, rev_str, self.relpath)) | 365 % (self.relpath, rev_str, self.relpath)) |
| 375 | 366 |
| 376 # See if the url has changed (the unittests use git://foo for the url, let | |
| 377 # that through). | |
| 378 current_url = self._Capture(['config', 'remote.origin.url']) | |
| 379 return_early = False | |
| 380 # TODO(maruel): Delete url != 'git://foo' since it's just to make the | |
| 381 # unit test pass. (and update the comment above) | |
| 382 # Skip url auto-correction if remote.origin.gclient-auto-fix-url is set. | |
| 383 # This allows devs to use experimental repos which have a different url | |
| 384 # but whose branch(s) are the same as official repos. | |
| 385 if (current_url != url and | |
| 386 url != 'git://foo' and | |
| 387 subprocess2.capture( | |
| 388 ['git', 'config', 'remote.origin.gclient-auto-fix-url'], | |
| 389 cwd=self.checkout_path).strip() != 'False'): | |
| 390 print('_____ switching %s to a new upstream' % self.relpath) | |
| 391 # Make sure it's clean | |
| 392 self._CheckClean(rev_str) | |
| 393 # Switch over to the new upstream | |
| 394 self._Run(['remote', 'set-url', 'origin', url], options) | |
| 395 self._FetchAndReset(revision, file_list, options) | |
| 396 return_early = True | |
| 397 | |
| 398 # Need to do this in the normal path as well as in the post-remote-switch | 367 # Need to do this in the normal path as well as in the post-remote-switch |
| 399 # path. | 368 # path. |
| 400 self._PossiblySwitchCache(url, options) | 369 self._PossiblySwitchCache(url, options) |
| 401 | 370 |
| 402 if return_early: | |
| 403 return self._Capture(['rev-parse', '--verify', 'HEAD']) | |
| 404 | |
| 405 cur_branch = self._GetCurrentBranch() | 371 cur_branch = self._GetCurrentBranch() |
| 406 | 372 |
| 407 # Cases: | 373 # Cases: |
| 408 # 0) HEAD is detached. Probably from our initial clone. | 374 # 0) HEAD is detached. Probably from our initial clone. |
| 409 # - make sure HEAD is contained by a named ref, then update. | 375 # - make sure HEAD is contained by a named ref, then update. |
| 410 # Cases 1-4. HEAD is a branch. | 376 # Cases 1-4. HEAD is a branch. |
| 411 # 1) current branch is not tracking a remote branch (could be git-svn) | 377 # 1) current branch is not tracking a remote branch (could be git-svn) |
| 412 # - try to rebase onto the new hash or branch | 378 # - try to rebase onto the new hash or branch |
| 413 # 2) current branch is tracking a remote branch with local committed | 379 # 2) current branch is tracking a remote branch with local committed |
| 414 # changes, but the DEPS file switched to point to a hash | 380 # changes, but the DEPS file switched to point to a hash |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 if use_reference: | 766 if use_reference: |
| 801 cmd += ['--reference', os.path.abspath(self.checkout_path)] | 767 cmd += ['--reference', os.path.abspath(self.checkout_path)] |
| 802 | 768 |
| 803 self._Run(cmd + [url, folder], | 769 self._Run(cmd + [url, folder], |
| 804 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True) | 770 options, filter_fn=filter_fn, cwd=self.cache_dir, retry=True) |
| 805 else: | 771 else: |
| 806 # For now, assert that host/path/to/repo.git is identical. We may want | 772 # For now, assert that host/path/to/repo.git is identical. We may want |
| 807 # to relax this restriction in the future to allow for smarter cache | 773 # to relax this restriction in the future to allow for smarter cache |
| 808 # repo update schemes (such as pulling the same repo, but from a | 774 # repo update schemes (such as pulling the same repo, but from a |
| 809 # different host). | 775 # different host). |
| 810 existing_url = self._Capture(['config', 'remote.origin.url'], | 776 existing_url = self.GetRemoteURL(options, cwd=folder) |
| 811 cwd=folder) | |
| 812 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) | 777 assert self._NormalizeGitURL(existing_url) == self._NormalizeGitURL(url) |
| 813 | 778 |
| 814 if use_reference: | 779 if use_reference: |
| 815 with open(altfile, 'w') as f: | 780 with open(altfile, 'w') as f: |
| 816 f.write(os.path.abspath(checkout_objects)) | 781 f.write(os.path.abspath(checkout_objects)) |
| 817 | 782 |
| 818 # Would normally use `git remote update`, but it doesn't support | 783 # Would normally use `git remote update`, but it doesn't support |
| 819 # --progress, so use fetch instead. | 784 # --progress, so use fetch instead. |
| 820 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'], | 785 self._Run(['fetch'] + v + ['--multiple', '--progress', '--all'], |
| 821 options, filter_fn=filter_fn, cwd=folder, retry=True) | 786 options, filter_fn=filter_fn, cwd=folder, retry=True) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 result, version = scm.SVN.AssertVersion('1.4') | 1035 result, version = scm.SVN.AssertVersion('1.4') |
| 1071 if not result: | 1036 if not result: |
| 1072 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version) | 1037 raise gclient_utils.Error('SVN version is older than 1.4: %s' % version) |
| 1073 return result | 1038 return result |
| 1074 except OSError: | 1039 except OSError: |
| 1075 return False | 1040 return False |
| 1076 | 1041 |
| 1077 def GetCheckoutRoot(self): | 1042 def GetCheckoutRoot(self): |
| 1078 return scm.SVN.GetCheckoutRoot(self.checkout_path) | 1043 return scm.SVN.GetCheckoutRoot(self.checkout_path) |
| 1079 | 1044 |
| 1045 def GetRemoteURL(self, options): |
| 1046 try: |
| 1047 local_info = scm.SVN.CaptureLocalInfo([os.curdir], self.checkout_path) |
| 1048 except (OSError, subprocess2.CalledProcessError): |
| 1049 return None |
| 1050 return local_info.get('URL') |
| 1051 |
| 1080 def GetRevisionDate(self, revision): | 1052 def GetRevisionDate(self, revision): |
| 1081 """Returns the given revision's date in ISO-8601 format (which contains the | 1053 """Returns the given revision's date in ISO-8601 format (which contains the |
| 1082 time zone).""" | 1054 time zone).""" |
| 1083 date = scm.SVN.Capture( | 1055 date = scm.SVN.Capture( |
| 1084 ['propget', '--revprop', 'svn:date', '-r', revision], | 1056 ['propget', '--revprop', 'svn:date', '-r', revision], |
| 1085 os.path.join(self.checkout_path, '.')) | 1057 os.path.join(self.checkout_path, '.')) |
| 1086 return date.strip() | 1058 return date.strip() |
| 1087 | 1059 |
| 1088 def cleanup(self, options, args, _file_list): | 1060 def cleanup(self, options, args, _file_list): |
| 1089 """Cleanup working copy.""" | 1061 """Cleanup working copy.""" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 new_command.append('--force') | 1422 new_command.append('--force') |
| 1451 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1423 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1452 new_command.extend(('--accept', 'theirs-conflict')) | 1424 new_command.extend(('--accept', 'theirs-conflict')) |
| 1453 elif options.manually_grab_svn_rev: | 1425 elif options.manually_grab_svn_rev: |
| 1454 new_command.append('--force') | 1426 new_command.append('--force') |
| 1455 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1427 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1456 new_command.extend(('--accept', 'postpone')) | 1428 new_command.extend(('--accept', 'postpone')) |
| 1457 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1429 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1458 new_command.extend(('--accept', 'postpone')) | 1430 new_command.extend(('--accept', 'postpone')) |
| 1459 return new_command | 1431 return new_command |
| OLD | NEW |