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