]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7509-commit-authorship.sh
The third batch
[thirdparty/git.git] / t / t7509-commit-authorship.sh
CommitLineData
c51f6cee
EM
1#!/bin/sh
2#
3# Copyright (c) 2009 Erick Mattos
4#
5
4625540d 6test_description='commit tests of various authorhip options. '
c51f6cee 7
9081a421 8TEST_PASSES_SANITIZE_LEAK=true
c51f6cee
EM
9. ./test-lib.sh
10
11author_header () {
12 git cat-file commit "$1" |
13 sed -n -e '/^$/q' -e '/^author /p'
14}
15
16message_body () {
17 git cat-file commit "$1" |
18 sed -e '1,/^$/d'
19}
20
21test_expect_success '-C option copies authorship and message' '
999cfc4f
ÆAB
22 test_commit --author Frigate\ \<flying@over.world\> \
23 "Initial Commit" foo Initial Initial &&
c51f6cee
EM
24 echo "Test 1" >>foo &&
25 test_tick &&
26 git commit -a -C Initial &&
27 author_header Initial >expect &&
28 author_header HEAD >actual &&
29 test_cmp expect actual &&
30
31 message_body Initial >expect &&
32 message_body HEAD >actual &&
33 test_cmp expect actual
34'
35
36test_expect_success '-C option copies only the message with --reset-author' '
37 echo "Test 2" >>foo &&
38 test_tick &&
39 git commit -a -C Initial --reset-author &&
40 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
a48fcd83 41 author_header HEAD >actual &&
c51f6cee
EM
42 test_cmp expect actual &&
43
44 message_body Initial >expect &&
45 message_body HEAD >actual &&
46 test_cmp expect actual
47'
48
49test_expect_success '-c option copies authorship and message' '
50 echo "Test 3" >>foo &&
51 test_tick &&
52 EDITOR=: VISUAL=: git commit -a -c Initial &&
53 author_header Initial >expect &&
54 author_header HEAD >actual &&
55 test_cmp expect actual
56'
57
58test_expect_success '-c option copies only the message with --reset-author' '
59 echo "Test 4" >>foo &&
60 test_tick &&
61 EDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&
62 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
63 author_header HEAD >actual &&
64 test_cmp expect actual &&
65
66 message_body Initial >expect &&
67 message_body HEAD >actual &&
68 test_cmp expect actual
69'
70
71test_expect_success '--amend option copies authorship' '
72 git checkout Initial &&
73 echo "Test 5" >>foo &&
74 test_tick &&
75 git commit -a --amend -m "amend test" &&
76 author_header Initial >expect &&
77 author_header HEAD >actual &&
d8b396e1 78 test_cmp expect actual &&
c51f6cee
EM
79
80 echo "amend test" >expect &&
81 message_body HEAD >actual &&
82 test_cmp expect actual
83'
84
fb7749e4
JN
85sha1_file() {
86 echo "$*" | sed "s#..#.git/objects/&/#"
87}
88remove_object() {
89 rm -f $(sha1_file "$*")
90}
fb7749e4
JN
91
92test_expect_success '--amend option with empty author' '
93 git cat-file commit Initial >tmp &&
94 sed "s/author [^<]* </author </" tmp >empty-author &&
fb7749e4
JN
95 sha=$(git hash-object -t commit -w empty-author) &&
96 test_when_finished "remove_object $sha" &&
97 git checkout $sha &&
98 test_when_finished "git checkout Initial" &&
99 echo "Empty author test" >>foo &&
100 test_tick &&
ce14e0b2 101 test_must_fail git commit -a -m "empty author" --amend 2>err &&
6789275d 102 test_grep "empty ident" err
fb7749e4
JN
103'
104
105test_expect_success '--amend option with missing author' '
106 git cat-file commit Initial >tmp &&
107 sed "s/author [^<]* </author </" tmp >malformed &&
34959d80 108 sha=$(git hash-object --literally -t commit -w malformed) &&
fb7749e4
JN
109 test_when_finished "remove_object $sha" &&
110 git checkout $sha &&
111 test_when_finished "git checkout Initial" &&
112 echo "Missing author test" >>foo &&
113 test_tick &&
ce14e0b2 114 test_must_fail git commit -a -m "malformed author" --amend 2>err &&
6789275d 115 test_grep "empty ident" err
fb7749e4
JN
116'
117
c51f6cee
EM
118test_expect_success '--reset-author makes the commit ours even with --amend option' '
119 git checkout Initial &&
120 echo "Test 6" >>foo &&
121 test_tick &&
122 git commit -a --reset-author -m "Changed again" --amend &&
123 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
124 author_header HEAD >actual &&
125 test_cmp expect actual &&
126
127 echo "Changed again" >expect &&
128 message_body HEAD >actual &&
129 test_cmp expect actual
130'
131
132test_expect_success '--reset-author and --author are mutually exclusive' '
133 git checkout Initial &&
134 echo "Test 7" >>foo &&
135 test_tick &&
136 test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
137'
138
139test_expect_success '--reset-author should be rejected without -c/-C/--amend' '
140 git checkout Initial &&
141 echo "Test 7" >>foo &&
142 test_tick &&
143 test_must_fail git commit -a --reset-author -m done
144'
145
37f7a857
JS
146test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' '
147 echo "cherry-pick 1a" >>foo &&
148 test_tick &&
149 git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" &&
150 git tag cherry-pick-head &&
52a47aea 151 git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
37f7a857
JS
152 echo "This is a MERGE_MSG" >.git/MERGE_MSG &&
153 echo "cherry-pick 1b" >>foo &&
154 test_tick &&
155 git commit -a &&
156 author_header cherry-pick-head >expect &&
157 author_header HEAD >actual &&
158 test_cmp expect actual &&
159
160 echo "This is a MERGE_MSG" >expect &&
161 message_body HEAD >actual &&
162 test_cmp expect actual
163'
164
165test_expect_success '--reset-author with CHERRY_PICK_HEAD' '
52a47aea 166 git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
37f7a857
JS
167 echo "cherry-pick 2" >>foo &&
168 test_tick &&
169 git commit -am "cherry-pick 2" --reset-author &&
170 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
171 author_header HEAD >actual &&
172 test_cmp expect actual
173'
174
c51f6cee 175test_done