Merge branch 'master' of github.com:elfsternberg/git-linter
* 'master' of github.com:elfsternberg/git-linter: 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!"
This commit is contained in:
commit
5cc8770ac3
|
@ -271,6 +271,11 @@ def get_filelist(options, extras):
|
|||
|
||||
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():
|
||||
""" 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
|
||||
|
||||
file_list_generator = working_list
|
||||
if 'revision' in options:
|
||||
file_list_generator = revision_list
|
||||
working_directory_trans = base_file_filter
|
||||
if 'all' in options:
|
||||
file_list_generator = all_list
|
||||
if 'staging' in options:
|
||||
|
@ -420,6 +428,9 @@ class Linters:
|
|||
|
||||
|
||||
def run_linters(options, config, extras=[]):
|
||||
if 'pr' in options:
|
||||
options.pop('pr')
|
||||
options['revision'] = 'HEAD^..HEAD'
|
||||
|
||||
def build_config_subset(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):
|
||||
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]
|
||||
(chosen_options, filenames) = getopt.getopt(commandline[1:],
|
||||
optstringsshort,
|
||||
|
|
|
@ -11,7 +11,11 @@ OPTIONS = [
|
|||
('b', 'base', False,
|
||||
_('Check all changed files in the repository, not just those in the current directory.'), []),
|
||||
('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,
|
||||
_('Short for -b -a: scan everything'), []),
|
||||
('w', 'workspace', False,
|
||||
|
|
|
@ -64,8 +64,7 @@ def print_report(results, unlintable_filenames, cant_lint_filenames,
|
|||
def print_help(options, name):
|
||||
print(_('Usage: {} [options] [filenames]').format(name))
|
||||
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):
|
||||
print(_('{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg').format(name, version))
|
||||
|
|
Loading…
Reference in New Issue