| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 def _discard_local_commits(self): | 93 def _discard_local_commits(self): |
| 94 self._run_git(['reset', '--hard', self._remote_branch_ref()]) | 94 self._run_git(['reset', '--hard', self._remote_branch_ref()]) |
| 95 | 95 |
| 96 def _local_commits(self, ref='HEAD'): | 96 def _local_commits(self, ref='HEAD'): |
| 97 return self._run_git(['log', '--pretty=oneline', ref + '...' + self._rem
ote_branch_ref()]).splitlines() | 97 return self._run_git(['log', '--pretty=oneline', ref + '...' + self._rem
ote_branch_ref()]).splitlines() |
| 98 | 98 |
| 99 def _rebase_in_progress(self): | 99 def _rebase_in_progress(self): |
| 100 return self._filesystem.exists(self.absolute_path(self._filesystem.join(
'.git', 'rebase-apply'))) | 100 return self._filesystem.exists(self.absolute_path(self._filesystem.join(
'.git', 'rebase-apply'))) |
| 101 | 101 |
| 102 def has_working_directory_changes(self): | 102 def has_working_directory_changes(self, pathspec=None): |
| 103 return self._run_git(['diff', 'HEAD', '--no-renames', '--name-only']) !=
"" | 103 """Checks whether there are uncommitted changes.""" |
| 104 command = ['diff', 'HEAD', '--no-renames', '--name-only'] |
| 105 if pathspec: |
| 106 command.extend(['--', pathspec]) |
| 107 return self._run_git(command) != '' |
| 104 | 108 |
| 105 def _discard_working_directory_changes(self): | 109 def _discard_working_directory_changes(self): |
| 106 # Could run git clean here too, but that wouldn't match subversion | 110 # Could run git clean here too, but that wouldn't match subversion |
| 107 self._run_git(['reset', 'HEAD', '--hard']) | 111 self._run_git(['reset', 'HEAD', '--hard']) |
| 108 # Aborting rebase even though this does not match subversion | 112 # Aborting rebase even though this does not match subversion |
| 109 if self._rebase_in_progress(): | 113 if self._rebase_in_progress(): |
| 110 self._run_git(['rebase', '--abort']) | 114 self._run_git(['rebase', '--abort']) |
| 111 | 115 |
| 112 def status_command(self): | 116 def status_command(self): |
| 113 # git status returns non-zero when there are changes, so we use git diff
name --name-status HEAD instead. | 117 # git status returns non-zero when there are changes, so we use git diff
name --name-status HEAD instead. |
| 114 # No file contents printed, thus utf-8 autodecoding in self.run is fine. | 118 # No file contents printed, thus utf-8 autodecoding in self.run is fine. |
| 115 return [self.executable_name, "diff", "--name-status", "--no-renames", "
HEAD"] | 119 return [self.executable_name, "diff", "--name-status", "--no-renames", "
HEAD"] |
| 116 | 120 |
| 117 def _status_regexp(self, expected_types): | 121 def _status_regexp(self, expected_types): |
| 118 return '^(?P<status>[%s])\t(?P<filename>.+)$' % expected_types | 122 return '^(?P<status>[%s])\t(?P<filename>.+)$' % expected_types |
| 119 | 123 |
| 124 def add_all(self, pathspec=None): |
| 125 command = ['add', '--all'] |
| 126 if pathspec: |
| 127 command.append(pathspec) |
| 128 return self._run_git(command) |
| 129 |
| 120 def add_list(self, paths, return_exit_code=False, recurse=True): | 130 def add_list(self, paths, return_exit_code=False, recurse=True): |
| 121 return self._run_git(["add"] + paths, return_exit_code=return_exit_code) | 131 return self._run_git(["add"] + paths, return_exit_code=return_exit_code) |
| 122 | 132 |
| 123 def delete_list(self, paths): | 133 def delete_list(self, paths): |
| 124 return self._run_git(["rm", "-f"] + paths) | 134 return self._run_git(["rm", "-f"] + paths) |
| 125 | 135 |
| 126 def move(self, origin, destination): | 136 def move(self, origin, destination): |
| 127 return self._run_git(["mv", "-f", origin, destination]) | 137 return self._run_git(["mv", "-f", origin, destination]) |
| 128 | 138 |
| 129 def exists(self, path): | 139 def exists(self, path): |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 if self.current_branch() != self._branch_tracking_remote_master(): | 331 if self.current_branch() != self._branch_tracking_remote_master(): |
| 322 return False | 332 return False |
| 323 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 333 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 324 return False | 334 return False |
| 325 return True | 335 return True |
| 326 | 336 |
| 327 def ensure_cleanly_tracking_remote_master(self): | 337 def ensure_cleanly_tracking_remote_master(self): |
| 328 self._discard_working_directory_changes() | 338 self._discard_working_directory_changes() |
| 329 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 339 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 330 self._discard_local_commits() | 340 self._discard_local_commits() |
| OLD | NEW |