am: match --signoff to the original scripted version
[git/gitweb.git] / t / t7509-commit.sh
blob9ac794052df6ac925733ff8a8852e9759bb0baf0
1 #!/bin/sh
3 # Copyright (c) 2009 Erick Mattos
6 test_description='git commit --reset-author'
8 . ./test-lib.sh
10 author_header () {
11 git cat-file commit "$1" |
12 sed -n -e '/^$/q' -e '/^author /p'
15 message_body () {
16 git cat-file commit "$1" |
17 sed -e '1,/^$/d'
20 test_expect_success '-C option copies authorship and message' '
21 echo "Initial" >foo &&
22 git add foo &&
23 test_tick &&
24 git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
25 git tag Initial &&
26 echo "Test 1" >>foo &&
27 test_tick &&
28 git commit -a -C Initial &&
29 author_header Initial >expect &&
30 author_header HEAD >actual &&
31 test_cmp expect actual &&
33 message_body Initial >expect &&
34 message_body HEAD >actual &&
35 test_cmp expect actual
38 test_expect_success '-C option copies only the message with --reset-author' '
39 echo "Test 2" >>foo &&
40 test_tick &&
41 git commit -a -C Initial --reset-author &&
42 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
43 author_header HEAD >actual &&
44 test_cmp expect actual &&
46 message_body Initial >expect &&
47 message_body HEAD >actual &&
48 test_cmp expect actual
51 test_expect_success '-c option copies authorship and message' '
52 echo "Test 3" >>foo &&
53 test_tick &&
54 EDITOR=: VISUAL=: git commit -a -c Initial &&
55 author_header Initial >expect &&
56 author_header HEAD >actual &&
57 test_cmp expect actual
60 test_expect_success '-c option copies only the message with --reset-author' '
61 echo "Test 4" >>foo &&
62 test_tick &&
63 EDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&
64 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
65 author_header HEAD >actual &&
66 test_cmp expect actual &&
68 message_body Initial >expect &&
69 message_body HEAD >actual &&
70 test_cmp expect actual
73 test_expect_success '--amend option copies authorship' '
74 git checkout Initial &&
75 echo "Test 5" >>foo &&
76 test_tick &&
77 git commit -a --amend -m "amend test" &&
78 author_header Initial >expect &&
79 author_header HEAD >actual &&
80 test_cmp expect actual &&
82 echo "amend test" >expect &&
83 message_body HEAD >actual &&
84 test_cmp expect actual
87 sha1_file() {
88 echo "$*" | sed "s#..#.git/objects/&/#"
90 remove_object() {
91 rm -f $(sha1_file "$*")
93 no_reflog() {
94 cp .git/config .git/config.saved &&
95 echo "[core] logallrefupdates = false" >>.git/config &&
96 test_when_finished "mv -f .git/config.saved .git/config" &&
98 if test -e .git/logs
99 then
100 mv .git/logs . &&
101 test_when_finished "mv logs .git/"
105 test_expect_success '--amend option with empty author' '
106 git cat-file commit Initial >tmp &&
107 sed "s/author [^<]* </author </" tmp >empty-author &&
108 no_reflog &&
109 sha=$(git hash-object -t commit -w empty-author) &&
110 test_when_finished "remove_object $sha" &&
111 git checkout $sha &&
112 test_when_finished "git checkout Initial" &&
113 echo "Empty author test" >>foo &&
114 test_tick &&
115 test_must_fail git commit -a -m "empty author" --amend 2>err &&
116 grep "empty ident" err
119 test_expect_success '--amend option with missing author' '
120 git cat-file commit Initial >tmp &&
121 sed "s/author [^<]* </author </" tmp >malformed &&
122 no_reflog &&
123 sha=$(git hash-object -t commit -w malformed) &&
124 test_when_finished "remove_object $sha" &&
125 git checkout $sha &&
126 test_when_finished "git checkout Initial" &&
127 echo "Missing author test" >>foo &&
128 test_tick &&
129 test_must_fail git commit -a -m "malformed author" --amend 2>err &&
130 grep "empty ident" err
133 test_expect_success '--reset-author makes the commit ours even with --amend option' '
134 git checkout Initial &&
135 echo "Test 6" >>foo &&
136 test_tick &&
137 git commit -a --reset-author -m "Changed again" --amend &&
138 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
139 author_header HEAD >actual &&
140 test_cmp expect actual &&
142 echo "Changed again" >expect &&
143 message_body HEAD >actual &&
144 test_cmp expect actual
147 test_expect_success '--reset-author and --author are mutually exclusive' '
148 git checkout Initial &&
149 echo "Test 7" >>foo &&
150 test_tick &&
151 test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
154 test_expect_success '--reset-author should be rejected without -c/-C/--amend' '
155 git checkout Initial &&
156 echo "Test 7" >>foo &&
157 test_tick &&
158 test_must_fail git commit -a --reset-author -m done
161 test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' '
162 echo "cherry-pick 1a" >>foo &&
163 test_tick &&
164 git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" &&
165 git tag cherry-pick-head &&
166 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
167 echo "This is a MERGE_MSG" >.git/MERGE_MSG &&
168 echo "cherry-pick 1b" >>foo &&
169 test_tick &&
170 git commit -a &&
171 author_header cherry-pick-head >expect &&
172 author_header HEAD >actual &&
173 test_cmp expect actual &&
175 echo "This is a MERGE_MSG" >expect &&
176 message_body HEAD >actual &&
177 test_cmp expect actual
180 test_expect_success '--reset-author with CHERRY_PICK_HEAD' '
181 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
182 echo "cherry-pick 2" >>foo &&
183 test_tick &&
184 git commit -am "cherry-pick 2" --reset-author &&
185 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
186 author_header HEAD >actual &&
187 test_cmp expect actual
190 test_done