Beispiel #1
0
    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)


if __name__ == "__main__":
    args = parse_command_line()
    try:
        init_all_globals(
            OrderedDict([(args.ref_name, (args.old_rev, args.new_rev))]))
        create_scratch_dir()
        check_update(args.ref_name, args.old_rev, args.new_rev)
    except InvalidUpdate, E:
        # The update was rejected.  Print the rejection reason, and
        # exit with a nonzero status.
        warn(*E)
        sys.exit(1)
    finally:
        # Delete our scratch directory.
        if utils.scratch_dir is not None:
            rmtree(utils.scratch_dir)
Beispiel #2
0
        hook_input=pre_receive_data
    )
    if result is not None:
        hook_exe, p, out = result
        if p.returncode != 0:
            raise InvalidUpdate(
                "Update rejected by this repository's hooks.pre-receive-hook" " script",
                "({}):".format(hook_exe),
                *out.splitlines()
            )
        else:
            sys.stdout.write(out)


if __name__ == "__main__":
    stdin = sys.stdin.read()
    refs_data = OrderedDict()
    for line in stdin.splitlines():
        old_rev, new_rev, ref_name = line.strip().split()
        refs_data[ref_name] = (old_rev, new_rev)

    try:
        init_all_globals(refs_data)
        pre_receive(refs_data)
        maybe_pre_receive_hook(stdin)
    except InvalidUpdate as e:
        # The update was rejected.  Print the rejection reason, and
        # exit with a nonzero status.
        warn(*e.args)
        sys.exit(1)