]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t7509-commit-authorship.sh
3 # Copyright (c) 2009 Erick Mattos
6 test_description
='commit tests of various authorhip options. '
11 git cat-file commit
"$1" |
12 sed -n -e '/^$/q' -e '/^author /p'
16 git cat-file commit
"$1" |
20 test_expect_success
'-C option copies authorship and message' '
21 echo "Initial" >foo &&
24 git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
26 echo "Test 1" >>foo &&
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 &&
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 &&
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 &&
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 &&
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
88 echo "$*" |
sed "s#..#.git/objects/&/#"
91 rm -f $
(sha1_file
"$*")
94 test_expect_success
'--amend option with empty author' '
95 git cat-file commit Initial >tmp &&
96 sed "s/author [^<]* </author </" tmp >empty-author &&
97 sha=$(git hash-object -t commit -w empty-author) &&
98 test_when_finished "remove_object $sha" &&
100 test_when_finished "git checkout Initial" &&
101 echo "Empty author test" >>foo &&
103 test_must_fail git commit -a -m "empty author" --amend 2>err &&
104 test_i18ngrep "empty ident" err
107 test_expect_success
'--amend option with missing author' '
108 git cat-file commit Initial >tmp &&
109 sed "s/author [^<]* </author </" tmp >malformed &&
110 sha=$(git hash-object -t commit -w malformed) &&
111 test_when_finished "remove_object $sha" &&
113 test_when_finished "git checkout Initial" &&
114 echo "Missing author test" >>foo &&
116 test_must_fail git commit -a -m "malformed author" --amend 2>err &&
117 test_i18ngrep "empty ident" err
120 test_expect_success
'--reset-author makes the commit ours even with --amend option' '
121 git checkout Initial &&
122 echo "Test 6" >>foo &&
124 git commit -a --reset-author -m "Changed again" --amend &&
125 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
126 author_header HEAD >actual &&
127 test_cmp expect actual &&
129 echo "Changed again" >expect &&
130 message_body HEAD >actual &&
131 test_cmp expect actual
134 test_expect_success
'--reset-author and --author are mutually exclusive' '
135 git checkout Initial &&
136 echo "Test 7" >>foo &&
138 test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
141 test_expect_success
'--reset-author should be rejected without -c/-C/--amend' '
142 git checkout Initial &&
143 echo "Test 7" >>foo &&
145 test_must_fail git commit -a --reset-author -m done
148 test_expect_success
'commit respects CHERRY_PICK_HEAD and MERGE_MSG' '
149 echo "cherry-pick 1a" >>foo &&
151 git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" &&
152 git tag cherry-pick-head &&
153 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
154 echo "This is a MERGE_MSG" >.git/MERGE_MSG &&
155 echo "cherry-pick 1b" >>foo &&
158 author_header cherry-pick-head >expect &&
159 author_header HEAD >actual &&
160 test_cmp expect actual &&
162 echo "This is a MERGE_MSG" >expect &&
163 message_body HEAD >actual &&
164 test_cmp expect actual
167 test_expect_success
'--reset-author with CHERRY_PICK_HEAD' '
168 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
169 echo "cherry-pick 2" >>foo &&
171 git commit -am "cherry-pick 2" --reset-author &&
172 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
173 author_header HEAD >actual &&
174 test_cmp expect actual