]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4014-format-patch.sh
Add a --cover-letter option to format-patch
[thirdparty/git.git] / t / t4014-format-patch.sh
CommitLineData
ece3c67f
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Format-patch skipping already incorporated patches'
7
8. ./test-lib.sh
9
10test_expect_success setup '
11
12 for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
cd894ee9
JH
13 cat file >elif &&
14 git add file elif &&
ece3c67f
JH
15 git commit -m Initial &&
16 git checkout -b side &&
17
18 for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
cd894ee9
JH
19 chmod +x elif &&
20 git update-index file elif &&
21 git update-index --chmod=+x elif &&
816366e2 22 git commit -m "Side changes #1" &&
ece3c67f
JH
23
24 for i in D E F; do echo "$i"; done >>file &&
25 git update-index file &&
816366e2 26 git commit -m "Side changes #2" &&
982b64e4 27 git tag C2 &&
ece3c67f
JH
28
29 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
30 git update-index file &&
816366e2 31 git commit -m "Side changes #3 with \\n backslash-n in it." &&
ece3c67f
JH
32
33 git checkout master &&
982b64e4
JH
34 git diff-tree -p C2 | git apply --index &&
35 git commit -m "Master accepts moral equivalent of #2"
ece3c67f
JH
36
37'
38
39test_expect_success "format-patch --ignore-if-in-upstream" '
40
41 git format-patch --stdout master..side >patch0 &&
42 cnt=`grep "^From " patch0 | wc -l` &&
8780bd8f 43 test $cnt = 3
ece3c67f
JH
44
45'
46
47test_expect_success "format-patch --ignore-if-in-upstream" '
48
49 git format-patch --stdout \
50 --ignore-if-in-upstream master..side >patch1 &&
51 cnt=`grep "^From " patch1 | wc -l` &&
8780bd8f 52 test $cnt = 2
ece3c67f
JH
53
54'
55
56test_expect_success "format-patch result applies" '
57
58 git checkout -b rebuild-0 master &&
59 git am -3 patch0 &&
60 cnt=`git rev-list master.. | wc -l` &&
8780bd8f 61 test $cnt = 2
ece3c67f
JH
62'
63
64test_expect_success "format-patch --ignore-if-in-upstream result applies" '
65
66 git checkout -b rebuild-1 master &&
67 git am -3 patch1 &&
68 cnt=`git rev-list master.. | wc -l` &&
8780bd8f 69 test $cnt = 2
ece3c67f
JH
70'
71
816366e2
JH
72test_expect_success 'commit did not screw up the log message' '
73
74 git cat-file commit side | grep "^Side .* with .* backslash-n"
75
76'
77
78test_expect_success 'format-patch did not screw up the log message' '
79
80 grep "^Subject: .*Side changes #3 with .* backslash-n" patch0 &&
81 grep "^Subject: .*Side changes #3 with .* backslash-n" patch1
82
83'
84
85test_expect_success 'replay did not screw up the log message' '
86
87 git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
88
89'
90
7d812145
DB
91test_expect_success 'multiple files' '
92
93 rm -rf patches/ &&
94 git checkout side &&
95 git format-patch -o patches/ master &&
96 ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch
97'
98
99test_expect_success 'thread' '
100
101 rm -rf patches/ &&
102 git checkout side &&
103 git format-patch --thread -o patches/ master &&
104 FIRST_MID=$(grep "Message-Id:" patches/0001-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") &&
105 for i in patches/0002-* patches/0003-*
106 do
107 grep "References: $FIRST_MID" $i &&
108 grep "In-Reply-To: $FIRST_MID" $i
109 done
110'
111
112test_expect_success 'thread in-reply-to' '
113
114 rm -rf patches/ &&
115 git checkout side &&
116 git format-patch --in-reply-to="<test.message>" --thread -o patches/ master &&
117 FIRST_MID="<test.message>" &&
118 for i in patches/*
119 do
120 grep "References: $FIRST_MID" $i &&
121 grep "In-Reply-To: $FIRST_MID" $i
122 done
123'
124
a5a27c79
DB
125test_expect_success 'thread cover-letter' '
126
127 rm -rf patches/ &&
128 git checkout side &&
129 git format-patch --cover-letter --thread -o patches/ master &&
130 FIRST_MID=$(grep "Message-Id:" patches/0000-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") &&
131 for i in patches/0001-* patches/0002-* patches/0003-*
132 do
133 grep "References: $FIRST_MID" $i &&
134 grep "In-Reply-To: $FIRST_MID" $i
135 done
136'
137
138test_expect_success 'thread cover-letter in-reply-to' '
139
140 rm -rf patches/ &&
141 git checkout side &&
142 git format-patch --cover-letter --in-reply-to="<test.message>" --thread -o patches/ master &&
143 FIRST_MID="<test.message>" &&
144 for i in patches/*
145 do
146 grep "References: $FIRST_MID" $i &&
147 grep "In-Reply-To: $FIRST_MID" $i
148 done
149'
150
7d812145
DB
151test_expect_success 'excessive subject' '
152
153 rm -rf patches/ &&
154 git checkout side &&
155 for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
156 git update-index file &&
157 git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." &&
158 git format-patch -o patches/ master..side &&
159 ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch
160'
161
ece3c67f 162test_done