Add CheckChangeSvnEolStyle presubmit canned check.

TEST=unit tests
BUG=none

Review URL: http://codereview.chromium.org/119421

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18053 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 3410d917f3
commit b7d469083f

@ -119,6 +119,16 @@ def CheckLongLines(input_api, output_api, maxlen=80, source_file_filter=None):
return []
def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter):
"""Checks that the source files have svn:eol-style=LF."""
bad = filter(lambda f: f.scm == 'svn' and f.Property('svn:eol-style') != 'LF',
input_api.AffectedSourceFiles(source_file_filter))
if bad:
return [output_api.PresubmitError(
"Fix these files with svn svn:eol-style=LF", items=bad)]
return []
### Other checks
def CheckDoNotSubmit(input_api, output_api):

@ -6,7 +6,7 @@
"""Enables directory-specific presubmit checks to run at upload and/or commit.
"""
__version__ = '1.3.1'
__version__ = '1.3.2'
# TODO(joi) Add caching where appropriate/needed. The API is designed to allow
# caching (between all different invocations of presubmit scripts for a given
@ -360,6 +360,7 @@ class AffectedFile(object):
self._repository_root = repository_root
self._is_directory = None
self._properties = {}
self.scm = ''
def ServerPath(self):
"""Returns a path string that identifies the file in the SCM system.
@ -442,6 +443,7 @@ class SvnAffectedFile(AffectedFile):
AffectedFile.__init__(self, *args, **kwargs)
self._server_path = None
self._is_text_file = None
self.scm = 'svn'
def ServerPath(self):
if self._server_path is None:

@ -831,6 +831,7 @@ class AffectedFileUnittest(PresubmitTestsBase):
members = [
'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath',
'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath',
'scm',
]
# If this test fails, you should add the relevant test.
self.compareMembers(presubmit.AffectedFile('a', 'b'), members)
@ -936,7 +937,8 @@ class CannedChecksUnittest(PresubmitTestsBase):
members = [
'CheckChangeHasBugField', 'CheckChangeHasNoCR', 'CheckChangeHasNoTabs',
'CheckChangeHasQaField', 'CheckChangeHasTestedField',
'CheckChangeHasTestField', 'CheckDoNotSubmit',
'CheckChangeHasTestField', 'CheckChangeSvnEolStyle',
'CheckDoNotSubmit',
'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests',
]
@ -1049,6 +1051,38 @@ class CannedChecksUnittest(PresubmitTestsBase):
self.TestContent(check, '', 'blah blah blah',
presubmit.OutputApi.PresubmitPromptWarning)
def testCheckChangeSvnEolStyle(self):
input_api1 = self.MockInputApi()
files1 = [
presubmit.SvnAffectedFile('foo/bar.cc', 'A'),
presubmit.SvnAffectedFile('foo.cc', 'M'),
]
input_api1.AffectedSourceFiles(None).AndReturn(files1)
presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'),
'svn:eol-style').AndReturn('LF')
presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'),
'svn:eol-style').AndReturn('LF')
input_api2 = self.MockInputApi()
files2 = [
presubmit.SvnAffectedFile('foo/bar.cc', 'A'),
presubmit.SvnAffectedFile('foo.cc', 'M'),
]
input_api2.AffectedSourceFiles(None).AndReturn(files2)
presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'),
'svn:eol-style').AndReturn('native')
presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'),
'svn:eol-style').AndReturn('CRLF')
self.mox.ReplayAll()
results1 = presubmit_canned_checks.CheckChangeSvnEolStyle(
input_api1, presubmit.OutputApi, None)
self.assertEquals(results1, [])
results2 = presubmit_canned_checks.CheckChangeSvnEolStyle(
input_api2, presubmit.OutputApi, None)
self.assertEquals(len(results2), 1)
self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError)
def testCannedCheckTreeIsOpenOpen(self):
input_api = self.MockInputApi()
input_api.is_committing = True

Loading…
Cancel
Save