t / t5402-post-merge-hook.shon commit cherry-pick/revert: respect order of revisions to pick (a73e22e)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Josh England
   4#
   5
   6test_description='Test the post-merge hook.'
   7. ./test-lib.sh
   8
   9test_expect_success setup '
  10        echo Data for commit0. >a &&
  11        git update-index --add a &&
  12        tree0=$(git write-tree) &&
  13        commit0=$(echo setup | git commit-tree $tree0) &&
  14        echo Changed data for commit1. >a &&
  15        git update-index a &&
  16        tree1=$(git write-tree) &&
  17        commit1=$(echo modify | git commit-tree $tree1 -p $commit0) &&
  18        git update-ref refs/heads/master $commit0 &&
  19        git clone ./. clone1 &&
  20        GIT_DIR=clone1/.git git update-index --add a &&
  21        git clone ./. clone2 &&
  22        GIT_DIR=clone2/.git git update-index --add a
  23'
  24
  25for clone in 1 2; do
  26    cat >clone${clone}/.git/hooks/post-merge <<'EOF'
  27#!/bin/sh
  28echo $@ >> $GIT_DIR/post-merge.args
  29EOF
  30    chmod u+x clone${clone}/.git/hooks/post-merge
  31done
  32
  33test_expect_success 'post-merge does not run for up-to-date ' '
  34        GIT_DIR=clone1/.git git merge $commit0 &&
  35        ! test -f clone1/.git/post-merge.args
  36'
  37
  38test_expect_success 'post-merge runs as expected ' '
  39        GIT_DIR=clone1/.git git merge $commit1 &&
  40        test -e clone1/.git/post-merge.args
  41'
  42
  43test_expect_success 'post-merge from normal merge receives the right argument ' '
  44        grep 0 clone1/.git/post-merge.args
  45'
  46
  47test_expect_success 'post-merge from squash merge runs as expected ' '
  48        GIT_DIR=clone2/.git git merge --squash $commit1 &&
  49        test -e clone2/.git/post-merge.args
  50'
  51
  52test_expect_success 'post-merge from squash merge receives the right argument ' '
  53        grep 1 clone2/.git/post-merge.args
  54'
  55
  56test_done