forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy patht7509-commit-authorship.sh
More file actions
executable file
·256 lines (224 loc) · 7.61 KB
/
t7509-commit-authorship.sh
File metadata and controls
executable file
·256 lines (224 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/sh
#
# Copyright (c) 2009 Erick Mattos
#
test_description='commit tests of various authorhip options. '
. ./test-lib.sh
author_header () {
git cat-file commit "$1" |
sed -n -e '/^$/q' -e '/^author /p'
}
committer_header () {
git cat-file commit "$1" |
sed -n -e '/^$/q' -e '/^committer /p'
}
message_body () {
git cat-file commit "$1" |
sed -e '1,/^$/d'
}
test_expect_success '-C option copies authorship and message' '
test_env GIT_COMMITTER_NAME="Frigate" \
GIT_COMMITTER_EMAIL="flying@over.world" \
test_commit --author Frigate\ \<flying@over.world\> \
"Initial Commit" foo Initial Initial &&
echo "Test 1" >>foo &&
test_tick &&
git commit -a -C Initial &&
author_header Initial >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
message_body Initial >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
test_expect_success '-C option copies only the message with --reset-author' '
echo "Test 2" >>foo &&
test_tick &&
git commit -a -C Initial --reset-author &&
echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
message_body Initial >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
test_expect_success '-c option copies authorship and message' '
echo "Test 3" >>foo &&
test_tick &&
EDITOR=: VISUAL=: git commit -a -c Initial &&
author_header Initial >expect &&
author_header HEAD >actual &&
test_cmp expect actual
'
test_expect_success '-c option copies only the message with --reset-author' '
echo "Test 4" >>foo &&
test_tick &&
EDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&
echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
message_body Initial >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
test_expect_success '--amend option copies authorship' '
git checkout Initial &&
echo "Test 5" >>foo &&
test_tick &&
git commit -a --amend -m "amend test" &&
author_header Initial >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
echo "amend test" >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
sha1_file() {
echo "$*" | sed "s#..#.git/objects/&/#"
}
remove_object() {
rm -f $(sha1_file "$*")
}
test_expect_success '--amend option with empty author' '
git cat-file commit Initial >tmp &&
sed "s/author [^<]* </author </" tmp >empty-author &&
sha=$(git hash-object -t commit -w empty-author) &&
test_when_finished "remove_object $sha" &&
git checkout $sha &&
test_when_finished "git checkout Initial" &&
echo "Empty author test" >>foo &&
test_tick &&
test_must_fail git commit -a -m "empty author" --amend 2>err &&
test_grep "empty ident" err
'
test_expect_success '--amend option with missing author' '
git cat-file commit Initial >tmp &&
sed "s/author [^<]* </author </" tmp >malformed &&
sha=$(git hash-object --literally -t commit -w malformed) &&
test_when_finished "remove_object $sha" &&
git checkout $sha &&
test_when_finished "git checkout Initial" &&
echo "Missing author test" >>foo &&
test_tick &&
test_must_fail git commit -a -m "malformed author" --amend 2>err &&
test_grep "empty ident" err
'
test_expect_success '--reset-author makes the commit ours even with --amend option' '
git checkout Initial &&
echo "Test 6" >>foo &&
test_tick &&
git commit -a --reset-author -m "Changed again" --amend &&
echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
echo "Changed again" >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
test_expect_success '--reset-author and --author are mutually exclusive' '
git checkout Initial &&
echo "Test 7" >>foo &&
test_tick &&
test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
'
test_expect_success '--reset-author should be rejected without -c/-C/--amend' '
git checkout Initial &&
echo "Test 7" >>foo &&
test_tick &&
test_must_fail git commit -a --reset-author -m done
'
test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' '
echo "cherry-pick 1a" >>foo &&
test_tick &&
git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" &&
git tag cherry-pick-head &&
git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
echo "This is a MERGE_MSG" >.git/MERGE_MSG &&
echo "cherry-pick 1b" >>foo &&
test_tick &&
git commit -a &&
author_header cherry-pick-head >expect &&
author_header HEAD >actual &&
test_cmp expect actual &&
echo "This is a MERGE_MSG" >expect &&
message_body HEAD >actual &&
test_cmp expect actual
'
test_expect_success '--reset-author with CHERRY_PICK_HEAD' '
git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
echo "cherry-pick 2" >>foo &&
test_tick &&
git commit -am "cherry-pick 2" --reset-author &&
echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
author_header HEAD >actual &&
test_cmp expect actual
'
test_expect_success '--committer option overrides committer' '
git checkout Initial &&
echo "Test --committer" >>foo &&
test_tick &&
git commit -a -m "test committer" --committer="Custom Committer <custom@committer.example>" &&
committer_header HEAD >actual &&
grep "Custom Committer <custom@committer.example>" actual
'
test_expect_success '--committer with pattern search' '
echo "Test committer pattern" >>foo &&
test_tick &&
git commit -a -m "test committer pattern" --committer="Frigate" &&
committer_header HEAD >actual &&
grep "Frigate <flying@over.world>" actual
'
test_expect_success '--committer malformed parameter' '
echo "Test malformed" >>foo &&
test_tick &&
test_must_fail git commit -a -m "test malformed" --committer="malformed committer"
'
test_expect_success '--committer with --amend option' '
git checkout -f Initial &&
echo "Test committer with amend" >>foo &&
test_tick &&
git commit -a -m "initial commit for amend test" &&
echo "Modified for amend" >>foo &&
test_tick &&
git commit -a --amend --no-edit \
--author="Test Author <test@author.example>" \
--committer="Test Committer <test@committer.example>" &&
author_header HEAD >actual_author &&
grep "Test Author <test@author.example>" actual_author &&
committer_header HEAD >actual_committer &&
grep "Test Committer <test@committer.example>" actual_committer
'
test_expect_success 'GIT_COMMITTER_* environment variables' '
git checkout -f Initial &&
echo "Test env vars" >>foo &&
test_tick &&
test_env GIT_COMMITTER_NAME="Env Committer" \
GIT_COMMITTER_EMAIL="env@test.example" \
git commit -a -m "test committer env vars" &&
committer_header HEAD >actual &&
grep "Env Committer <env@test.example>" actual
'
test_expect_success '--committer overrides GIT_COMMITTER_* environment variables' '
echo "Test override" >>foo &&
test_tick &&
test_env GIT_COMMITTER_NAME="Env Committer" \
GIT_COMMITTER_EMAIL="env@test.example" \
git commit -a -m "test override" \
--committer="Override Committer <override@test.example>" &&
committer_header HEAD >actual &&
grep "Override Committer <override@test.example>" actual
'
test_expect_success '--date with --committer changes both author and committer dates' '
git checkout -f Initial &&
echo "Test date override" >>foo &&
test_tick &&
git commit -a -m "test date" \
--author="Date Author <date@author.example>" \
--committer="Date Committer <date@committer.example>" \
--date="2024-06-15 10:30:00 +0800" &&
git log -1 --format="%ai" >author_date &&
git log -1 --format="%ci" >committer_date &&
grep "2024-06-15 10:30:00 +0800" author_date &&
grep "2024-06-15 10:30:00 +0800" committer_date
'
test_done