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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 command.extend(['--', pathspec]) | 105 command.extend(['--', pathspec]) |
106 return self._run_git(command) != '' | 106 return self._run_git(command) != '' |
107 | 107 |
108 def _discard_working_directory_changes(self): | 108 def _discard_working_directory_changes(self): |
109 # Could run git clean here too, but that wouldn't match subversion | 109 # Could run git clean here too, but that wouldn't match subversion |
110 self._run_git(['reset', 'HEAD', '--hard']) | 110 self._run_git(['reset', 'HEAD', '--hard']) |
111 # Aborting rebase even though this does not match subversion | 111 # Aborting rebase even though this does not match subversion |
112 if self._rebase_in_progress(): | 112 if self._rebase_in_progress(): |
113 self._run_git(['rebase', '--abort']) | 113 self._run_git(['rebase', '--abort']) |
114 | 114 |
| 115 def unstaged_changes(self): |
| 116 """Lists files with unstaged changes, including untracked files. |
| 117 |
| 118 Returns a dict mapping modified file paths (relative to checkout root) |
| 119 to one-character codes identifying the change, e.g. 'M' for modified, |
| 120 'D' for deleted, '?' for untracked. |
| 121 """ |
| 122 # `git status -z` is a version of `git status -s`, that's recommended |
| 123 # for machine parsing. Lines are terminated with NUL rather than LF. |
| 124 unstaged_changes = {} |
| 125 change_lines = self._run_git(['status', '-z']).rstrip('\x00').split('\x0
0') |
| 126 for line in change_lines: |
| 127 if line[1] == ' ': |
| 128 continue # Already staged for commit. |
| 129 path = line[3:] |
| 130 unstaged_changes[path] = line[1] |
| 131 return unstaged_changes |
| 132 |
115 def status_command(self): | 133 def status_command(self): |
116 # git status returns non-zero when there are changes, so we use git diff
name --name-status HEAD instead. | 134 # git status returns non-zero when there are changes, so we use git diff
name --name-status HEAD instead. |
117 # No file contents printed, thus utf-8 autodecoding in self.run is fine. | 135 # No file contents printed, thus utf-8 autodecoding in self.run is fine. |
118 return [self.executable_name, "diff", "--name-status", "--no-renames", "
HEAD"] | 136 return [self.executable_name, "diff", "--name-status", "--no-renames", "
HEAD"] |
119 | 137 |
120 def _status_regexp(self, expected_types): | 138 def _status_regexp(self, expected_types): |
121 return '^(?P<status>[%s])\t(?P<filename>.+)$' % expected_types | 139 return '^(?P<status>[%s])\t(?P<filename>.+)$' % expected_types |
122 | 140 |
123 def add_all(self, pathspec=None): | 141 def add_all(self, pathspec=None): |
124 command = ['add', '--all'] | 142 command = ['add', '--all'] |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 if self.current_branch() != self._branch_tracking_remote_master(): | 348 if self.current_branch() != self._branch_tracking_remote_master(): |
331 return False | 349 return False |
332 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 350 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
333 return False | 351 return False |
334 return True | 352 return True |
335 | 353 |
336 def ensure_cleanly_tracking_remote_master(self): | 354 def ensure_cleanly_tracking_remote_master(self): |
337 self._discard_working_directory_changes() | 355 self._discard_working_directory_changes() |
338 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 356 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
339 self._discard_local_commits() | 357 self._discard_local_commits() |
OLD | NEW |