Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2009, 2010, 2011 Google Inc. All rights reserved. | 1 # Copyright (c) 2009, 2010, 2011 Google Inc. All rights reserved. |
| 2 # Copyright (c) 2009 Apple Inc. All rights reserved. | 2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 class Git(object): | 41 class Git(object): |
| 42 # Unless otherwise specified, methods are expected to return paths relative | 42 # Unless otherwise specified, methods are expected to return paths relative |
| 43 # to self.checkout_root. | 43 # to self.checkout_root. |
| 44 | 44 |
| 45 # Git doesn't appear to document error codes, but seems to return | 45 # Git doesn't appear to document error codes, but seems to return |
| 46 # 1 or 128, mostly. | 46 # 1 or 128, mostly. |
| 47 ERROR_FILE_IS_MISSING = 128 | 47 ERROR_FILE_IS_MISSING = 128 |
| 48 | 48 |
| 49 executable_name = 'git' | 49 executable_name = 'git' |
| 50 | 50 |
| 51 def __init__(self, cwd, executive=None, filesystem=None): | 51 def __init__(self, cwd=None, executive=None, filesystem=None): |
| 52 self.cwd = cwd | |
| 53 self._executive = executive or Executive() | 52 self._executive = executive or Executive() |
| 54 self._filesystem = filesystem or FileSystem() | 53 self._filesystem = filesystem or FileSystem() |
| 54 | |
| 55 self.cwd = cwd or self._filesystem.abspath(self._filesystem.getcwd()) | |
| 56 if not Git.in_working_directory(self.cwd, executive=self._executive): | |
| 57 module_directory = self._filesystem.abspath( | |
| 58 self._filesystem.dirname(self._filesystem.path_to_module(self.__ module__))) | |
| 59 _log.info('The current directory (%s) is not in a git repo, trying d irectory %s.', | |
| 60 cwd, module_directory) | |
| 61 if Git.in_working_directory(module_directory, executive=self._execut ive): | |
| 62 self.cwd = module_directory | |
| 63 _log.error('Failed to find Git repo for %s or %s', cwd, module_direc tory) | |
| 64 | |
| 65 self._init_executable_name() | |
| 55 self.checkout_root = self.find_checkout_root(self.cwd) | 66 self.checkout_root = self.find_checkout_root(self.cwd) |
| 56 | 67 |
| 68 def _init_executable_name(self): | |
| 69 # FIXME: This is a hack and should be removed. | |
| 70 try: | |
| 71 self._executive.run_command(['git', 'help']) | |
| 72 except OSError: | |
| 73 try: | |
| 74 self._executive.run_command(['git.bat', 'help']) | |
| 75 # The Win port uses the depot_tools package, which contains a nu mber | |
| 76 # of development tools, including Python and git. Instead of usi ng a | |
| 77 # real git executable, depot_tools indirects via a batch file, c alled | |
| 78 # git.bat. This batch file allows depot_tools to auto-update the real | |
| 79 # git executable, which is contained in a subdirectory. | |
| 80 # | |
| 81 # That's all fine and good, except that subprocess.popen can det ect | |
| 82 # the difference between a real git executable and batch file wh en we | |
| 83 # don't provide use shell=True. Rather than use shell=True on Wi ndows, | |
| 84 # We hack the git.bat name into the SVN class. | |
|
jeffcarp
2017/01/31 22:24:56
The 'SVN class' reference is no longer accurate (w
qyearsley
2017/02/01 00:58:47
Gah, I'm not sure, I think it might originally hav
| |
| 85 _log.debug('Engaging git.bat Windows hack.') | |
| 86 self.executable_name = 'git.bat' | |
| 87 except OSError: | |
| 88 _log.debug('Failed to engage git.bat Windows hack.') | |
| 89 | |
| 57 def _run_git(self, | 90 def _run_git(self, |
| 58 command_args, | 91 command_args, |
| 59 cwd=None, | 92 cwd=None, |
| 60 input=None, # pylint: disable=redefined-builtin | 93 input=None, # pylint: disable=redefined-builtin |
| 61 timeout_seconds=None, | 94 timeout_seconds=None, |
| 62 decode_output=True, | 95 decode_output=True, |
| 63 return_exit_code=False): | 96 return_exit_code=False): |
| 64 full_command_args = [self.executable_name] + command_args | 97 full_command_args = [self.executable_name] + command_args |
| 65 cwd = cwd or self.checkout_root | 98 cwd = cwd or self.checkout_root |
| 66 return self._executive.run_command( | 99 return self._executive.run_command( |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 if self.current_branch() != self._branch_tracking_remote_master(): | 417 if self.current_branch() != self._branch_tracking_remote_master(): |
| 385 return False | 418 return False |
| 386 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 419 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 387 return False | 420 return False |
| 388 return True | 421 return True |
| 389 | 422 |
| 390 def ensure_cleanly_tracking_remote_master(self): | 423 def ensure_cleanly_tracking_remote_master(self): |
| 391 self._discard_working_directory_changes() | 424 self._discard_working_directory_changes() |
| 392 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 425 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 393 self._discard_local_commits() | 426 self._discard_local_commits() |
| OLD | NEW |