t / t7507-commit-verbose.shon commit format-patch: introduce format.useAutoBase configuration (bb52995)
   1#!/bin/sh
   2
   3test_description='verbose commit template'
   4. ./test-lib.sh
   5
   6cat >check-for-diff <<EOF
   7#!$SHELL_PATH
   8exec grep '^diff --git' "\$1"
   9EOF
  10chmod +x check-for-diff
  11test_set_editor "$PWD/check-for-diff"
  12
  13cat >message <<'EOF'
  14subject
  15
  16body
  17EOF
  18
  19test_expect_success 'setup' '
  20        echo content >file &&
  21        git add file &&
  22        git commit -F message
  23'
  24
  25test_expect_success 'initial commit shows verbose diff' '
  26        git commit --amend -v
  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'
  44
  45test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
  46        git config diff.mnemonicprefix true &&
  47        git commit --amend -v &&
  48        check_message message
  49'
  50
  51cat >diff <<'EOF'
  52This is an example commit message that contains a diff.
  53
  54diff --git c/file i/file
  55new file mode 100644
  56index 0000000..f95c11d
  57--- /dev/null
  58+++ i/file
  59@@ -0,0 +1 @@
  60+this is some content
  61EOF
  62
  63test_expect_success 'diff in message is retained without -v' '
  64        git commit --amend -F diff &&
  65        check_message diff
  66'
  67
  68test_expect_success 'diff in message is retained with -v' '
  69        git commit --amend -F diff -v &&
  70        check_message diff
  71'
  72
  73test_expect_success 'submodule log is stripped out too with -v' '
  74        git config diff.submodule log &&
  75        git submodule add ./. sub &&
  76        git commit -m "sub added" &&
  77        (
  78                cd sub &&
  79                echo "more" >>file &&
  80                git commit -a -m "submodule commit"
  81        ) &&
  82        (
  83                GIT_EDITOR=cat &&
  84                export GIT_EDITOR &&
  85                test_must_fail git commit -a -v 2>err
  86        ) &&
  87        test_i18ngrep "Aborting commit due to empty commit message." err
  88'
  89
  90test_expect_success 'verbose diff is stripped out with set core.commentChar' '
  91        (
  92                GIT_EDITOR=cat &&
  93                export GIT_EDITOR &&
  94                test_must_fail git -c core.commentchar=";" commit -a -v 2>err
  95        ) &&
  96        test_i18ngrep "Aborting commit due to empty commit message." err
  97'
  98
  99test_done