5a811812f056218b6ae0d30386c0b6dea07364ee
   1#!/bin/sh
   2
   3test_description='verbose commit template'
   4. ./test-lib.sh
   5
   6write_script "check-for-diff" <<\EOF &&
   7grep '^diff --git' "$1" >out
   8exit 0
   9EOF
  10test_set_editor "$PWD/check-for-diff"
  11
  12cat >message <<'EOF'
  13subject
  14
  15body
  16EOF
  17
  18test_expect_success 'setup' '
  19        echo content >file &&
  20        git add file &&
  21        git commit -F message
  22'
  23
  24test_expect_success 'initial commit shows verbose diff' '
  25        git commit --amend -v &&
  26        test_line_count = 1 out
  27'
  28
  29test_expect_success 'second commit' '
  30        echo content modified >file &&
  31        git add file &&
  32        git commit -F message
  33'
  34
  35check_message() {
  36        git log -1 --pretty=format:%s%n%n%b >actual &&
  37        test_cmp "$1" actual
  38}
  39
  40test_expect_success 'verbose diff is stripped out' '
  41        git commit --amend -v &&
  42        check_message message &&
  43        test_line_count = 1 out
  44'
  45
  46test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
  47        git config diff.mnemonicprefix true &&
  48        git commit --amend -v &&
  49        check_message message &&
  50        test_line_count = 1 out
  51'
  52
  53cat >diff <<'EOF'
  54This is an example commit message that contains a diff.
  55
  56diff --git c/file i/file
  57new file mode 100644
  58index 0000000..f95c11d
  59--- /dev/null
  60+++ i/file
  61@@ -0,0 +1 @@
  62+this is some content
  63EOF
  64
  65test_expect_success 'diff in message is retained without -v' '
  66        git commit --amend -F diff &&
  67        check_message diff
  68'
  69
  70test_expect_success 'diff in message is retained with -v' '
  71        git commit --amend -F diff -v &&
  72        check_message diff
  73'
  74
  75test_expect_success 'submodule log is stripped out too with -v' '
  76        git config diff.submodule log &&
  77        git submodule add ./. sub &&
  78        git commit -m "sub added" &&
  79        (
  80                cd sub &&
  81                echo "more" >>file &&
  82                git commit -a -m "submodule commit"
  83        ) &&
  84        (
  85                GIT_EDITOR=cat &&
  86                export GIT_EDITOR &&
  87                test_must_fail git commit -a -v 2>err
  88        ) &&
  89        test_i18ngrep "Aborting commit due to empty commit message." err
  90'
  91
  92test_expect_success 'verbose diff is stripped out with set core.commentChar' '
  93        (
  94                GIT_EDITOR=cat &&
  95                export GIT_EDITOR &&
  96                test_must_fail git -c core.commentchar=";" commit -a -v 2>err
  97        ) &&
  98        test_i18ngrep "Aborting commit due to empty commit message." err
  99'
 100
 101test_expect_success 'status does not verbose without --verbose' '
 102        git status >actual &&
 103        ! grep "^diff --git" actual
 104'
 105
 106test_done