t / t7604-merge-custom-message.shon commit t7610-mergetool: use test_cmp instead of test $(cat file) = $txt (e10dffd)
   1#!/bin/sh
   2
   3test_description='git merge
   4
   5Testing merge when using a custom message for the merge commit.'
   6
   7. ./test-lib.sh
   8
   9create_merge_msgs() {
  10        echo >exp.subject "custom message"
  11
  12        cp exp.subject exp.log &&
  13        echo >>exp.log "" &&
  14        echo >>exp.log "* tag 'c2':" &&
  15        echo >>exp.log "  c2"
  16}
  17
  18test_expect_success 'setup' '
  19        echo c0 >c0.c &&
  20        git add c0.c &&
  21        git commit -m c0 &&
  22        git tag c0 &&
  23        echo c1 >c1.c &&
  24        git add c1.c &&
  25        git commit -m c1 &&
  26        git tag c1 &&
  27        git reset --hard c0 &&
  28        echo c2 >c2.c &&
  29        git add c2.c &&
  30        git commit -m c2 &&
  31        git tag c2 &&
  32        create_merge_msgs
  33'
  34
  35
  36test_expect_success 'merge c2 with a custom message' '
  37        git reset --hard c1 &&
  38        git merge -m "$(cat exp.subject)" c2 &&
  39        git cat-file commit HEAD >raw &&
  40        sed -e "1,/^$/d" raw >actual &&
  41        test_cmp exp.subject actual
  42'
  43
  44test_expect_success 'merge --log appends to custom message' '
  45        git reset --hard c1 &&
  46        git merge --log -m "$(cat exp.subject)" c2 &&
  47        git cat-file commit HEAD >raw &&
  48        sed -e "1,/^$/d" raw >actual &&
  49        test_cmp exp.log actual
  50'
  51
  52mesg_with_comment_and_newlines='
  53# text
  54
  55'
  56
  57test_expect_success 'prepare file with comment line and trailing newlines'  '
  58        printf "%s" "$mesg_with_comment_and_newlines" >expect
  59'
  60
  61test_expect_success 'cleanup commit messages (verbatim option)' '
  62        git reset --hard c1 &&
  63        git merge --cleanup=verbatim -F expect c2 &&
  64        git cat-file commit HEAD >raw &&
  65        sed -e "1,/^$/d" raw >actual &&
  66        test_cmp expect actual
  67'
  68
  69test_expect_success 'cleanup commit messages (whitespace option)' '
  70        git reset --hard c1 &&
  71        test_write_lines "" "# text" "" >text &&
  72        echo "# text" >expect &&
  73        git merge --cleanup=whitespace -F text c2 &&
  74        git cat-file commit HEAD >raw &&
  75        sed -e "1,/^$/d" raw >actual &&
  76        test_cmp expect actual
  77'
  78
  79test_expect_success 'cleanup merge messages (scissors option)' '
  80        git reset --hard c1 &&
  81        cat >text <<-\EOF &&
  82
  83        # to be kept
  84
  85          # ------------------------ >8 ------------------------
  86        # to be kept, too
  87        # ------------------------ >8 ------------------------
  88        to be removed
  89        # ------------------------ >8 ------------------------
  90        to be removed, too
  91        EOF
  92
  93        cat >expect <<-\EOF &&
  94        # to be kept
  95
  96          # ------------------------ >8 ------------------------
  97        # to be kept, too
  98        EOF
  99        git merge --cleanup=scissors -e -F text c2 &&
 100        git cat-file commit HEAD >raw &&
 101        sed -e "1,/^$/d" raw >actual &&
 102        test_cmp expect actual
 103'
 104
 105test_expect_success 'cleanup commit messages (strip option)' '
 106        git reset --hard c1 &&
 107        test_write_lines "" "# text" "sample" "" >text &&
 108        echo sample >expect &&
 109        git merge --cleanup=strip -F text c2 &&
 110        git cat-file commit HEAD >raw &&
 111        sed -e "1,/^$/d" raw >actual &&
 112        test_cmp expect actual
 113'
 114
 115test_done