t / t5401-update-hooks.shon commit git-svn: correctly handle do_{switch,update} in deep directories (2b27f6c)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Shawn O. Pearce
   4#
   5
   6test_description='Test the update hook infrastructure.'
   7. ./test-lib.sh
   8
   9test_expect_success setup '
  10        echo This is a test. >a &&
  11        git-update-index --add a &&
  12        tree0=$(git-write-tree) &&
  13        commit0=$(echo setup | git-commit-tree $tree0) &&
  14        git-update-ref HEAD $commit0 &&
  15        git-clone ./. victim &&
  16        echo We hope it works. >a &&
  17        git-update-index a &&
  18        tree1=$(git-write-tree) &&
  19        commit1=$(echo modify | git-commit-tree $tree1 -p $commit0) &&
  20        git-update-ref HEAD $commit1
  21'
  22
  23cat >victim/.git/hooks/update <<'EOF'
  24#!/bin/sh
  25echo "$@" >$GIT_DIR/update.args
  26read x; printf "$x" >$GIT_DIR/update.stdin
  27echo STDOUT update
  28echo STDERR update >&2
  29EOF
  30chmod u+x victim/.git/hooks/update
  31
  32cat >victim/.git/hooks/post-update <<'EOF'
  33#!/bin/sh
  34echo "$@" >$GIT_DIR/post-update.args
  35read x; printf "$x" >$GIT_DIR/post-update.stdin
  36echo STDOUT post-update
  37echo STDERR post-update >&2
  38EOF
  39chmod u+x victim/.git/hooks/post-update
  40
  41test_expect_success push '
  42        git-send-pack ./victim/.git/ master >send.out 2>send.err
  43'
  44
  45test_expect_success 'hooks ran' '
  46        test -f victim/.git/update.args &&
  47        test -f victim/.git/update.stdin &&
  48        test -f victim/.git/post-update.args &&
  49        test -f victim/.git/post-update.stdin
  50'
  51
  52test_expect_success 'update hook arguments' '
  53        echo refs/heads/master $commit0 $commit1 |
  54        diff -u - victim/.git/update.args
  55'
  56
  57test_expect_success 'post-update hook arguments' '
  58        echo refs/heads/master |
  59        diff -u - victim/.git/post-update.args
  60'
  61
  62test_expect_failure 'update hook stdin is /dev/null' '
  63        test -s victim/.git/update.stdin
  64'
  65
  66test_expect_failure 'post-update hook stdin is /dev/null' '
  67        test -s victim/.git/post-update.stdin
  68'
  69
  70test_expect_failure 'send-pack produced no output' '
  71        test -s send.out
  72'
  73
  74test_expect_success 'send-pack stderr contains hook messages' '
  75        grep "STDOUT update" send.err &&
  76        grep "STDERR update" send.err &&
  77        grep "STDOUT post-update" send.err &&
  78        grep "STDERR post-update" send.err
  79'
  80
  81test_done