2a040b7664d7b3ed72154e1ba8c8599913b2b2a1
1#!/bin/sh
2
3test_description='Test cherry-pick -x and -s'
4
5. ./test-lib.sh
6
7pristine_detach () {
8 git cherry-pick --quit &&
9 git checkout -f "$1^0" &&
10 git read-tree -u --reset HEAD &&
11 git clean -d -f -f -q -x
12}
13
14mesg_one_line='base: commit message'
15
16mesg_no_footer="$mesg_one_line
17
18OneWordBodyThatsNotA-S-o-B"
19
20mesg_with_footer="$mesg_no_footer
21
22Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
23Signed-off-by: A.U. Thor <author@example.com>
24Signed-off-by: B.U. Thor <buthor@example.com>"
25
26mesg_broken_footer="$mesg_no_footer
27
28The signed-off-by string should begin with the words Signed-off-by followed
29by a colon and space, and then the signers name and email address. e.g.
30Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
31
32mesg_with_footer_sob="$mesg_with_footer
33Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
34
35
36test_expect_success setup '
37 git config advice.detachedhead false &&
38 echo unrelated >unrelated &&
39 git add unrelated &&
40 test_commit initial foo a &&
41 test_commit "$mesg_one_line" foo b mesg-one-line &&
42 git reset --hard initial &&
43 test_commit "$mesg_no_footer" foo b mesg-no-footer &&
44 git reset --hard initial &&
45 test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
46 git reset --hard initial &&
47 test_commit "$mesg_with_footer" foo b mesg-with-footer &&
48 git reset --hard initial &&
49 test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
50 pristine_detach initial &&
51 test_commit conflicting unrelated
52'
53
54test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
55 pristine_detach initial &&
56 git cherry-pick -s mesg-one-line &&
57 cat <<-EOF >expect &&
58 $mesg_one_line
59
60 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
61 EOF
62 git log -1 --pretty=format:%B >actual &&
63 test_cmp expect actual
64'
65
66test_expect_failure 'cherry-pick -s inserts blank line after non-conforming footer' '
67 pristine_detach initial &&
68 git cherry-pick -s mesg-broken-footer &&
69 cat <<-EOF >expect &&
70 $mesg_broken_footer
71
72 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
73 EOF
74 git log -1 --pretty=format:%B >actual &&
75 test_cmp expect actual
76'
77
78test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
79 pristine_detach initial &&
80 git cherry-pick -s mesg-no-footer &&
81 cat <<-EOF >expect &&
82 $mesg_no_footer
83
84 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
85 EOF
86 git log -1 --pretty=format:%B >actual &&
87 test_cmp expect actual
88'
89
90test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
91 pristine_detach initial &&
92 git cherry-pick -s mesg-with-footer &&
93 cat <<-EOF >expect &&
94 $mesg_with_footer
95 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
96 EOF
97 git log -1 --pretty=format:%B >actual &&
98 test_cmp expect actual
99'
100
101test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
102 pristine_detach initial &&
103 git cherry-pick -s mesg-with-footer-sob &&
104 cat <<-EOF >expect &&
105 $mesg_with_footer_sob
106 EOF
107 git log -1 --pretty=format:%B >actual &&
108 test_cmp expect actual
109'
110
111test_done