aboutsummaryrefslogtreecommitdiff
path: root/rh/config.py
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2016-10-16 21:56:58 -0700
committerLuis Hector Chavez <lhchavez@google.com>2016-10-17 21:51:54 -0700
commit5c4c293174bb61f0f39035a71acd9084abfa743d (patch)
treeb4ae15a61eb8f8309bc6022edc4d36bab7e0e5c7 /rh/config.py
parent25abf4bf354f937d46c125776f33478f0b4b71b9 (diff)
downloadrepohooks-5c4c293174bb61f0f39035a71acd9084abfa743d.tar.gz
Add an option to ignore merged commits
When uploading merge-commits, git log will list commits that are not necessarily uploaded (since they have usually been already committed to another branch). In order to avoid developers skipping verification on these cases, this change adds an option to the config file that will add --first-parent to the git log invocation, so pre-upload checks are only performed on the commits that the developer intended. Bug: 31926893 Test: repo upload Change-Id: I76959906ed05b5cd09c4263fb54997b55dd6cfc3
Diffstat (limited to 'rh/config.py')
-rw-r--r--rh/config.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/rh/config.py b/rh/config.py
index 05d7cb2..6a149d7 100644
--- a/rh/config.py
+++ b/rh/config.py
@@ -97,6 +97,10 @@ class PreSubmitConfig(object):
BUILTIN_HOOKS_SECTION = 'Builtin Hooks'
BUILTIN_HOOKS_OPTIONS_SECTION = 'Builtin Hooks Options'
TOOL_PATHS_SECTION = 'Tool Paths'
+ OPTIONS_SECTION = 'Options'
+
+ OPTION_IGNORE_MERGED_COMMITS = 'ignore_merged_commits'
+ VALID_OPTIONS = (OPTION_IGNORE_MERGED_COMMITS,)
def __init__(self, paths=('',), global_paths=()):
"""Initialize.
@@ -168,6 +172,14 @@ class PreSubmitConfig(object):
yield (hook, functools.partial(rh.hooks.BUILTIN_HOOKS[hook],
options=options))
+ @property
+ def ignore_merged_commits(self):
+ """Whether to skip hooks for merged commits."""
+ return rh.shell.boolean_shell_value(
+ self.config.get(self.OPTIONS_SECTION,
+ self.OPTION_IGNORE_MERGED_COMMITS, None),
+ False)
+
def _validate(self):
"""Run consistency checks on the config settings."""
config = self.config
@@ -178,6 +190,7 @@ class PreSubmitConfig(object):
self.BUILTIN_HOOKS_SECTION,
self.BUILTIN_HOOKS_OPTIONS_SECTION,
self.TOOL_PATHS_SECTION,
+ self.OPTIONS_SECTION,
))
bad_sections = set(config.sections()) - valid_sections
if bad_sections:
@@ -233,3 +246,12 @@ class PreSubmitConfig(object):
if bad_tools:
raise ValidationError('%s: unknown tools: %s' %
(self.paths, bad_tools))
+
+ # Reject unknown options.
+ valid_options = set(self.VALID_OPTIONS)
+ if config.has_section(self.OPTIONS_SECTION):
+ options = set(config.options(self.OPTIONS_SECTION))
+ bad_options = options - valid_options
+ if bad_options:
+ raise ValidationError('%s: unknown options: %s' %
+ (self.paths, bad_options))