chiark / gitweb /
git-debrebase: test suite: spot any merges which have multiple identical parents
[dgit.git] / tests / lib-gdr
1 #
2
3 : ${GDR_TEST_DEBUG=-D}
4 export GDR_TEST_DEBUG
5
6 t-git-debrebase () {
7         local gdr=${DGIT_GITDEBREBASE_TEST-git-debrebase}
8         : '
9 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
10         $gdr    $GDR_TEST_OPTS $GDR_TEST_DEBUG $t_gdr_xopts "$@"
11         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
12 '
13 }
14
15 t-gdr-good () {
16         local state=$1
17         local beforetag=$2 # say HEAD to skip this check
18         # state should be one of
19         #   laundered
20         #   stitched
21         #   patches
22
23         git diff --quiet ${beforetag-t.before} -- ':.' ':!debian/patches'
24
25         local etype netype bwtip
26
27         case $state in
28         laundered)
29                         etype=Upstream
30                         bwtip=Y:`t-git-debrebase breakwater`
31                 ;;
32         stitched)       etype=Pseudomerge ;;
33         pushed)         etype=AddPatches; netype=Pseudomerge ;;
34         esac
35
36         t-git-debrebase analyse >../anal.check
37         expect=`git rev-parse HEAD`
38         exec <../anal.check
39         local cid ctype info nparents
40         while read cid ctype info; do
41                 : ===== $cid $ctype $info =====
42                 test $cid = $expect
43                 local cetype=$etype
44                 if [ "x$ctype" = "x$etype" ]; then cetype=SAME; fi
45                 local parents="`git log -n1 --pretty=format:%P $cid`"
46                 expect="$parents"
47                 enparents=1
48                 : "$ctype/$cetype" "$parents"
49
50                 case "$ctype/$cetype" in
51                 Pseudomerge/SAME)                       ;;
52                 Packaging/SAME)                         ;;
53                 Packaging/Upstream)                     ;;
54                 AddPatches/SAME)                        ;;
55                 Changelog/Packaging)                    ;;
56                 Changelog/Upstream)                     ;;
57                 Upstream/SAME)                          ;;
58                 Anchor/Upstream)                        ;;
59                 Anchor/Packaging)                       ;;
60                 *)
61                         fail "etype=$etype ctype=$ctype cetype=$cetype $cid"
62                         ;;
63                 esac
64
65                 case "$ctype/$etype" in
66                 Packaging/Upstream|\
67                 Changelog/Upstream)
68                         if [ "x$bwtip" != x ]; then
69                                 test "$bwtip" = "Y:$cid"
70                                 bwtip=''
71                         fi
72                 esac
73
74                 case "$ctype" in
75                 Pseudomerge)
76                         expect=${info#Contributor=}
77                         expect=${expect%% *}
78                         enparents=2
79                         git diff --quiet $expect..$cid
80                         etype=Upstream
81                         ;;
82                 Packaging)
83                         git diff --quiet $expect..$cid -- ':.' ':!debian' 
84                         git diff --quiet $expect..$cid -- ':debian/patches'
85                         etype=Packaging
86                         ;;
87                 AddPatches)
88                         git diff --quiet $expect..$cid -- \
89                                 ':.' ':!debian/patches'
90                         etype=$netype
91                         netype=Upstream
92                         ;;
93                 Changelog)
94                         git diff --quiet $expect..$cid -- \
95                                 ':.' ':!debian/changelog'
96                         etype=Packaging
97                         ;;
98                 Upstream/SAME)
99                         git diff --quiet $expect..$cid -- ':debian'
100                         ;;
101                 Anchor)
102                         break
103                         ;;
104                 esac
105
106                 local cnparents=`printf "%s" "$parents" | wc -w`
107                 test $cnparents = $enparents
108
109                 local cndparents=`
110         for f in $parents; do echo $f; done | sort -u | wc -w
111                                 `
112                 test $cndparents = $cnparents
113
114                 case "$parents" in
115                 *"$expect"*)    ;;
116                 *)              fail 'unexpected parent' ;;
117                 esac
118
119         done
120 }
121
122 t-some-changes () {
123         local token=$1
124
125         t-git-next-date
126
127         echo >>debian/zorkmid "// debian $token"
128         git add debian/zorkmid
129         git commit -m "DEBIAN add zorkmid ($token)"
130
131         echo >>src.c "// upstream $token"
132         git commit -a -m "UPSTREAM edit src.c ($token)"
133
134         for f in debian/zorkmid src.c; do
135                 echo "// both! $token" >>$f
136                 git add $f
137         done
138         git commit -m "MIXED add both ($token)"
139
140         t-git-next-date
141 }
142
143 t-make-new-upstream-tarball () {
144         local uv=$1
145         git checkout make-upstream
146         # leaves ust set to filename of orig tarball
147         echo "upstream $uv" >>docs/README
148         git commit -a -m "upstream $uv tarball"
149         ust=example_$uv.orig.tar.gz
150         git archive -o ../$ust --prefix=example-2.0/ make-upstream
151 }
152
153 t-nmu-upload-1 () {
154         # usage:
155         #  v=<full version>
156         #  nmu-upload-1 <nmubranch>
157         #  gbp pq import or perhaps other similar things
158         #  nmu-upload-2
159         #  maybe make some dgit-covertible commits
160         #  nmu-upload-3
161
162         t-git-next-date
163         nmubranch=$1
164         git checkout -f -b $nmubranch
165         t-git-debrebase
166         t-git-debrebase convert-to-gbp
167         t-git-next-date
168         # now we are on a gbp patched-unapplied branch
169 }
170
171
172 t-nmu-upload-2 () {
173         t-git-next-date
174         t-dch-commit -v $v -m "nmu $nmubranch $v"
175 }
176
177 t-nmu-upload-3 () {
178         t-dch-commit -r sid
179
180         t-dgit -wgf build-source
181
182         cd ..
183         c=${p}_${v}_source.changes
184         debsign -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $c
185         dput -c $tmp/dput.cf test-dummy $c
186
187         t-archive-process-incoming sid
188         t-git-next-date
189         cd $p
190         git checkout master
191 }
192
193 t-nmu-commit-an-upstream-change () {
194         echo >>newsrc.c "// more upstream"
195         git add newsrc.c
196         git commit -m 'UPSTREAM NMU'
197 }
198
199 t-maintainer-commit-some-changes () {
200         t-dch-commit -v$v -m "start $v"
201
202         t-some-changes "maintainer $v"
203         t-git-debrebase
204         t-git-debrebase stitch
205
206         git branch did.maintainer
207
208         t-git-next-date
209 }
210
211 t-nmu-causes-ff-fail () {
212         t-dgit fetch
213
214         t-expect-fail E:'Not.*fast-forward' \
215         git merge --ff-only dgit/dgit/sid
216
217         t-expect-fail E:'-fdiverged.*refs/remotes/dgit/dgit/sid' \
218         t-git-debrebase
219 }
220
221 t-nmu-reconciled-good () {
222         local nmutree=$1
223
224         : 'check that what we have is what is expected'
225
226         git checkout -b compare.nmu origin/master~0
227         git checkout $nmutree .
228         git rm -rf debian/patches
229         git commit -m 'rm patches nmu'
230
231         git checkout -b compare.maintainer origin/master~0
232         git checkout did.maintainer .
233         git rm -rf --ignore-unmatch debian/patches
234         git commit --allow-empty -m 'rm patches maintainer'
235
236         git merge compare.nmu
237         git diff --quiet master
238
239         : 'check that dgit still likes it'
240
241         git checkout master
242         t-dgit -wgf quilt-fixup
243 }