Chromium Code Reviews| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 114 |
| 115 def unstaged_changes(self): | 115 def unstaged_changes(self): |
| 116 """Lists files with unstaged changes, including untracked files. | 116 """Lists files with unstaged changes, including untracked files. |
| 117 | 117 |
| 118 Returns a dict mapping modified file paths (relative to checkout root) | 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, | 119 to one-character codes identifying the change, e.g. 'M' for modified, |
| 120 'D' for deleted, '?' for untracked. | 120 'D' for deleted, '?' for untracked. |
| 121 """ | 121 """ |
| 122 # `git status -z` is a version of `git status -s`, that's recommended | 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. | 123 # for machine parsing. Lines are terminated with NUL rather than LF. |
| 124 change_lines = self._run_git(['status', '-z']).rstrip('\x00') | |
| 125 if not change_lines: | |
| 126 return {} # No changes. | |
| 124 unstaged_changes = {} | 127 unstaged_changes = {} |
|
qyearsley
2016/12/28 18:47:20
Here, if there are no changes, then change_lines i
| |
| 125 change_lines = self._run_git(['status', '-z']).rstrip('\x00').split('\x0 0') | 128 for line in change_lines.split('\x00'): |
| 126 for line in change_lines: | 129 assert len(line) > 4, 'Unexpected change line format %s' % line |
| 127 if line[1] == ' ': | 130 if line[1] == ' ': |
| 128 continue # Already staged for commit. | 131 continue # Already staged for commit. |
| 129 path = line[3:] | 132 path = line[3:] |
| 130 unstaged_changes[path] = line[1] | 133 unstaged_changes[path] = line[1] |
| 131 return unstaged_changes | 134 return unstaged_changes |
| 132 | 135 |
| 133 def status_command(self): | 136 def status_command(self): |
| 134 # git status returns non-zero when there are changes, so we use git diff name --name-status HEAD instead. | 137 # git status returns non-zero when there are changes, so we use git diff name --name-status HEAD instead. |
| 135 # No file contents printed, thus utf-8 autodecoding in self.run is fine. | 138 # No file contents printed, thus utf-8 autodecoding in self.run is fine. |
| 136 return [self.executable_name, "diff", "--name-status", "--no-renames", " HEAD"] | 139 return [self.executable_name, "diff", "--name-status", "--no-renames", " HEAD"] |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 if self.current_branch() != self._branch_tracking_remote_master(): | 351 if self.current_branch() != self._branch_tracking_remote_master(): |
| 349 return False | 352 return False |
| 350 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: | 353 if len(self._local_commits(self._branch_tracking_remote_master())) > 0: |
| 351 return False | 354 return False |
| 352 return True | 355 return True |
| 353 | 356 |
| 354 def ensure_cleanly_tracking_remote_master(self): | 357 def ensure_cleanly_tracking_remote_master(self): |
| 355 self._discard_working_directory_changes() | 358 self._discard_working_directory_changes() |
| 356 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) | 359 self._run_git(['checkout', '-q', self._branch_tracking_remote_master()]) |
| 357 self._discard_local_commits() | 360 self._discard_local_commits() |
| OLD | NEW |