263d262
< gitdir = main.root.Dir(".git")
371,373c370,379
< # Try to wire up git to the style hooks
< git_pre_commit_hook = gitdir.File("hooks/pre-commit")
< if not ignore_style and gitdir.exists() and not git_pre_commit_hook.exists():
---
> def install_git_style_hooks():
> try:
> gitdir = Dir(readCommand(
> ["git", "rev-parse", "--git-dir"]).strip("\n"))
> except Exception, e:
> print "Warning: Failed to find git repo directory: %s" % e
> return
>
> git_hooks = gitdir.Dir("hooks")
> git_pre_commit_hook = git_hooks.File("pre-commit")
375a382,384
> if git_pre_commit_hook.exists():
> return
>
383,384c392,397
< try:
< rel_style_script = os.path.relpath(
---
> if not git_hooks.exists():
> mkdir(git_hooks.get_abspath())
>
> # Use a relative symlink if the hooks live in the source directory
> if git_pre_commit_hook.is_under(main.root):
> script_path = os.path.relpath(
387c400,404
< os.symlink(rel_style_script, git_pre_commit_hook.get_abspath())
---
> else:
> script_path = git_style_script.get_abspath()
>
> try:
> os.symlink(script_path, git_pre_commit_hook.get_abspath())
391d407
< sys.exit(1)
392a409,412
> # Try to wire up git to the style hooks
> if not ignore_style and main.root.Entry(".git").exists():
> install_git_style_hooks()
>