Skip to content

Make the pre-commit hook report non-temporary path names #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cleanup()
trap cleanup EXIT

tmpStaging=$(mktemp -d)
touch $tmpStaging/.git

# Copy contents of staged version of files to temporary staging area
# because we only want the staged version that will be commited and not
Expand Down
15 changes: 11 additions & 4 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,10 @@ def Error(filename, linenum, category, confidence, message):
sys.stderr.write('%s:%s: warning: %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence))
else:
fileinfo = FileInfo(filename)
path_from_root = fileinfo.RepositoryName()
sys.stderr.write('%s:%s: %s [%s] [%d]\n' % (
filename, linenum, message, category, confidence))
path_from_root, linenum, message, category, confidence))


# Matches standard C++ escape sequences per 2.13.2.3 of the C++ standard.
Expand Down Expand Up @@ -6469,13 +6471,18 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
return

# Note, if no dot is found, this will give the entire filename as the ext.
file_extension = filename[filename.rfind('.') + 1:]
fileinfo = FileInfo(filename)
path_from_root = fileinfo.RepositoryName()
file_extension = fileinfo.Extension()
if not file_extension:
file_extension = filename[filename.rfind('.')]
file_extension = file_extension[1:]

# When reading from stdin, the extension is unknown, so no cpplint tests
# should rely on the extension.
if filename != '-' and file_extension not in _valid_extensions:
sys.stderr.write('Ignoring %s; not a valid file name '
'(%s)\n' % (filename, ', '.join(_valid_extensions)))
'(%s)\n' % (path_from_root, ', '.join(_valid_extensions)))
else:
ProcessFileData(filename, file_extension, lines, Error,
extra_check_functions)
Expand All @@ -6498,7 +6505,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
Error(filename, linenum, 'whitespace/newline', 1,
'Unexpected \\r (^M) found; better to use only \\n')

sys.stdout.write('Done processing %s\n' % filename)
sys.stdout.write('Done processing %s\n' % path_from_root)
_RestoreFilters()


Expand Down