mirror of
https://github.com/balkian/pre-commit-hooks.git
synced 2024-11-21 15:12:27 +00:00
Fixed installation issues
This commit is contained in:
parent
2ac8641f06
commit
ec1d9b8be6
@ -1,4 +1,4 @@
|
|||||||
include requirements.txt
|
include requirements.txt
|
||||||
include test-requirements.txt
|
include test-requirements.txt
|
||||||
include README.md
|
include README.md
|
||||||
include balkian-pre-commit/VERSION
|
include balkian_pre_commit/VERSION
|
||||||
|
@ -18,12 +18,13 @@ pro-commit hooks for various projects
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import semver
|
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
|
|
||||||
__version_info__ = semver.parse_version_info(__version__)
|
try:
|
||||||
|
import semver
|
||||||
|
__version_info__ = semver.parse_version_info(__version__)
|
||||||
|
|
||||||
if __version_info__.prerelease:
|
if __version_info__.prerelease:
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
msg = 'WARNING: You are using a pre-release version of {} ({})'.format(
|
msg = 'WARNING: You are using a pre-release version of {} ({})'.format(
|
||||||
@ -33,3 +34,5 @@ if __version_info__.prerelease:
|
|||||||
else:
|
else:
|
||||||
import sys
|
import sys
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
except ImportError:
|
||||||
|
print('semver not installed, not doing version checking')
|
||||||
|
@ -8,12 +8,15 @@ 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()
|
||||||
if branch_name == 'master':
|
|
||||||
for fn in args.filenames:
|
for fn in args.filenames:
|
||||||
if os.path.basename(fn) == 'VERSION':
|
if os.path.basename(fn) == 'VERSION':
|
||||||
with open(fn) as f:
|
with open(fn) as f:
|
||||||
version = semver.parse_version_info(f.read())
|
currentcontent = f.read().strip()
|
||||||
if version.prerelease:
|
prevcontent = check_output(['git', 'show', 'HEAD:{}'.format(fn)]).strip().decode()
|
||||||
|
current = semver.parse_version_info(currentcontent)
|
||||||
|
print('Checking versions: {} -> {}'.format(prevcontent, currentcontent))
|
||||||
|
if (branch_name == 'master' and current.prerelease) or\
|
||||||
|
(semver.compare(currentcontent, prevcontent)<1):
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
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
|
||||||
files: VERSION$
|
files: "VERSION$"
|
Loading…
Reference in New Issue
Block a user