t / t5501-post-upload-pack.shon commit Git 1.6.6-rc2 (80d9361)
   1#!/bin/sh
   2
   3test_description='post upload-hook'
   4
   5. ./test-lib.sh
   6
   7LOGFILE=".git/post-upload-pack-log"
   8
   9test_expect_success setup '
  10        test_commit A &&
  11        test_commit B &&
  12        git reset --hard A &&
  13        test_commit C &&
  14        git branch prev B &&
  15        mkdir -p .git/hooks &&
  16        {
  17                echo "#!$SHELL_PATH" &&
  18                echo "cat >post-upload-pack-log"
  19        } >".git/hooks/post-upload-pack" &&
  20        chmod +x .git/hooks/post-upload-pack
  21'
  22
  23test_expect_success initial '
  24        rm -fr sub &&
  25        git init sub &&
  26        (
  27                cd sub &&
  28                git fetch --no-tags .. prev
  29        ) &&
  30        want=$(sed -n "s/^want //p" "$LOGFILE") &&
  31        test "$want" = "$(git rev-parse --verify B)" &&
  32        ! grep "^have " "$LOGFILE" &&
  33        kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
  34        test "$kind" = fetch
  35'
  36
  37test_expect_success second '
  38        rm -fr sub &&
  39        git init sub &&
  40        (
  41                cd sub &&
  42                git fetch --no-tags .. prev:refs/remotes/prev &&
  43                git fetch --no-tags .. master
  44        ) &&
  45        want=$(sed -n "s/^want //p" "$LOGFILE") &&
  46        test "$want" = "$(git rev-parse --verify C)" &&
  47        have=$(sed -n "s/^have //p" "$LOGFILE") &&
  48        test "$have" = "$(git rev-parse --verify B)" &&
  49        kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
  50        test "$kind" = fetch
  51'
  52
  53test_expect_success all '
  54        rm -fr sub &&
  55        HERE=$(pwd) &&
  56        git init sub &&
  57        (
  58                cd sub &&
  59                git clone "file://$HERE/.git" new
  60        ) &&
  61        sed -n "s/^want //p" "$LOGFILE" | sort >actual &&
  62        git rev-parse A B C | sort >expect &&
  63        test_cmp expect actual &&
  64        ! grep "^have " "$LOGFILE" &&
  65        kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
  66        test "$kind" = clone
  67'
  68
  69test_done