Added a command, '--revision', the lets you test files that were changed
and committed already. This is mostly a helpful addition to "Oh, I didn't lint those!" Also, added the basic '--pr', which gives you the list of files changed in the very last commit, so you don't have to specify which revision you mean.
This commit is contained in:
parent
1a942e6b1c
commit
a8451c83bf
|
@ -271,6 +271,11 @@ def get_filelist(options, extras):
|
||||||
|
|
||||||
return check_for_conflicts(parse_stream([], stream))
|
return check_for_conflicts(parse_stream([], stream))
|
||||||
|
|
||||||
|
def revision_list():
|
||||||
|
cmd = ['diff', '--name-only', '-z', options.get('revision')]
|
||||||
|
return [entry for entry in get_git_response(cmd).split(u'\x00')
|
||||||
|
if len(entry) > 0]
|
||||||
|
|
||||||
def staging_list():
|
def staging_list():
|
||||||
""" Return the list of files added or modified to the stage """
|
""" Return the list of files added or modified to the stage """
|
||||||
|
|
||||||
|
@ -302,6 +307,9 @@ def get_filelist(options, extras):
|
||||||
working_directory_trans = base_file_filter
|
working_directory_trans = base_file_filter
|
||||||
|
|
||||||
file_list_generator = working_list
|
file_list_generator = working_list
|
||||||
|
if 'revision' in options:
|
||||||
|
file_list_generator = revision_list
|
||||||
|
working_directory_trans = base_file_filter
|
||||||
if 'all' in options:
|
if 'all' in options:
|
||||||
file_list_generator = all_list
|
file_list_generator = all_list
|
||||||
if 'staging' in options:
|
if 'staging' in options:
|
||||||
|
@ -420,6 +428,9 @@ class Linters:
|
||||||
|
|
||||||
|
|
||||||
def run_linters(options, config, extras=[]):
|
def run_linters(options, config, extras=[]):
|
||||||
|
if 'pr' in options:
|
||||||
|
options.pop('pr')
|
||||||
|
options['revision'] = 'HEAD^..HEAD'
|
||||||
|
|
||||||
def build_config_subset(keys):
|
def build_config_subset(keys):
|
||||||
""" Returns a subset of the configuration, with only those linters mentioned in keys """
|
""" Returns a subset of the configuration, with only those linters mentioned in keys """
|
||||||
|
|
|
@ -71,7 +71,7 @@ def cleanup_options(options, commandline):
|
||||||
def longoptstogo(i):
|
def longoptstogo(i):
|
||||||
return i[1] + ((i[2] and '=') or '')
|
return i[1] + ((i[2] and '=') or '')
|
||||||
|
|
||||||
optstringsshort = ''.join([shortoptstogo(opt) for opt in options])
|
optstringsshort = ''.join([shortoptstogo(opt) for opt in options if opt[0]])
|
||||||
optstringslong = [longoptstogo(opt) for opt in options]
|
optstringslong = [longoptstogo(opt) for opt in options]
|
||||||
(chosen_options, filenames) = getopt.getopt(commandline[1:],
|
(chosen_options, filenames) = getopt.getopt(commandline[1:],
|
||||||
optstringsshort,
|
optstringsshort,
|
||||||
|
|
|
@ -11,7 +11,11 @@ OPTIONS = [
|
||||||
('b', 'base', False,
|
('b', 'base', False,
|
||||||
_('Check all changed files in the repository, not just those in the current directory.'), []),
|
_('Check all changed files in the repository, not just those in the current directory.'), []),
|
||||||
('a', 'all', False,
|
('a', 'all', False,
|
||||||
_('Scan all files in the repository, not just those that have changed.'), []),
|
_('Scan all files in the repository, not just those that have changed.'), ['revision']),
|
||||||
|
('r', 'revision', True,
|
||||||
|
_('Scan all files changed between revisions'), []),
|
||||||
|
(None, 'pr', False,
|
||||||
|
_('Scan all files changed between head and previous check-in'), ['revision']),
|
||||||
('e', 'every', False,
|
('e', 'every', False,
|
||||||
_('Short for -b -a: scan everything'), []),
|
_('Short for -b -a: scan everything'), []),
|
||||||
('w', 'workspace', False,
|
('w', 'workspace', False,
|
||||||
|
|
|
@ -64,8 +64,7 @@ def print_report(results, unlintable_filenames, cant_lint_filenames,
|
||||||
def print_help(options, name):
|
def print_help(options, name):
|
||||||
print(_('Usage: {} [options] [filenames]').format(name))
|
print(_('Usage: {} [options] [filenames]').format(name))
|
||||||
for item in options:
|
for item in options:
|
||||||
print(' -{:<1} --{:<12} {}'.format(item[0], item[1], item[3]))
|
print(' {:<2} --{:<12} {}'.format((item[0] and ('-' + item[0])) or '', item[1], item[3]))
|
||||||
|
|
||||||
|
|
||||||
def print_version(name, version):
|
def print_version(name, version):
|
||||||
print(_('{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg').format(name, version))
|
print(_('{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg').format(name, version))
|
||||||
|
|
Loading…
Reference in New Issue