Skip to content
Snippets Groups Projects
Commit 9039e0d2 authored by Mathieu Courtois's avatar Mathieu Courtois
Browse files

[#34305] add check-prepush option in ~/.gitconfig

parent da5f6b5f
No related branches found
No related tags found
No related merge requests found
......@@ -95,6 +95,7 @@ class AsterCfgSection(object): # pragma pylint: disable=R0902
"check_commit",
"check_submit",
"check_precommit",
"check_prepush",
"docaster_uri",
"docaster_cafile",
"clang_format",
......@@ -132,6 +133,7 @@ class AsterCfgSection(object): # pragma pylint: disable=R0902
self.check_commit = _read("check-commit", "warn")
self.check_submit = _read("check-submit", "warn")
self.check_precommit = _read("check-precommit", "undef")
self.check_prepush = _read("check-prepush", "undef")
# installation root of devtools
self.aslint_root = get_absolute_dirname(__file__)
self.devtools_root = get_absolute_dirname(osp.join(self.aslint_root, os.pardir))
......
......@@ -54,28 +54,9 @@ def aslint(repopath, paths=(), amend=False):
revs = ("HEAD~1",) if amend else None
# logger.title("running aslint...")
choice = ASCFG.get("check.precommit")
if choice == "no":
logger.warn(
"pre-commit checkings skipped because of 'check-precommit'"
" value in your ~/.gitconfig file"
)
if _check_preference("pre-commit") == OK:
return OK
elif choice == "undef":
logger.info(
"pre-commit: If you don't plan to submit your work "
"you can disable these checkings by adding "
"'check-precommit = no' in the [aster] section in "
"your ~/.gitconfig file."
)
logger.info(
"pre-commit: To hide this message you can set the value " "'check-precommit = yes'."
)
elif choice != "yes":
logger.warn(
"unknown choice {0!r} for 'check.precommit'"
" (see ~/.gitconfig) must be 'yes' or 'no'.".format(choice)
)
dchg = get_changed_files(repopath, revs=revs, files=paths)
changes = filter_dict(dchg)
report = Report()
......@@ -141,6 +122,8 @@ def run_ctest_minimal(repopath):
checkcontext.reponame = get_repo_name(repopath)
if checkcontext.reponame != "src":
return OK
if _check_preference("pre-push") == OK:
return OK
logger.warning("Run a minimal list of testcases (for about 30 seconds).")
......@@ -166,3 +149,39 @@ def run_ctest_minimal(repopath):
if call(cmd):
return NOOK
return OK
def _check_preference(hook):
"""Check if a checking is enabled or disabled in '~/.gitconfig'.
Arguments:
hook (str): Hook name.
Returns:
bool: OK if the hook should be skipped, NOOK otherwise.
"""
from aslint.config import ASCFG
assert hook in ("pre-commit", "pre-push"), hook
option = f"check.{hook.replace('-', '')}"
gitopt = option.replace(".", "-")
choice = ASCFG.get(option)
if choice == "no":
logger.warn(
"%s checkings skipped because of '%s'" " value in your ~/.gitconfig file", hook, gitopt
)
return OK
elif choice in (None, "undef"):
logger.info(
"%s: If you want to disable these checkings, just add "
"'%s = no' in the [aster] section in your ~/.gitconfig file.",
hook,
gitopt,
)
logger.info("%s: To hide this message you can set the value '%s = yes'.", hook, gitopt)
elif choice != "yes":
logger.warn(
"unknown choice %r for '%s' (see ~/.gitconfig) must be 'yes' or 'no'.", choice, option
)
return NOOK
......@@ -14,7 +14,7 @@ from aslint.config import ASCFG
from aslint.baseutils import force_list
from aslint.logger import logger
from ..ext_utils import RE_ISSUE, get_issues_from_descr, is_admin
from ..ext_utils import RE_ISSUE, get_issues_from_descr
OK, NOOK = 0, 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment