| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 full_command_args = [self.executable_name] + command_args | 63 full_command_args = [self.executable_name] + command_args |
| 64 full_kwargs = kwargs | 64 full_kwargs = kwargs |
| 65 if 'cwd' not in full_kwargs: | 65 if 'cwd' not in full_kwargs: |
| 66 full_kwargs['cwd'] = self.checkout_root | 66 full_kwargs['cwd'] = self.checkout_root |
| 67 return self._run(full_command_args, **full_kwargs) | 67 return self._run(full_command_args, **full_kwargs) |
| 68 | 68 |
| 69 @classmethod | 69 @classmethod |
| 70 def in_working_directory(cls, path, executive=None): | 70 def in_working_directory(cls, path, executive=None): |
| 71 try: | 71 try: |
| 72 executive = executive or Executive() | 72 executive = executive or Executive() |
| 73 return executive.run_command([cls.executable_name, 'rev-parse', '--i
s-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() =
= "true" | 73 return executive.run_command([cls.executable_name, 'rev-parse', '--i
s-inside-work-tree'], |
| 74 except OSError, e: | 74 cwd=path, error_handler=Executive.ignor
e_error).rstrip() == "true" |
| 75 except OSError as e: |
| 75 # The Windows bots seem to through a WindowsError when git isn't ins
talled. | 76 # The Windows bots seem to through a WindowsError when git isn't ins
talled. |
| 76 return False | 77 return False |
| 77 | 78 |
| 78 def find_checkout_root(self, path): | 79 def find_checkout_root(self, path): |
| 79 # "git rev-parse --show-cdup" would be another way to get to the root | 80 # "git rev-parse --show-cdup" would be another way to get to the root |
| 80 checkout_root = self._run_git(['rev-parse', '--show-toplevel'], cwd=(pat
h or "./")).strip() | 81 checkout_root = self._run_git(['rev-parse', '--show-toplevel'], cwd=(pat
h or "./")).strip() |
| 81 if not self._filesystem.isabs(checkout_root): # Sometimes git returns r
elative paths | 82 if not self._filesystem.isabs(checkout_root): # Sometimes git returns r
elative paths |
| 82 checkout_root = self._filesystem.join(path, checkout_root) | 83 checkout_root = self._filesystem.join(path, checkout_root) |
| 83 return checkout_root | 84 return checkout_root |
| 84 | 85 |
| 85 @classmethod | 86 @classmethod |
| 86 def read_git_config(cls, key, cwd=None, executive=None): | 87 def read_git_config(cls, key, cwd=None, executive=None): |
| 87 # FIXME: This should probably use cwd=self.checkout_root. | 88 # FIXME: This should probably use cwd=self.checkout_root. |
| 88 # Pass --get-all for cases where the config has multiple values | 89 # Pass --get-all for cases where the config has multiple values |
| 89 # Pass the cwd if provided so that we can handle the case of running web
kit-patch outside of the working directory. | 90 # Pass the cwd if provided so that we can handle the case of running web
kit-patch outside of the working directory. |
| 90 # FIXME: This should use an Executive. | 91 # FIXME: This should use an Executive. |
| 91 executive = executive or Executive() | 92 executive = executive or Executive() |
| 92 return executive.run_command([cls.executable_name, "config", "--get-all"
, key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n') | 93 return executive.run_command( |
| 94 [cls.executable_name, "config", "--get-all", key], error_handler=Exe
cutive.ignore_error, cwd=cwd).rstrip('\n') |
| 93 | 95 |
| 94 def _discard_local_commits(self): | 96 def _discard_local_commits(self): |
| 95 self._run_git(['reset', '--hard', self._remote_branch_ref()]) | 97 self._run_git(['reset', '--hard', self._remote_branch_ref()]) |
| 96 | 98 |
| 97 def _local_commits(self, ref='HEAD'): | 99 def _local_commits(self, ref='HEAD'): |
| 98 return self._run_git(['log', '--pretty=oneline', ref + '...' + self._rem
ote_branch_ref()]).splitlines() | 100 return self._run_git(['log', '--pretty=oneline', ref + '...' + self._rem
ote_branch_ref()]).splitlines() |
| 99 | 101 |
| 100 def _rebase_in_progress(self): | 102 def _rebase_in_progress(self): |
| 101 return self._filesystem.exists(self.absolute_path(self._filesystem.join(
'.git', 'rebase-apply'))) | 103 return self._filesystem.exists(self.absolute_path(self._filesystem.join(
'.git', 'rebase-apply'))) |
| 102 | 104 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 def current_branch_or_ref(self): | 147 def current_branch_or_ref(self): |
| 146 """Returns the name of the current branch, or the commit hash if HEAD is
detached.""" | 148 """Returns the name of the current branch, or the commit hash if HEAD is
detached.""" |
| 147 branch_name = self.current_branch() | 149 branch_name = self.current_branch() |
| 148 if not branch_name: | 150 if not branch_name: |
| 149 # HEAD is detached; use commit SHA instead. | 151 # HEAD is detached; use commit SHA instead. |
| 150 return self._run_git(['rev-parse', 'HEAD']).strip() | 152 return self._run_git(['rev-parse', 'HEAD']).strip() |
| 151 return branch_name | 153 return branch_name |
| 152 | 154 |
| 153 def _upstream_branch(self): | 155 def _upstream_branch(self): |
| 154 current_branch = self.current_branch() | 156 current_branch = self.current_branch() |
| 155 return self._branch_from_ref(self.read_git_config('branch.%s.merge' % cu
rrent_branch, cwd=self.checkout_root, executive=self._executive).strip()) | 157 return self._branch_from_ref(self.read_git_config( |
| 158 'branch.%s.merge' % current_branch, cwd=self.checkout_root, executiv
e=self._executive).strip()) |
| 156 | 159 |
| 157 def _merge_base(self, git_commit=None): | 160 def _merge_base(self, git_commit=None): |
| 158 if git_commit: | 161 if git_commit: |
| 159 # Rewrite UPSTREAM to the upstream branch | 162 # Rewrite UPSTREAM to the upstream branch |
| 160 if 'UPSTREAM' in git_commit: | 163 if 'UPSTREAM' in git_commit: |
| 161 upstream = self._upstream_branch() | 164 upstream = self._upstream_branch() |
| 162 if not upstream: | 165 if not upstream: |
| 163 raise ScriptError(message='No upstream/tracking branch set.'
) | 166 raise ScriptError(message='No upstream/tracking branch set.'
) |
| 164 git_commit = git_commit.replace('UPSTREAM', upstream) | 167 git_commit = git_commit.replace('UPSTREAM', upstream) |
| 165 | 168 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if self.current_branch() != self._branch_tracking_remote_master(): | 323 if self.current_branch() != self._branch_tracking_remote_master(): |
| 321 return False | 324 return False |
| 322 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 325 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 323 return False | 326 return False |
| 324 return True | 327 return True |
| 325 | 328 |
| 326 def ensure_cleanly_tracking_remote_master(self): | 329 def ensure_cleanly_tracking_remote_master(self): |
| 327 self._discard_working_directory_changes() | 330 self._discard_working_directory_changes() |
| 328 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 331 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 329 self._discard_local_commits() | 332 self._discard_local_commits() |
| OLD | NEW |