for key in os.environ:
    if 'SourceTree' in os.environ[key] or 'SmartGit' in os.environ[key]:
        is_terminal = False
break
How to know if a git hook is being called from not within the terminal/command line