Commit bae81507 authored by qyearsley's avatar qyearsley Committed by Commit bot

In Git.unstaged_files, handle the case when there are no changes.

This is a follow-up fix to a mistake in http://crrev.com/2590693002.

BUG=662584

Review-Url: https://codereview.chromium.org/2605933002
Cr-Commit-Position: refs/heads/master@{#440887}
parent 38d9efa1
......@@ -121,9 +121,12 @@ class Git(SCM):
"""
# `git status -z` is a version of `git status -s`, that's recommended
# for machine parsing. Lines are terminated with NUL rather than LF.
change_lines = self._run_git(['status', '-z']).rstrip('\x00')
if not change_lines:
return {} # No changes.
unstaged_changes = {}
change_lines = self._run_git(['status', '-z']).rstrip('\x00').split('\x00')
for line in change_lines:
for line in change_lines.split('\x00'):
assert len(line) > 4, 'Unexpected change line format %s' % line
if line[1] == ' ':
continue # Already staged for commit.
path = line[3:]
......
......@@ -255,7 +255,7 @@ class GitTestWithMock(SCMTestBase):
def test_unstaged_files(self):
scm = self.make_scm()
status_lines = [
lines = [
' M d/modified.txt',
' D d/deleted.txt',
'?? d/untracked.txt',
......@@ -263,8 +263,7 @@ class GitTestWithMock(SCMTestBase):
'M d/modified-staged.txt',
'A d/added-staged.txt',
]
# pylint: disable=protected-access
scm._run_git = lambda args: '\x00'.join(status_lines) + '\x00'
scm._run_git = lambda _: '\x00'.join(lines) + '\x00' # pylint: disable=protected-access
self.assertEqual(
scm.unstaged_changes(),
{
......@@ -272,3 +271,8 @@ class GitTestWithMock(SCMTestBase):
'd/deleted.txt': 'D',
'd/untracked.txt': '?',
})
def test_unstaged_files_with_no_changes(self):
scm = self.make_scm()
scm._run_git = lambda _: '\x00' # pylint: disable=protected-access
self.assertEqual(scm.unstaged_changes(), {})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment