Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t7509-commit-authorship.sh
blobfd8c8f8f0bccf81eed7711e178912753ac200d72
1 #!/bin/sh
3 # Copyright (c) 2009 Erick Mattos
6 test_description='commit tests of various authorhip options. '
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 author_header () {
12 git cat-file commit "$1" |
13 sed -n -e '/^$/q' -e '/^author /p'
16 message_body () {
17 git cat-file commit "$1" |
18 sed -e '1,/^$/d'
21 test_expect_success '-C option copies authorship and message' '
22 test_commit --author Frigate\ \<flying@over.world\> \
23 "Initial Commit" foo Initial Initial &&
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 &&
31 message_body Initial >expect &&
32 message_body HEAD >actual &&
33 test_cmp expect actual
36 test_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 &&
41 author_header HEAD >actual &&
42 test_cmp expect actual &&
44 message_body Initial >expect &&
45 message_body HEAD >actual &&
46 test_cmp expect actual
49 test_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
58 test_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 &&
66 message_body Initial >expect &&
67 message_body HEAD >actual &&
68 test_cmp expect actual
71 test_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 &&
78 test_cmp expect actual &&
80 echo "amend test" >expect &&
81 message_body HEAD >actual &&
82 test_cmp expect actual
85 sha1_file() {
86 echo "$*" | sed "s#..#.git/objects/&/#"
88 remove_object() {
89 rm -f $(sha1_file "$*")
92 test_expect_success '--amend option with empty author' '
93 git cat-file commit Initial >tmp &&
94 sed "s/author [^<]* </author </" tmp >empty-author &&
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 &&
101 test_must_fail git commit -a -m "empty author" --amend 2>err &&
102 test_grep "empty ident" err
105 test_expect_success '--amend option with missing author' '
106 git cat-file commit Initial >tmp &&
107 sed "s/author [^<]* </author </" tmp >malformed &&
108 sha=$(git hash-object --literally -t commit -w malformed) &&
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 &&
114 test_must_fail git commit -a -m "malformed author" --amend 2>err &&
115 test_grep "empty ident" err
118 test_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 &&
127 echo "Changed again" >expect &&
128 message_body HEAD >actual &&
129 test_cmp expect actual
132 test_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>"
139 test_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
146 test_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 &&
151 git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
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 &&
160 echo "This is a MERGE_MSG" >expect &&
161 message_body HEAD >actual &&
162 test_cmp expect actual
165 test_expect_success '--reset-author with CHERRY_PICK_HEAD' '
166 git update-ref CHERRY_PICK_HEAD $(git rev-parse cherry-pick-head) &&
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
175 test_done