def run(self, old_sha1, new_sha1, _ref):
        sha1s = LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1)

        for sha1 in sha1s:
            commit_message = LibHookKit.run_git_command(
                ['log', '-1', '--format=%s%n%b', sha1])

            # 1) Check the staged commits if they have a duplicate commit message
            other_sha1s = [e for e in sha1s if not e == sha1]
            found = self.scan_sha1_list_for_message(other_sha1s,
                                                    commit_message)

            if found:
                return self.duplicate_found(sha1, found)

# 2) Check existing commits if they have a duplicate commit message
            commit_message = commit_message.rstrip()

            # Needed for multi-line comments
            grep_prefix = ''

            if '\n' in commit_message:
                grep_prefix = '/'

            # This is to fix a problem where * was causing problems with
            # the shell git command. I tried re.escape, but that caused the
            # "push inbetween" test to fail. I don't have time to investigate
            # further, so I'll stick with this hotfix for now.
            commit_message = commit_message.replace('*', '\*')

            match_sha1s = LibHookKit.run_git_command([
                'log', '--format=%H',
                '--grep=' + grep_prefix + '^%s$' % commit_message
            ])

            match_sha1s = filter(None, match_sha1s.split('\n'))
            try:
                match_sha1s.remove(sha1)
            except:
                pass

# sha1s may contain partial matches - refine it down to exact matches
            for _sha1 in match_sha1s:
                old_message = LibHookKit.get_commit_message(_sha1).rstrip()
                if old_message == commit_message:
                    return self.duplicate_found(sha1, _sha1)

        return True
    def run(self, old_sha1, new_sha1, _ref):
        sha1s = LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1)

        for sha1 in sha1s:
            commit_message = LibHookKit.run_git_command(['log', '-1',
                                                         '--format=%s%n%b',
                                                         sha1])

# 1) Check the staged commits if they have a duplicate commit message
            other_sha1s = [e for e in sha1s if not e == sha1]
            found = self.scan_sha1_list_for_message(other_sha1s,
                                                    commit_message)

            if found:
                return self.duplicate_found(sha1, found)

# 2) Check existing commits if they have a duplicate commit message
            commit_message = commit_message.rstrip()

# Needed for multi-line comments
            grep_prefix = ''

            if '\n' in commit_message:
                grep_prefix = '/'

            # This is to fix a problem where * was causing problems with
            # the shell git command. I tried re.escape, but that caused the
            # "push inbetween" test to fail. I don't have time to investigate
            # further, so I'll stick with this hotfix for now.
            commit_message = commit_message.replace('*', '\*')

            match_sha1s = LibHookKit.run_git_command(['log', '--format=%H',
                                                      '--grep=' + grep_prefix +
                                                      '^%s$' % commit_message])

            match_sha1s = filter(None, match_sha1s.split('\n'))
            try:
                match_sha1s.remove(sha1)
            except:
                pass

# sha1s may contain partial matches - refine it down to exact matches
            for _sha1 in match_sha1s:
                old_message = LibHookKit.get_commit_message(_sha1).rstrip()
                if old_message == commit_message:
                    return self.duplicate_found(sha1, _sha1)

        return True
Example #3
0
def trigger_scripts(old_sha1, new_sha1, ref):
    # We only care about branches
    # TBD: Add hook support for things other than branches
    if not ref.startswith('refs/heads'):
        return

# Delete branch
    if new_sha1 == '0000000000000000000000000000000000000000':
        return

# New branch
    if old_sha1 == '0000000000000000000000000000000000000000':
        # FIXME: This feels really wrong, but I'm not sure what I should do instead.
        #        I'll do this for now, until I can think of something better.
        #        (or it starts causing problems)
        old_sha1 = LibHookKit.run_git_command(
            ['merge-base', new_sha1, 'master'])
        old_sha1 = old_sha1.rstrip()

    failed = False

    script_names = []
    for script in scripts_to_run_each_commit:
        script_names.append(script.label)

    for script in scripts_to_run_on_last_commit:
        script_names.append(script.label)

    script_names = ', '.join(script_names)

    print '* Checks: ' + script_names + '\n'
    sys.stdout.flush()

    for sha1 in LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1):
        for script in scripts_to_run_each_commit:
            if not script.run(sha1):
                print '\t!!! Fail: ' + sha1 + ' - ' + script.error_message
                sys.stdout.flush()
                failed = True


#should pass in a dict of args
#FIXME: This really needs tests!
    for script in scripts_to_run_on_last_commit:
        if not script.run(old_sha1, new_sha1, ref):
            print '!!! Fail: ' + script.error_message
            sys.stdout.flush()
            failed = True

    if failed:
        exit_with_error_message('\n!!! PUSH ABORTED !!!\n')
Example #4
0
def trigger_scripts(old_sha1, new_sha1, ref):
    # We only care about branches
    # TBD: Add hook support for things other than branches
    if not ref.startswith("refs/heads"):
        return

    # Delete branch
    if new_sha1 == "0000000000000000000000000000000000000000":
        return

    # New branch
    if old_sha1 == "0000000000000000000000000000000000000000":
        # FIXME: This feels really wrong, but I'm not sure what I should do instead.
        #        I'll do this for now, until I can think of something better.
        #        (or it starts causing problems)
        old_sha1 = LibHookKit.run_git_command(["merge-base", new_sha1, "master"])
        old_sha1 = old_sha1.rstrip()

    failed = False

    script_names = []
    for script in scripts_to_run_each_commit:
        script_names.append(script.label)

    for script in scripts_to_run_on_last_commit:
        script_names.append(script.label)

    script_names = ", ".join(script_names)

    print "* Checks: " + script_names + "\n"
    sys.stdout.flush()

    for sha1 in LibHookKit.get_sha1_list_between_commits(old_sha1, new_sha1):
        for script in scripts_to_run_each_commit:
            if not script.run(sha1):
                print "\t!!! Fail: " + sha1 + " - " + script.error_message
                sys.stdout.flush()
                failed = True

    # should pass in a dict of args
    # FIXME: This really needs tests!
    for script in scripts_to_run_on_last_commit:
        if not script.run(old_sha1, new_sha1, ref):
            print "!!! Fail: " + script.error_message
            sys.stdout.flush()
            failed = True

    if failed:
        exit_with_error_message("\n!!! PUSH ABORTED !!!\n")