Merge "Do not warn about uncommited files if sha is set explicitly." am: f32000dda2
am: bf406fd592
Change-Id: I73ad7e039cc47713a12e7f70356af1bf872d22b5
This commit is contained in:
@@ -73,11 +73,12 @@ def RunCheckstyleOnACommit(commit, config_xml=CHECKSTYLE_STYLE):
|
|||||||
Returns:
|
Returns:
|
||||||
A tuple of errors and warnings.
|
A tuple of errors and warnings.
|
||||||
"""
|
"""
|
||||||
if not commit:
|
explicit_commit = commit is not None
|
||||||
|
if not explicit_commit:
|
||||||
_WarnIfUntrackedFiles()
|
_WarnIfUntrackedFiles()
|
||||||
commit = git.last_commit()
|
commit = git.last_commit()
|
||||||
print 'Running Checkstyle on %s commit' % 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():
|
if not commit_modified_files.keys():
|
||||||
print 'No Java files to check'
|
print 'No Java files to check'
|
||||||
return [], []
|
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
|
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()
|
root = git.repository_root()
|
||||||
pending_files = git.modified_files(root, True)
|
pending_files = git.modified_files(root, True)
|
||||||
if pending_files:
|
if pending_files and not explicit_commit:
|
||||||
out.write(ERROR_UNCOMMITTED)
|
out.write(ERROR_UNCOMMITTED)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,14 @@ class TestCheckstyle(unittest.TestCase):
|
|||||||
checkstyle._GetModifiedFiles(mock_last_commit(), out=out)
|
checkstyle._GetModifiedFiles(mock_last_commit(), out=out)
|
||||||
self.assertEqual(out.getvalue(), checkstyle.ERROR_UNCOMMITTED)
|
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):
|
def test_GetModifiedFilesNonJava(self):
|
||||||
checkstyle.git.modified_files = mock_modified_files_non_java
|
checkstyle.git.modified_files = mock_modified_files_non_java
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
|
|||||||
Reference in New Issue
Block a user