chiark / gitweb /
Check for pre-commit hook existence.
authorRussell Steicke <russellsteicke@gmail.com>
Sun, 3 Aug 2008 14:14:01 +0000 (22:14 +0800)
committerPetr Baudis <pasky@suse.cz>
Sun, 3 Aug 2008 14:26:03 +0000 (16:26 +0200)
Running tg in a repo without an active pre-commit hook fails
saying

  grep: .git/hooks/pre-commit: No such file or directory
  cat: .git/hooks/pre-commit: No such file or directory

Even "tg help" does this!  So add extra checks for existence
of the pre-commit hook.

tg.sh

diff --git a/tg.sh b/tg.sh
index 6896721..c334f70 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -21,9 +21,11 @@ die()
 setup_hook()
 {
        hook_call="\"\$(tg --hooks-path)\"/$1 \"\$@\""
-       if fgrep -q "$hook_call" "$git_dir/hooks/$1"; then
-               # Another job well done!
-               return
+       if [ -x "$git_dir/hooks/$1" ]; then
+               if fgrep -q "$hook_call" "$git_dir/hooks/$1"; then
+                       # Another job well done!
+                       return
+               fi
        fi
        # Prepare incanation
        if [ -x "$git_dir/hooks/$1" ]; then
@@ -35,7 +37,7 @@ setup_hook()
        {
                echo "#!/bin/sh"
                echo "$hook_call"
-               cat "$git_dir/hooks/$1"
+               [ -x "$git_dir/hooks/$1" ] && cat "$git_dir/hooks/$1"
        } >"$git_dir/hooks/$1+"
        chmod a+x "$git_dir/hooks/$1+"
        mv "$git_dir/hooks/$1+" "$git_dir/hooks/$1"