diff --git a/git_lint/git_lint.py b/git_lint/git_lint.py index 28532d7..d3b62bd 100644 --- a/git_lint/git_lint.py +++ b/git_lint/git_lint.py @@ -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 """ diff --git a/git_lint/option_handler.py b/git_lint/option_handler.py index 1086247..523ea9c 100644 --- a/git_lint/option_handler.py +++ b/git_lint/option_handler.py @@ -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, diff --git a/git_lint/options.py b/git_lint/options.py index 2428ef9..d18452b 100644 --- a/git_lint/options.py +++ b/git_lint/options.py @@ -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, diff --git a/git_lint/reporters.py b/git_lint/reporters.py index 59c8c74..60bc690 100644 --- a/git_lint/reporters.py +++ b/git_lint/reporters.py @@ -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))