| 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=None, executive=None, filesystem=None): | 51 def __init__(self, cwd, executive=None, filesystem=None): |
| 52 self.cwd = cwd |
| 52 self._executive = executive or Executive() | 53 self._executive = executive or Executive() |
| 53 self._filesystem = filesystem or FileSystem() | 54 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() | |
| 66 self.checkout_root = self.find_checkout_root(self.cwd) | 55 self.checkout_root = self.find_checkout_root(self.cwd) |
| 67 | 56 |
| 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 t
he real | |
| 79 # git executable, which is contained in a subdirectory. | |
| 80 _log.debug('Engaging git.bat Windows hack.') | |
| 81 self.executable_name = 'git.bat' | |
| 82 except OSError: | |
| 83 _log.debug('Failed to engage git.bat Windows hack.') | |
| 84 | |
| 85 def _run_git(self, | 57 def _run_git(self, |
| 86 command_args, | 58 command_args, |
| 87 cwd=None, | 59 cwd=None, |
| 88 input=None, # pylint: disable=redefined-builtin | 60 input=None, # pylint: disable=redefined-builtin |
| 89 timeout_seconds=None, | 61 timeout_seconds=None, |
| 90 decode_output=True, | 62 decode_output=True, |
| 91 return_exit_code=False): | 63 return_exit_code=False): |
| 92 full_command_args = [self.executable_name] + command_args | 64 full_command_args = [self.executable_name] + command_args |
| 93 cwd = cwd or self.checkout_root | 65 cwd = cwd or self.checkout_root |
| 94 return self._executive.run_command( | 66 return self._executive.run_command( |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if self.current_branch() != self._branch_tracking_remote_master(): | 384 if self.current_branch() != self._branch_tracking_remote_master(): |
| 413 return False | 385 return False |
| 414 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 386 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 415 return False | 387 return False |
| 416 return True | 388 return True |
| 417 | 389 |
| 418 def ensure_cleanly_tracking_remote_master(self): | 390 def ensure_cleanly_tracking_remote_master(self): |
| 419 self._discard_working_directory_changes() | 391 self._discard_working_directory_changes() |
| 420 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 392 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 421 self._discard_local_commits() | 393 self._discard_local_commits() |
| OLD | NEW |