sequencer.c: recognize "(cherry picked from ..." as part of s-o-b footer
[git/mingw.git] / t / t3511-cherry-pick-x.sh
blob73da182e1a0294de7f9dd7cdeb88536acf4131c0
1 #!/bin/sh
3 test_description='Test cherry-pick -x and -s'
5 . ./test-lib.sh
7 pristine_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
14 mesg_one_line='base: commit message'
16 mesg_no_footer="$mesg_one_line
18 OneWordBodyThatsNotA-S-o-B"
20 mesg_with_footer="$mesg_no_footer
22 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
23 Signed-off-by: A.U. Thor <author@example.com>
24 Signed-off-by: B.U. Thor <buthor@example.com>"
26 mesg_broken_footer="$mesg_no_footer
28 The signed-off-by string should begin with the words Signed-off-by followed
29 by a colon and space, and then the signers name and email address. e.g.
30 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
32 mesg_with_footer_sob="$mesg_with_footer
33 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
35 mesg_with_cherry_footer="$mesg_with_footer_sob
36 (cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
37 Tested-by: C.U. Thor <cuthor@example.com>"
40 test_expect_success setup '
41 git config advice.detachedhead false &&
42 echo unrelated >unrelated &&
43 git add unrelated &&
44 test_commit initial foo a &&
45 test_commit "$mesg_one_line" foo b mesg-one-line &&
46 git reset --hard initial &&
47 test_commit "$mesg_no_footer" foo b mesg-no-footer &&
48 git reset --hard initial &&
49 test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
50 git reset --hard initial &&
51 test_commit "$mesg_with_footer" foo b mesg-with-footer &&
52 git reset --hard initial &&
53 test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
54 git reset --hard initial &&
55 test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
56 pristine_detach initial &&
57 test_commit conflicting unrelated
60 test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
61 pristine_detach initial &&
62 git cherry-pick -s mesg-one-line &&
63 cat <<-EOF >expect &&
64 $mesg_one_line
66 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
67 EOF
68 git log -1 --pretty=format:%B >actual &&
69 test_cmp expect actual
72 test_expect_failure 'cherry-pick -s inserts blank line after non-conforming footer' '
73 pristine_detach initial &&
74 git cherry-pick -s mesg-broken-footer &&
75 cat <<-EOF >expect &&
76 $mesg_broken_footer
78 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
79 EOF
80 git log -1 --pretty=format:%B >actual &&
81 test_cmp expect actual
84 test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
85 pristine_detach initial &&
86 git cherry-pick -s mesg-no-footer &&
87 cat <<-EOF >expect &&
88 $mesg_no_footer
90 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
91 EOF
92 git log -1 --pretty=format:%B >actual &&
93 test_cmp expect actual
96 test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
97 pristine_detach initial &&
98 git cherry-pick -s mesg-with-footer &&
99 cat <<-EOF >expect &&
100 $mesg_with_footer
101 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
103 git log -1 --pretty=format:%B >actual &&
104 test_cmp expect actual
107 test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
108 pristine_detach initial &&
109 sha1=`git rev-parse mesg-with-footer^0` &&
110 git cherry-pick -x -s mesg-with-footer &&
111 cat <<-EOF >expect &&
112 $mesg_with_footer
113 (cherry picked from commit $sha1)
114 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
116 git log -1 --pretty=format:%B >actual &&
117 test_cmp expect actual
120 test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
121 pristine_detach initial &&
122 git cherry-pick -s mesg-with-footer-sob &&
123 cat <<-EOF >expect &&
124 $mesg_with_footer_sob
126 git log -1 --pretty=format:%B >actual &&
127 test_cmp expect actual
130 test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
131 pristine_detach initial &&
132 sha1=`git rev-parse mesg-with-footer-sob^0` &&
133 git cherry-pick -x -s mesg-with-footer-sob &&
134 cat <<-EOF >expect &&
135 $mesg_with_footer_sob
136 (cherry picked from commit $sha1)
137 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
139 git log -1 --pretty=format:%B >actual &&
140 test_cmp expect actual
143 test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
144 pristine_detach initial &&
145 sha1=`git rev-parse mesg-with-cherry-footer^0` &&
146 git cherry-pick -x mesg-with-cherry-footer &&
147 cat <<-EOF >expect &&
148 $mesg_with_cherry_footer
149 (cherry picked from commit $sha1)
151 git log -1 --pretty=format:%B >actual &&
152 test_cmp expect actual
155 test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
156 pristine_detach initial &&
157 git cherry-pick -s mesg-with-cherry-footer &&
158 cat <<-EOF >expect &&
159 $mesg_with_cherry_footer
160 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
162 git log -1 --pretty=format:%B >actual &&
163 test_cmp expect actual
166 test_done