t / t7507-commit-verbose.shon commit Merge branch 'sb/submodule-rm-absorb' (3ccd681)
   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_expect_success 'setup -v -v' '
 107        echo dirty >file
 108'
 109
 110for i in true 1
 111do
 112        test_expect_success "commit.verbose=$i and --verbose omitted" "
 113                git -c commit.verbose=$i commit --amend &&
 114                test_line_count = 1 out
 115        "
 116done
 117
 118for i in false -2 -1 0
 119do
 120        test_expect_success "commit.verbose=$i and --verbose omitted" "
 121                git -c commit.verbose=$i commit --amend &&
 122                test_line_count = 0 out
 123        "
 124done
 125
 126for i in 2 3
 127do
 128        test_expect_success "commit.verbose=$i and --verbose omitted" "
 129                git -c commit.verbose=$i commit --amend &&
 130                test_line_count = 2 out
 131        "
 132done
 133
 134for i in true false -2 -1 0 1 2 3
 135do
 136        test_expect_success "commit.verbose=$i and --verbose" "
 137                git -c commit.verbose=$i commit --amend --verbose &&
 138                test_line_count = 1 out
 139        "
 140
 141        test_expect_success "commit.verbose=$i and --no-verbose" "
 142                git -c commit.verbose=$i commit --amend --no-verbose &&
 143                test_line_count = 0 out
 144        "
 145
 146        test_expect_success "commit.verbose=$i and -v -v" "
 147                git -c commit.verbose=$i commit --amend -v -v &&
 148                test_line_count = 2 out
 149        "
 150done
 151
 152test_expect_success "status ignores commit.verbose=true" '
 153        git -c commit.verbose=true status >actual &&
 154        ! grep "^diff --git actual"
 155'
 156
 157test_done