9

I have a git hook that is running whenever some one commits to their local repository.

Some people are committing from the terminal and some people are committing from SourceTree or SmartGit or some other 3rd party application.

SourceTree behaves differently when it comes to hooks. For example, errors are red by default, and user input doesn't seem to be supported so I need to change my python scripts depending on whether or not the user is committing from SourceTree or SmartGit etc.

Is there any way to do this within my script?

Ogen
  • 6,499
  • 7
  • 58
  • 124
  • Did you tried to compare enviroments variables using `printenv`? – Dario Jun 17 '16 at 13:23
  • @Dario No, I will try that and get back to you. – Ogen Jun 18 '16 at 04:03
  • @Dario I'm using `print os.environ`. Is that what you had in mind? What am I supposed to examine from this output exactly? – Ogen Jun 18 '16 at 05:31
  • Do you have access to the server where the repos live? It seems likely this whatever it is you want to accomplish could be done more easily and maintainably server-side rather than client-side. That said, what is it that these hooks do? – Jordan Bonitatis Jun 19 '16 at 23:47
  • @JordanBonitatis It's a pre-commit hook which is client side – Ogen Jun 19 '16 at 23:48

1 Answers1

5

I was able to solve the problem using this python code. It simply checks the environment variables for any occurrences of third party git clients. I don't know if it's the best solution or if it will work all the time - but it meets my needs for now.

is_terminal = True

for key in os.environ:
    if "SourceTree" in os.environ[key] or "SmartGit" in os.environ[key]:
        is_terminal = False
        break
Ogen
  • 6,499
  • 7
  • 58
  • 124