Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='verbose commit template' |
| 4 | . ./test-lib.sh |
| 5 | |
Pranit Bauva | de45dbb | 2016-05-05 15:20:01 +0530 | [diff] [blame] | 6 | write_script "check-for-diff" <<\EOF && |
| 7 | grep '^diff --git' "$1" >out |
| 8 | exit 0 |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 9 | EOF |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 10 | test_set_editor "$PWD/check-for-diff" |
| 11 | |
| 12 | cat >message <<'EOF' |
| 13 | subject |
| 14 | |
| 15 | body |
| 16 | EOF |
| 17 | |
| 18 | test_expect_success 'setup' ' |
| 19 | echo content >file && |
| 20 | git add file && |
| 21 | git commit -F message |
| 22 | ' |
| 23 | |
Jeff King | 1324fb6 | 2008-11-12 03:23:37 -0500 | [diff] [blame] | 24 | test_expect_success 'initial commit shows verbose diff' ' |
Pranit Bauva | de45dbb | 2016-05-05 15:20:01 +0530 | [diff] [blame] | 25 | git commit --amend -v && |
| 26 | test_line_count = 1 out |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 27 | ' |
| 28 | |
| 29 | test_expect_success 'second commit' ' |
| 30 | echo content modified >file && |
| 31 | git add file && |
| 32 | git commit -F message |
| 33 | ' |
| 34 | |
| 35 | check_message() { |
| 36 | git log -1 --pretty=format:%s%n%n%b >actual && |
| 37 | test_cmp "$1" actual |
| 38 | } |
| 39 | |
| 40 | test_expect_success 'verbose diff is stripped out' ' |
| 41 | git commit --amend -v && |
Pranit Bauva | de45dbb | 2016-05-05 15:20:01 +0530 | [diff] [blame] | 42 | check_message message && |
| 43 | test_line_count = 1 out |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 44 | ' |
| 45 | |
| 46 | test_expect_success 'verbose diff is stripped out (mnemonicprefix)' ' |
| 47 | git config diff.mnemonicprefix true && |
| 48 | git commit --amend -v && |
Pranit Bauva | de45dbb | 2016-05-05 15:20:01 +0530 | [diff] [blame] | 49 | check_message message && |
| 50 | test_line_count = 1 out |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 51 | ' |
| 52 | |
| 53 | cat >diff <<'EOF' |
| 54 | This is an example commit message that contains a diff. |
| 55 | |
| 56 | diff --git c/file i/file |
| 57 | new file mode 100644 |
| 58 | index 0000000..f95c11d |
| 59 | --- /dev/null |
| 60 | +++ i/file |
| 61 | @@ -0,0 +1 @@ |
| 62 | +this is some content |
| 63 | EOF |
| 64 | |
| 65 | test_expect_success 'diff in message is retained without -v' ' |
| 66 | git commit --amend -F diff && |
| 67 | check_message diff |
| 68 | ' |
| 69 | |
Jens Lehmann | 1a72cfd | 2013-12-05 20:44:14 +0100 | [diff] [blame] | 70 | test_expect_success 'diff in message is retained with -v' ' |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 71 | git commit --amend -F diff -v && |
| 72 | check_message diff |
| 73 | ' |
| 74 | |
Jens Lehmann | 1a72cfd | 2013-12-05 20:44:14 +0100 | [diff] [blame] | 75 | test_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 | |
| 92 | test_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 | |
Pranit Bauva | 98baeb7 | 2016-05-05 15:19:59 +0530 | [diff] [blame] | 101 | test_expect_success 'status does not verbose without --verbose' ' |
| 102 | git status >actual && |
| 103 | ! grep "^diff --git" actual |
| 104 | ' |
| 105 | |
Pranit Bauva | aaab842 | 2016-05-05 15:20:02 +0530 | [diff] [blame] | 106 | test_expect_success 'setup -v -v' ' |
| 107 | echo dirty >file |
| 108 | ' |
| 109 | |
| 110 | for i in true 1 |
| 111 | do |
| 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 | " |
| 116 | done |
| 117 | |
| 118 | for i in false -2 -1 0 |
| 119 | do |
| 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 | " |
| 124 | done |
| 125 | |
| 126 | for i in 2 3 |
| 127 | do |
| 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 | " |
| 132 | done |
| 133 | |
| 134 | for i in true false -2 -1 0 1 2 3 |
| 135 | do |
| 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 | " |
| 150 | done |
| 151 | |
| 152 | test_expect_success "status ignores commit.verbose=true" ' |
| 153 | git -c commit.verbose=true status >actual && |
| 154 | ! grep "^diff --git actual" |
| 155 | ' |
| 156 | |
Jeff King | 0b38227 | 2008-11-12 03:25:52 -0500 | [diff] [blame] | 157 | test_done |