| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return return_code != self.ERROR_FILE_IS_MISSING | 131 return return_code != self.ERROR_FILE_IS_MISSING |
| 132 | 132 |
| 133 def _branch_from_ref(self, ref): | 133 def _branch_from_ref(self, ref): |
| 134 return ref.replace('refs/heads/', '') | 134 return ref.replace('refs/heads/', '') |
| 135 | 135 |
| 136 def current_branch(self): | 136 def current_branch(self): |
| 137 return self._branch_from_ref(self._run_git(['symbolic-ref', '-q', 'HEAD'
]).strip()) | 137 return self._branch_from_ref(self._run_git(['symbolic-ref', '-q', 'HEAD'
]).strip()) |
| 138 | 138 |
| 139 def _upstream_branch(self): | 139 def _upstream_branch(self): |
| 140 current_branch = self.current_branch() | 140 current_branch = self.current_branch() |
| 141 # If the remote is pointing to something other than "." than the upstrea
m branch isn't a local branch. |
| 142 if self.read_git_config('branch.%s.remote' % current_branch, cwd=self.ch
eckout_root, executive=self._executive) != ".": |
| 143 return None |
| 141 return self._branch_from_ref(self.read_git_config('branch.%s.merge' % cu
rrent_branch, cwd=self.checkout_root, executive=self._executive).strip()) | 144 return self._branch_from_ref(self.read_git_config('branch.%s.merge' % cu
rrent_branch, cwd=self.checkout_root, executive=self._executive).strip()) |
| 142 | 145 |
| 143 def _merge_base(self, git_commit=None): | 146 def _merge_base(self, git_commit=None): |
| 144 if git_commit: | 147 if git_commit: |
| 145 # Rewrite UPSTREAM to the upstream branch | 148 # Rewrite UPSTREAM to the upstream branch |
| 146 if 'UPSTREAM' in git_commit: | 149 if 'UPSTREAM' in git_commit: |
| 147 upstream = self._upstream_branch() | 150 upstream = self._upstream_branch() |
| 148 if not upstream: | 151 if not upstream: |
| 149 raise ScriptError(message='No upstream/tracking branch set.'
) | 152 raise ScriptError(message='No upstream/tracking branch set.'
) |
| 150 git_commit = git_commit.replace('UPSTREAM', upstream) | 153 git_commit = git_commit.replace('UPSTREAM', upstream) |
| 151 | 154 |
| 152 # Special-case <refname>.. to include working copy changes, e.g., 'H
EAD....' shows only the diffs from HEAD. | 155 # Special-case <refname>.. to include working copy changes, e.g., 'H
EAD....' shows only the diffs from HEAD. |
| 153 if git_commit.endswith('....'): | 156 if git_commit.endswith('....'): |
| 154 return git_commit[:-4] | 157 return git_commit[:-4] |
| 155 | 158 |
| 156 if '..' not in git_commit: | 159 if '..' not in git_commit: |
| 157 git_commit = git_commit + "^.." + git_commit | 160 git_commit = git_commit + "^.." + git_commit |
| 158 return git_commit | 161 return git_commit |
| 159 | 162 |
| 163 upstream = self._upstream_branch() |
| 164 if upstream: |
| 165 return upstream |
| 166 |
| 160 return self._remote_merge_base() | 167 return self._remote_merge_base() |
| 161 | 168 |
| 162 def changed_files(self, git_commit=None): | 169 def changed_files(self, git_commit=None): |
| 163 # FIXME: --diff-filter could be used to avoid the "extract_filenames" st
ep. | 170 # FIXME: --diff-filter could be used to avoid the "extract_filenames" st
ep. |
| 164 status_command = [self.executable_name, 'diff', '-r', '--name-status', "
--no-renames", "--no-ext-diff", "--full-index", self._merge_base(git_commit)] | 171 status_command = [self.executable_name, 'diff', '-r', '--name-status', "
--no-renames", "--no-ext-diff", "--full-index", self._merge_base(git_commit)] |
| 165 # FIXME: I'm not sure we're returning the same set of files that SVN.cha
nged_files is. | 172 # FIXME: I'm not sure we're returning the same set of files that SVN.cha
nged_files is. |
| 166 # Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R) | 173 # Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R) |
| 167 return self._run_status_and_extract_filenames(status_command, self._stat
us_regexp("ADM")) | 174 return self._run_status_and_extract_filenames(status_command, self._stat
us_regexp("ADM")) |
| 168 | 175 |
| 169 def _added_files(self): | 176 def _added_files(self): |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if self.current_branch() != self._branch_tracking_remote_master(): | 318 if self.current_branch() != self._branch_tracking_remote_master(): |
| 312 return False | 319 return False |
| 313 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 320 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 314 return False | 321 return False |
| 315 return True | 322 return True |
| 316 | 323 |
| 317 def ensure_cleanly_tracking_remote_master(self): | 324 def ensure_cleanly_tracking_remote_master(self): |
| 318 self._discard_working_directory_changes() | 325 self._discard_working_directory_changes() |
| 319 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 326 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 320 self._discard_local_commits() | 327 self._discard_local_commits() |
| OLD | NEW |