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 test_commit --author Frigate\ \<flying@over.world\> \
22 "Initial Commit" foo Initial Initial &&
23 echo "Test 1" >>foo &&
25 git commit -a -C Initial &&
26 author_header Initial >expect &&
27 author_header HEAD >actual &&
28 test_cmp expect actual &&
30 message_body Initial >expect &&
31 message_body HEAD >actual &&
32 test_cmp expect actual
35 test_expect_success '-C option copies only the message with --reset-author' '
36 echo "Test 2" >>foo &&
38 git commit -a -C Initial --reset-author &&
39 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
40 author_header HEAD >actual &&
41 test_cmp expect actual &&
43 message_body Initial >expect &&
44 message_body HEAD >actual &&
45 test_cmp expect actual
48 test_expect_success '-c option copies authorship and message' '
49 echo "Test 3" >>foo &&
51 EDITOR=: VISUAL=: git commit -a -c Initial &&
52 author_header Initial >expect &&
53 author_header HEAD >actual &&
54 test_cmp expect actual
57 test_expect_success '-c option copies only the message with --reset-author' '
58 echo "Test 4" >>foo &&
60 EDITOR=: VISUAL=: git commit -a -c Initial --reset-author &&
61 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
62 author_header HEAD >actual &&
63 test_cmp expect actual &&
65 message_body Initial >expect &&
66 message_body HEAD >actual &&
67 test_cmp expect actual
70 test_expect_success '--amend option copies authorship' '
71 git checkout Initial &&
72 echo "Test 5" >>foo &&
74 git commit -a --amend -m "amend test" &&
75 author_header Initial >expect &&
76 author_header HEAD >actual &&
77 test_cmp expect actual &&
79 echo "amend test" >expect &&
80 message_body HEAD >actual &&
81 test_cmp expect actual
85 echo "$*" | sed "s#..#.git/objects/&/#"
88 rm -f $(sha1_file "$*")
91 test_expect_success '--amend option with empty author' '
92 git cat-file commit Initial >tmp &&
93 sed "s/author [^<]* </author </" tmp >empty-author &&
94 sha=$(git hash-object -t commit -w empty-author) &&
95 test_when_finished "remove_object $sha" &&
97 test_when_finished "git checkout Initial" &&
98 echo "Empty author test" >>foo &&
100 test_must_fail git commit -a -m "empty author" --amend 2>err &&
101 test_i18ngrep "empty ident" err
104 test_expect_success '--amend option with missing author' '
105 git cat-file commit Initial >tmp &&
106 sed "s/author [^<]* </author </" tmp >malformed &&
107 sha=$(git hash-object -t commit -w malformed) &&
108 test_when_finished "remove_object $sha" &&
110 test_when_finished "git checkout Initial" &&
111 echo "Missing author test" >>foo &&
113 test_must_fail git commit -a -m "malformed author" --amend 2>err &&
114 test_i18ngrep "empty ident" err
117 test_expect_success '--reset-author makes the commit ours even with --amend option' '
118 git checkout Initial &&
119 echo "Test 6" >>foo &&
121 git commit -a --reset-author -m "Changed again" --amend &&
122 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
123 author_header HEAD >actual &&
124 test_cmp expect actual &&
126 echo "Changed again" >expect &&
127 message_body HEAD >actual &&
128 test_cmp expect actual
131 test_expect_success '--reset-author and --author are mutually exclusive' '
132 git checkout Initial &&
133 echo "Test 7" >>foo &&
135 test_must_fail git commit -a --reset-author --author="Xyzzy <frotz@nitfol.xz>"
138 test_expect_success '--reset-author should be rejected without -c/-C/--amend' '
139 git checkout Initial &&
140 echo "Test 7" >>foo &&
142 test_must_fail git commit -a --reset-author -m done
145 test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' '
146 echo "cherry-pick 1a" >>foo &&
148 git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" &&
149 git tag cherry-pick-head &&
150 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
151 echo "This is a MERGE_MSG" >.git/MERGE_MSG &&
152 echo "cherry-pick 1b" >>foo &&
155 author_header cherry-pick-head >expect &&
156 author_header HEAD >actual &&
157 test_cmp expect actual &&
159 echo "This is a MERGE_MSG" >expect &&
160 message_body HEAD >actual &&
161 test_cmp expect actual
164 test_expect_success '--reset-author with CHERRY_PICK_HEAD' '
165 git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD &&
166 echo "cherry-pick 2" >>foo &&
168 git commit -am "cherry-pick 2" --reset-author &&
169 echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect &&
170 author_header HEAD >actual &&
171 test_cmp expect actual