1
0
mirror of https://github.com/balkian/pre-commit-hooks.git synced 2024-11-14 12:12:28 +00:00

Make branchversion run always

This should prevent commits without VERSION bump
This commit is contained in:
J. Fernando Sánchez 2017-02-02 04:30:31 +01:00
parent ec1d9b8be6
commit b7dc27a616
2 changed files with 13 additions and 10 deletions

View File

@ -8,17 +8,19 @@ def main(argv=None):
parser.add_argument('filenames', nargs='*') parser.add_argument('filenames', nargs='*')
args = parser.parse_args(argv) args = parser.parse_args(argv)
branch_name = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode() branch_name = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
error = 1
for fn in args.filenames: for fn in args.filenames:
if os.path.basename(fn) == 'VERSION': with open(fn) as f:
with open(fn) as f: currentcontent = f.read().strip()
currentcontent = f.read().strip() prevcontent = check_output(['git', 'show', 'HEAD:{}'.format(fn)]).strip().decode()
prevcontent = check_output(['git', 'show', 'HEAD:{}'.format(fn)]).strip().decode() current = semver.parse_version_info(currentcontent)
current = semver.parse_version_info(currentcontent) print('Checking versions: {} -> {}'.format(prevcontent, currentcontent))
print('Checking versions: {} -> {}'.format(prevcontent, currentcontent)) if (branch_name == 'master' and current.prerelease) or\
if (branch_name == 'master' and current.prerelease) or\ (semver.compare(currentcontent, prevcontent)<1):
(semver.compare(currentcontent, prevcontent)<1): return 1
return 1 else:
return 0 error = 0
return error
if __name__ == '__main__': if __name__ == '__main__':
exit(main()) exit(main())

View File

@ -3,4 +3,5 @@
description: This hook avoids commiting a pre-release to a master branch. description: This hook avoids commiting a pre-release to a master branch.
entry: branchversion entry: branchversion
language: python language: python
always_run: True
files: "VERSION$" files: "VERSION$"