def check_update(ref_name, old_rev, new_rev): """General handler of the given update. Raises InvalidUpdate if the update cannot be accepted (usually because one of the commits fails a style-check, for instance). PARAMETERS ref_name: The name of the reference being update (Eg: refs/heads/master). old_rev: The commit SHA1 of the reference before the update. new_rev: The new commit SHA1 that the reference will point to if the update is accepted. REMARKS This function assumes that scratch_dir has been initialized. """ debug('check_update(ref_name=%s, old_rev=%s, new_rev=%s)' % (ref_name, old_rev, new_rev), level=2) update_cls = new_update(ref_name, old_rev, new_rev, git_show_ref(), submitter_email=None) if update_cls is None: raise InvalidUpdate( "This type of update (%s,%s) is currently unsupported." % (ref_name, get_object_type(new_rev))) with FileLock('git-hooks::update.token'): update_cls.validate()
def check_update(ref_name, old_rev, new_rev): """General handler of the given update. Raises InvalidUpdate if the update cannot be accepted (usually because one of the commits fails a style-check, for instance). PARAMETERS ref_name: The name of the reference being update (Eg: refs/heads/master). old_rev: The commit SHA1 of the reference before the update. new_rev: The new commit SHA1 that the reference will point to if the update is accepted. REMARKS This function assumes that scratch_dir has been initialized. """ debug( "check_update(ref_name=%s, old_rev=%s, new_rev=%s)" % (ref_name, old_rev, new_rev), level=2, ) check_minimum_system_requirements() # Do nothing if the reference is in the hooks.ignore-refs list. ignore_refs_match = utils.search_config_option_list("hooks.ignore-refs", ref_name) if ignore_refs_match is not None: debug(f"{ref_name} ignored due to hooks.ignore-refs" f" ({ignore_refs_match})") return update_cls = new_update( ref_name, old_rev, new_rev, git_show_ref(), submitter_email=None ) if update_cls is None: # Report an error. We could look more precisely into what # might be the reason behind this error, and print more precise # diagnostics, but it does not seem like this would be worth # the effort: It requires some pretty far-fetched scenarios # for this to trigger; so, this should happen only very seldomly, # and when a user does something very unusual. raise InvalidUpdate( "This type of update (%s,%s) is not valid." % (ref_name, get_object_type(new_rev)) ) with FileLock("git-hooks::update.token"): update_cls.validate() maybe_update_hook(ref_name, old_rev, new_rev)
def post_receive(updated_refs, submitter_email): """Implement the post-receive hook for all given updated_refs. PARAMETERS updated_refs: An OrderedDict, indexed by the name of the ref being updated, and containing 2-elements tuple. This tuple contains the previous revision, and the new revision of the reference. submitter_email: Same as AbstractUpdate.__init__. """ refs = git_show_ref() for ref_name in updated_refs.keys(): (old_rev, new_rev) = updated_refs[ref_name] post_receive_one(ref_name, old_rev, new_rev, refs, submitter_email) # Flush the email queue. Since this involves creating a daemon, # only do so if there is at least one email to be sent. email_queue = EmailQueue() if email_queue.queue: run_in_daemon(email_queue.flush)