8
9
test_description='git commit'
10
. ./test-lib.sh
11
+. "$TEST_DIRECTORY/diff-lib.sh"
12
12
-test_tick
13
+author='The Real Author <someguy@his.email.org>'
14
14
-test_expect_success \
15
- "initial status" \
16
- "echo 'bongo bongo' >file &&
17
- git add file"
15
+test_tick
16
19
-test_expect_success "Constructing initial commit" '
17
+test_expect_success 'initial status' '
18
+ echo bongo bongo >file &&
19
+ git add file &&
20
git status >actual &&
21
test_i18ngrep "Initial commit" actual
22
'
23
24
-test_expect_success \
25
- "fail initial amend" \
26
- "test_must_fail git commit --amend"
24
+test_expect_success 'fail initial amend' '
25
+ test_must_fail git commit --amend
26
+'
27
28
-test_expect_success \
29
- "initial commit" \
30
- "git commit -m initial"
28
+test_expect_success 'setup: initial commit' '
29
+ git commit -m initial
30
+'
31
32
-test_expect_success \
33
- "invalid options 1" \
34
- "test_must_fail git commit -m foo -m bar -F file"
32
+test_expect_success '-m and -F do not mix' '
33
+ test_must_fail git commit -m foo -m bar -F file
34
+'
35
36
-test_expect_success \
37
- "invalid options 2" \
38
- "test_must_fail git commit -C HEAD -m illegal"
36
+test_expect_success '-m and -C do not mix' '
37
+ test_must_fail git commit -C HEAD -m illegal
38
+'
39
40
-test_expect_success \
41
- "using paths with -a" \
42
- "echo King of the bongo >file &&
43
- test_must_fail git commit -m foo -a file"
40
+test_expect_success 'paths and -a do not mix' '
41
+ echo King of the bongo >file &&
42
+ test_must_fail git commit -m foo -a file
43
+'
44
45
test_expect_success PERL 'can use paths with --interactive' '
46
echo bong-o-bong >file &&
50
git reset --hard HEAD^
51
'
52
53
-test_expect_success \
54
- "using invalid commit with -C" \
55
- "test_must_fail git commit -C bogus"
53
+test_expect_success 'using invalid commit with -C' '
54
+ test_must_fail git commit -C bogus
55
+'
56
57
-test_expect_success \
58
- "testing nothing to commit" \
59
- "test_must_fail git commit -m initial"
57
+test_expect_success 'nothing to commit' '
58
+ test_must_fail git commit -m initial
59
+'
60
61
-test_expect_success \
62
- "next commit" \
63
- "echo 'bongo bongo bongo' >file && \
64
- git commit -m next -a"
61
+test_expect_success 'setup: non-initial commit' '
62
+ echo bongo bongo bongo >file &&
63
+ git commit -m next -a
64
+'
65
66
-test_expect_success \
67
- "commit message from non-existing file" \
68
- "echo 'more bongo: bongo bongo bongo bongo' >file && \
69
- test_must_fail git commit -F gah -a"
66
+test_expect_success 'commit message from non-existing file' '
67
+ echo more bongo: bongo bongo bongo bongo >file &&
68
+ test_must_fail git commit -F gah -a
69
+'
70
71
-# Empty except stray tabs and spaces on a few lines.
72
-sed -e 's/@$//' >msg <<EOF
73
- @
71
+test_expect_success 'empty commit message' '
72
+ # Empty except stray tabs and spaces on a few lines.
73
+ sed -e "s/@//g" >msg <<-\EOF &&
74
+ @ @
75
+ @@
76
+ @ @
77
+ @Signed-off-by: hula@
78
+ EOF
79
+ test_must_fail git commit -F msg -a
80
+'
81
75
- @
76
-Signed-off-by: hula
77
-EOF
78
-test_expect_success \
79
- "empty commit message" \
80
- "test_must_fail git commit -F msg -a"
82
+test_expect_success 'setup: commit message from file' '
83
+ echo this is the commit message, coming from a file >msg &&
84
+ git commit -F msg -a
85
+'
86
82
-test_expect_success \
83
- "commit message from file" \
84
- "echo 'this is the commit message, coming from a file' >msg && \
85
- git commit -F msg -a"
87
+test_expect_success 'amend commit' '
88
+ cat >editor <<-\EOF &&
89
+ #!/bin/sh
90
+ sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
91
+ mv "$1-" "$1"
92
+ EOF
93
+ chmod 755 editor &&
94
+ EDITOR=./editor git commit --amend
95
+'
96
87
-cat >editor <<\EOF
88
-#!/bin/sh
89
-sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
90
-mv "$1-" "$1"
91
-EOF
92
-chmod 755 editor
97
+test_expect_success '-m and -F do not mix' '
98
+ echo enough with the bongos >file &&
99
+ test_must_fail git commit -F msg -m amending .
100
+'
101
+
102
+test_expect_success 'using message from other commit' '
103
+ git commit -C HEAD^ .
104
+'
105
94
-test_expect_success \
95
- "amend commit" \
96
- "EDITOR=./editor git commit --amend"
106
+test_expect_success 'editing message from other commit' '
107
+ cat >editor <<-\EOF &&
108
+ #!/bin/sh
109
+ sed -e "s/amend/older/g" < "$1" > "$1-"
110
+ mv "$1-" "$1"
111
+ EOF
112
+ chmod 755 editor &&
113
+ echo hula hula >file &&
114
+ EDITOR=./editor git commit -c HEAD^ -a
115
+'
116
98
-test_expect_success \
99
- "passing -m and -F" \
100
- "echo 'enough with the bongos' >file && \
101
- test_must_fail git commit -F msg -m amending ."
117
+test_expect_success 'message from stdin' '
118
+ echo silly new contents >file &&
119
+ echo commit message from stdin |
120
+ git commit -F - -a
121
+'
122
103
-test_expect_success \
104
- "using message from other commit" \
105
- "git commit -C HEAD^ ."
123
+test_expect_success 'overriding author from command line' '
124
+ echo gak >file &&
125
+ git commit -m author \
126
+ --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 &&
127
+ grep Rubber.Duck output
128
+'
129
107
-cat >editor <<\EOF
108
-#!/bin/sh
109
-sed -e "s/amend/older/g" < "$1" > "$1-"
110
-mv "$1-" "$1"
111
-EOF
112
-chmod 755 editor
113
-
114
-test_expect_success \
115
- "editing message from other commit" \
116
- "echo 'hula hula' >file && \
117
- EDITOR=./editor git commit -c HEAD^ -a"
118
-
119
-test_expect_success \
120
- "message from stdin" \
121
- "echo 'silly new contents' >file && \
122
- echo commit message from stdin | git commit -F - -a"
123
-
124
-test_expect_success \
125
- "overriding author from command line" \
126
- "echo 'gak' >file && \
127
- git commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a >output 2>&1"
128
-
129
-test_expect_success \
130
- "commit --author output mentions author" \
131
- "grep Rubber.Duck output"
132
-
133
-test_expect_success PERL \
134
- "interactive add" \
135
- "echo 7 | git commit --interactive | grep 'What now'"
136
-
137
-test_expect_success PERL \
138
- "commit --interactive doesn't change index if editor aborts" \
139
- "echo zoo >file &&
130
+test_expect_success PERL 'interactive add' '
131
+ echo 7 |
132
+ git commit --interactive |
133
+ grep "What now"
134
+'
135
+
136
+test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
137
+ echo zoo >file &&
138
test_must_fail git diff --exit-code >diff1 &&
141
- (echo u ; echo '*' ; echo q) |
142
- (EDITOR=: && export EDITOR &&
143
- test_must_fail git commit --interactive) &&
139
+ (echo u ; echo "*" ; echo q) |
140
+ (
141
+ EDITOR=: &&
142
+ export EDITOR &&
143
+ test_must_fail git commit --interactive
144
+ ) &&
145
git diff >diff2 &&
145
- test_cmp diff1 diff2"
146
+ compare_diff_patch diff1 diff2
147
+'
148
147
-cat >editor <<\EOF
148
-#!/bin/sh
149
-sed -e "s/good/bad/g" < "$1" > "$1-"
150
-mv "$1-" "$1"
151
-EOF
152
-chmod 755 editor
153
-
154
-cat >msg <<EOF
155
-A good commit message.
156
-EOF
157
-
158
-test_expect_success \
159
- 'editor not invoked if -F is given' '
160
- echo "moo" >file &&
161
- EDITOR=./editor git commit -a -F msg &&
162
- git show -s --pretty=format:"%s" | grep -q good &&
163
- echo "quack" >file &&
164
- echo "Another good message." | EDITOR=./editor git commit -a -F - &&
165
- git show -s --pretty=format:"%s" | grep -q good
166
- '
149
+test_expect_success 'editor not invoked if -F is given' '
150
+ cat >editor <<-\EOF &&
151
+ #!/bin/sh
152
+ sed -e s/good/bad/g <"$1" >"$1-"
153
+ mv "$1-" "$1"
154
+ EOF
155
+ chmod 755 editor &&
156
+
157
+ echo A good commit message. >msg &&
158
+ echo moo >file &&
159
+
160
+ EDITOR=./editor git commit -a -F msg &&
161
+ git show -s --pretty=format:%s >subject &&
162
+ grep -q good subject &&
163
+
164
+ echo quack >file &&
165
+ echo Another good message. |
166
+ EDITOR=./editor git commit -a -F - &&
167
+ git show -s --pretty=format:%s >subject &&
168
+ grep -q good subject
169
+'
170
171
test_expect_success 'partial commit that involves removal (1)' '
172
200
201
'
202
200
-author="The Real Author <someguy@his.email.org>"
203
test_expect_success 'amend commit to fix author' '
204
205
oldtick=$GIT_AUTHOR_DATE &&
328
329
'
330
329
-author="The Real Author <someguy@his.email.org>"
331
test_expect_success 'amend commit to fix author' '
332
333
oldtick=$GIT_AUTHOR_DATE &&
354
355
test_expect_success 'same tree (single parent)' '
356
356
- git reset --hard
357
-
358
- if git commit -m empty
359
- then
360
- echo oops -- should have complained
361
- false
362
- else
363
- : happy
364
- fi
357
+ git reset --hard &&
358
+ test_must_fail git commit -m empty
359
360
'
361