| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import argparse |
| 22 |
|
| 23 |
from git_repository import parse_git_revisions |
| 24 |
|
| 25 |
def nonzero_uint(value): |
| 26 |
ivalue = int(value) |
| 27 |
if ivalue <= 0: |
| 28 |
raise argparse.ArgumentTypeError('%s is not a non-zero positive integer' % value) |
| 29 |
return ivalue |
| 30 |
|
| 31 |
parser = argparse.ArgumentParser(description='Check git ChangeLog format ' |
| 32 |
'of a commit') |
| 33 |
parser.add_argument('revisions', default='HEAD', nargs='?', |
| 34 |
help='Git revisions (e.g. hash~5..hash or just hash) - ' |
| 35 |
'if not specified: HEAD') |
| 36 |
parser.add_argument('-g', '--git-path', default='.', |
| 37 |
help='Path to git repository') |
| 38 |
parser.add_argument('-p', '--print-changelog', action='store_true', |
| 39 |
help='Print final changelog entires') |
| 40 |
parser.add_argument('-v', '--verbose', action='store_true', |
| 41 |
help='Print verbose information') |
| 42 |
parser.add_argument('-n', '--num-commits', type=nonzero_uint, default=1, |
| 43 |
help='Number of commits to check (i.e. shorthand for ' |
| 44 |
'hash~N..hash)') |
| 45 |
args = parser.parse_args() |
| 46 |
|
| 47 |
if args.num_commits > 1: |
| 48 |
if '..' in args.revisions: |
| 49 |
print('ERR: --num-commits and range of revisions are mutually exclusive') |
| 50 |
exit(1) |
| 51 |
args.revisions = '{0}~{1}..{0}'.format(args.revisions, args.num_commits) |
| 52 |
|
| 53 |
retval = 0 |
| 54 |
for git_commit in parse_git_revisions(args.git_path, args.revisions): |
| 55 |
res = 'OK' if git_commit.success else 'FAILED' |
| 56 |
print('Checking %s: %s' % (git_commit.original_info.hexsha, res)) |
| 57 |
if git_commit.success: |
| 58 |
if args.print_changelog: |
| 59 |
git_commit.print_output() |
| 60 |
if args.verbose and git_commit.warnings: |
| 61 |
for warning in git_commit.warnings: |
| 62 |
print('WARN: %s' % warning) |
| 63 |
else: |
| 64 |
if args.verbose and git_commit.warnings: |
| 65 |
for warning in git_commit.warnings: |
| 66 |
print('WARN: %s' % warning) |
| 67 |
for error in git_commit.errors: |
| 68 |
print('ERR: %s' % error) |
| 69 |
if args.verbose and error.details: |
| 70 |
print(error.details) |
| 71 |
retval = 1 |
| 72 |
|
| 73 |
exit(retval) |