Merge "Do not warn about uncommited files if sha is set explicitly."
am: f32000dda2
Change-Id: I455aa99a655a903c2752bd29e759b8bb3d499306
This commit is contained in:
@@ -73,11 +73,12 @@ def RunCheckstyleOnACommit(commit, config_xml=CHECKSTYLE_STYLE):
|
||||
Returns:
|
||||
A tuple of errors and warnings.
|
||||
"""
|
||||
if not commit:
|
||||
explicit_commit = commit is not None
|
||||
if not explicit_commit:
|
||||
_WarnIfUntrackedFiles()
|
||||
commit = git.last_commit()
|
||||
print 'Running Checkstyle on %s commit' % commit
|
||||
commit_modified_files = _GetModifiedFiles(commit)
|
||||
commit_modified_files = _GetModifiedFiles(commit, explicit_commit)
|
||||
if not commit_modified_files.keys():
|
||||
print 'No Java files to check'
|
||||
return [], []
|
||||
@@ -216,10 +217,10 @@ def _ShouldSkip(commit_check, modified_lines, line, rule, test_class=False):
|
||||
return line not in modified_lines and rule not in FORCED_RULES
|
||||
|
||||
|
||||
def _GetModifiedFiles(commit, out=sys.stdout):
|
||||
def _GetModifiedFiles(commit, explicit_commit=False, out=sys.stdout):
|
||||
root = git.repository_root()
|
||||
pending_files = git.modified_files(root, True)
|
||||
if pending_files:
|
||||
if pending_files and not explicit_commit:
|
||||
out.write(ERROR_UNCOMMITTED)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@@ -122,6 +122,14 @@ class TestCheckstyle(unittest.TestCase):
|
||||
checkstyle._GetModifiedFiles(mock_last_commit(), out=out)
|
||||
self.assertEqual(out.getvalue(), checkstyle.ERROR_UNCOMMITTED)
|
||||
|
||||
def test_GetModifiedFilesUncommittedExplicitCommit(self):
|
||||
checkstyle.git.modified_files = mock_modified_files_uncommitted
|
||||
out = StringIO()
|
||||
files = checkstyle._GetModifiedFiles(mock_last_commit(), True, out=out)
|
||||
output = out.getvalue()
|
||||
self.assertEqual(output, '')
|
||||
self.assertEqual(files, {TEST_FILE1: FILE_MODIFIED, TEST_FILE2: FILE_ADDED})
|
||||
|
||||
def test_GetModifiedFilesNonJava(self):
|
||||
checkstyle.git.modified_files = mock_modified_files_non_java
|
||||
out = StringIO()
|
||||
|
||||
Reference in New Issue
Block a user