The logic for re.match() , sys.exit(1) does not make sense, plus why can't i use return True if the re.match regex matches The whole idea behind this ,is the user enters :
1. hg commit -m "NO-TIK" and is able to submit the changeset
2. hg commit -m "NO-REVIEW" also does the same as # 1
3. hg commit -m "JIRA-123 blah blah" is also submitted as long as there is a valid issue "JIRA-123" otherwise the commit is reverted with the message "%s does not exist"%ticket
4. hg commit -m "plain english without ANY of the above, reverts the changes , so the above 3 rules MUST be observed.


#!/usr/bin/env python

import re, os, sys, jira, subprocess
from optparse import OptionParser
import warnings
from collections import namedtuple


def verify_commit_text(tags):
    for line in tags:
        if re.match(r'[^\NO-TIK]',line):
            sys.exit(1)
        elif re.match(r'[^\NO-REVIEW]', line):
            sys.exit(1)
        elif re.match(r'[a-zA-Z]+-\d+', line):
            # Validate the JIRA ID
            m = re.search("([a-zA-Z]+-\d+)",line)
            m_args = m.group(1)
            m_args = [m_args]
            if CheckForJiraIssueRecord(m_args):
                sys.exit(1)
            else:
                print >> sys.stderr, ("%s does not exist"%m_args)
        else:
            sys.exit(0)

def CheckForJiraIssueRecord(my_args):
    # turn off stdout
    #sys.stdout = open(os.devnull)
    #sys.stderr = open(os.devnull)
    com = jira.Commands()
    logger = jira.setupLogging()
    jira_env = {'home':os.environ['HOME']}
    command_name = "cat"
    server = "http://jira.server.com:8080/rpc/soap/jirasoapservice-v2?wsdl"
    options = namedtuple('Options', 'user password')('user','password')
    jira.soap = jira.Client(server)
    jira.start_login(options, jira_env, command_name, com, logger)
    issue = com.run(command_name, logger, jira_env, my_args)
    if issue:
        return True

if __name__ == '__main__':
    commit_text_verified = verify_commit_text(os.popen('hg tip --template "{desc}"'))
    if commit_text_verified:
        sys.exit(0)
    else:
        print >> sys.stderr, ('[obey the rules!]')
        sys.exit(1)
You seem confused about sys.exit is doing. It exits your program. You function verify_commit_text never exits. Your code after calling verify_commit_text is never executed. The program always hits a sys.exit in verify_commit_text and terminates. The first thing you need to do is eliminate all the sys.exit() except in the __main__ section. You should really only have sys.exit in there.