t/t3511: add some tests of 'cherry-pick -s' functionality

Add some tests to ensure that 'cherry-pick -s' operates in the following manner: * Inserts a blank line before appending a s-o-b to a commit message that does not contain a s-o-b footer * Does not mistake first line "subject: description" as a s-o-b footer * Does not mistake single word message body as conforming to rfc2822 * Appends a s-o-b when last s-o-b in footer does not match committer s-o-b, even when committer's s-o-b exists elsewhere in footer. * Does not append a s-o-b when last s-o-b matches committer s-o-b * Correctly detects a non-conforming footer containing a mix of s-o-b like elements and s-o-b elements. (marked "expect failure") Signed-off-by: Brandon Casey <bcasey@nvidia.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Feb 12, 2013 at 02:17 UTC f2b9a7555bb7791fa8d137da033b403d16af5085
1 file changed +111
t/t3511-cherry-pick-x.sh new
+111
@@ -0,0 +1,111 @@
1 +#!/bin/sh
2 +
3 +test_description='Test cherry-pick -x and -s'
4 +
5 +. ./test-lib.sh
6 +
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
12 +}
13 +
14 +mesg_one_line='base: commit message'
15 +
16 +mesg_no_footer="$mesg_one_line
17 +
18 +OneWordBodyThatsNotA-S-o-B"
19 +
20 +mesg_with_footer="$mesg_no_footer
21 +
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>"
25 +
26 +mesg_broken_footer="$mesg_no_footer
27 +
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>"
31 +
32 +mesg_with_footer_sob="$mesg_with_footer
33 +Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
34 +
35 +
36 +test_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 +
54 +test_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 +
66 +test_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 +
78 +test_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 +
90 +test_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 +
101 +test_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 +
111 +test_done