1020af94b714635d94e6f014889af004353fe0dd
   1#!/bin/sh
   2#
   3# Copyright (c) 2010 Thomas Rast
   4#
   5
   6test_description='Test the post-rewrite hook.'
   7. ./test-lib.sh
   8
   9test_expect_success 'setup' '
  10        test_commit A foo A &&
  11        test_commit B foo B &&
  12        test_commit C foo C &&
  13        test_commit D foo D
  14'
  15
  16mkdir .git/hooks
  17
  18cat >.git/hooks/post-rewrite <<EOF
  19#!/bin/sh
  20echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
  21cat > "$TRASH_DIRECTORY"/post-rewrite.data
  22EOF
  23chmod u+x .git/hooks/post-rewrite
  24
  25clear_hook_input () {
  26        rm -f post-rewrite.args post-rewrite.data
  27}
  28
  29verify_hook_input () {
  30        test_cmp "$TRASH_DIRECTORY"/post-rewrite.args expected.args &&
  31        test_cmp "$TRASH_DIRECTORY"/post-rewrite.data expected.data
  32}
  33
  34test_expect_success 'git commit --amend' '
  35        clear_hook_input &&
  36        echo "D new message" > newmsg &&
  37        oldsha=$(git rev-parse HEAD^0) &&
  38        git commit -Fnewmsg --amend &&
  39        echo amend > expected.args &&
  40        echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
  41        verify_hook_input
  42'
  43
  44test_expect_success 'git commit --amend --no-post-rewrite' '
  45        clear_hook_input &&
  46        echo "D new message again" > newmsg &&
  47        git commit --no-post-rewrite -Fnewmsg --amend &&
  48        test ! -f post-rewrite.args &&
  49        test ! -f post-rewrite.data
  50'
  51
  52test_done