chiark / gitweb /
Document multisuite
[dgit.git] / dgit-maint-merge.7.pod
1 =head1 NAME
2
3 dgit - tutorial for package maintainers, using a workflow centered around git-merge(1)
4
5 =head1 INTRODUCTION
6
7 This document describes elements of a workflow for maintaining a
8 non-native Debian package using B<dgit>.  The workflow makes the
9 following opinionated assumptions:
10
11 =over 4
12
13 =item
14
15 Git histories should be the non-linear histories produced by
16 git-merge(1), preserving all information about divergent development
17 that was later brought together.
18
19 =item
20
21 Maintaining convenient and powerful git workflows takes priority over
22 the usefulness of the raw Debian source package.  The Debian archive
23 is thought of as an output format.
24
25 For example, we don't spend time curating a series of quilt patches.
26 However, the information such a series would contain is readily
27 available from B<dgit-repos>.
28
29 =item
30
31 It is more important to have the Debian package's git history be a
32 descendent of upstream's git history than to use exactly the orig.tar
33 that upstream makes available for download.
34
35 =back
36
37 =head1 GIT CONFIGURATION
38
39 Add the following to your ~/.gitconfig to teach git-archive(1) how to
40 compress orig tarballs:
41
42 =over 4
43
44     [tar "tar.xz"]
45         command = xz -c
46     [tar "tar.gz"]
47         command = gzip -c
48
49 =back
50
51 =head1 INITIAL DEBIANISATION
52
53 =head2 When upstream tags releases in git
54
55 Suppose that the latest stable upstream release is 1.2.2, and this has
56 been tagged '1.2.2' by upstream.
57
58 =over 4
59
60     % git clone -oupstream https://some.upstream/foo.git
61     % cd foo
62     % git verify-tag 1.2.2
63     % git reset --hard 1.2.2
64     % git branch --unset-upstream
65
66 =back
67
68 The final command detachs your master branch from the upstream remote,
69 so that git doesn't try to push anything there, or merge unreleased
70 upstream commits.  If you want to maintain a copy of your packaging
71 branch on B<alioth.debian.org> in addition to B<dgit-repos>, you can
72 do something like this:
73
74 =over 4
75
76     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
77     % git push --follow-tags -u origin master
78
79 =back
80
81 Now go ahead and Debianise your package.  Just make commits on the
82 master branch, adding things in the I<debian/> directory.  If you need
83 to patch the upstream source, just make commits that change files
84 outside of the I<debian/> directory.  It is best to separate commits
85 that touch I<debian/> from commits that touch upstream source, so that
86 the latter can be cherry-picked by upstream.
87
88 Note that there is no need to maintain a separate 'upstream' branch,
89 unless you also happen to be involved in upstream development.  We
90 work with upstream tags rather than any branches, except when
91 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
92
93 Finally, you need an orig tarball.  Generate one with git-archive(1):
94
95 =over 4
96
97     % git archive -o ../foo_1.2.2.orig.tar.xz 1.2.2
98
99 =back
100
101 If you are using the version 1.0 source package format, replace 'xz'
102 with 'gz'.
103
104 This tarball is ephemeral and easily regenerated, so we don't commit
105 it anywhere (e.g. with tools like pristine-tar(1)).
106
107 =head3 Verifying upstream's tarball releases
108
109 =over 4
110
111 It can be a good idea to compare upstream's released tarballs with the
112 release tags, at least for the first upload of the package.  If they
113 are different, you might need to add some additional steps to your
114 I<debian/rules>, such as running autotools.
115
116 A convenient way to perform this check is to import the tarball as
117 described in the following section, using a different value for
118 'upstream-tag', and then use git-diff(1) to compare the imported
119 tarball to the release tag.  If they are the same, you can use
120 upstream's tarball instead of running git-archive(1).
121
122 =back
123
124 =head2 When upstream releases only tarballs
125
126 We need a virtual upstream branch with virtual release tags.
127 gbp-import-orig(1) can manage this for us.  To begin
128
129 =over 4
130
131     % mkdir foo
132     % cd foo
133     % git init
134
135 =back
136
137 Now create I<debian/gbp.conf>:
138
139 =over 4
140
141     [DEFAULT]
142     upstream-branch = upstream
143     debian-branch = master
144     upstream-tag = %(version)s
145
146     sign-tags = True
147     pristine-tar = False
148     pristine-tar-commit = False
149
150 =back
151
152 Then we can import the upstream version:
153
154 =over 4
155
156     % git add debian/gbp.conf && git commit -m "create gbp.conf"
157     % gbp import-orig ../foo_1.2.2.orig.tar.xz
158
159 =back
160
161 You are now ready to proceed as above, making commits to both the
162 upstream source and the I<debian/> directory.
163
164 If you want to maintain a copy of your repository on
165 B<alioth.debian.org>, you should push both the origin and the upstream
166 branches:
167
168 =over 4
169
170     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
171     % git push --follow-tags -u origin master upstream
172
173 =back
174
175 =head1 SOURCE PACKAGE CONFIGURATION
176
177 =head2 debian/source/options
178
179 We set some source package options such that dgit can transparently
180 handle the "dropping" and "refreshing" of changes to the upstream
181 source:
182
183 =over 4
184
185     single-debian-patch
186     auto-commit
187
188 =back
189
190 You don't need to create this file if you are using the version 1.0
191 source package format.
192
193 =head2 Sample text for README.source
194
195 It is a good idea to explain how a user can obtain a break down of the
196 changes to the upstream source:
197
198 =over 4
199
200 The Debian packaging of foo is maintained using dgit.  For the sake of
201 an efficient workflow, Debian modifications to the upstream source are
202 squashed into a single diff, rather than a series of quilt patches.
203 To obtain a patch queue for package version 1.2.3-1:
204
205 =over 4
206
207     # apt-get install dgit
208     % dgit clone foo
209     % cd foo
210     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
211
212 =back
213
214 See dgit(1), dgit(7) and dgit-maint-merge(7) for more information.
215
216 =back
217
218 =head1 BUILDING AND UPLOADING
219
220 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
221 push> as detailed in dgit(1).  If any command fails, dgit will provide
222 a carefully-worded error message explaining what you should do.  If
223 it's not clear, file a bug against dgit.  Remember to pass I<--new>
224 for the first upload.
225
226 As an alternative to B<dgit build> and friends, you can use a tool
227 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
228 HEAD has exactly the contents of the source package.  gitpkg(1) is
229 highly configurable, and one dgit user reports using it to produce and
230 test multiple source packages, from different branches corresponding
231 to each of the current Debian suites.
232
233 If you want to skip dgit's checks while iterating on a problem with
234 the package build (for example, you don't want to commit your changes
235 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
236
237 =head1 NEW UPSTREAM RELEASES
238
239 =head2 When upstream tags releases in git
240
241 It's a good idea to preview the merge of the new upstream release.
242 First, just check for any new or deleted files that may need
243 accounting for in your copyright file:
244
245 =over 4
246
247     % git remote update
248     % git diff --stat master..1.2.3 -- . ':!debian'
249
250 =back
251
252 You can then review the full merge diff:
253
254 =over 4
255
256     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
257
258 =back
259
260 Once you're satisfied with what will be merged, update your package:
261
262 =over 4
263
264     % git archive ../foo_1.2.3.orig.tar.xz 1.2.3
265     % git merge 1.2.3
266     % dch -v1.2.3-1 New upstream release.
267     % git add debian/changelog && git commit -m changelog
268
269 =back
270
271 and you are ready to try a build.
272
273 Again, if you are using the version 1.0 source package format, replace
274 'xz' with 'gz'.
275
276 =head2 When upstream releases only tarballs
277
278 Either
279
280 =over 4
281
282     % gbp import-orig ../foo_1.2.2.orig.tar.xz
283
284 =back
285
286 or if you have a working watch file
287
288 =over 4
289
290     % gbp import-orig --uscan
291
292 =back
293
294 =head1 HANDLING DFSG-NON-FREE MATERIAL
295
296 =head2 When upstream tags releases in git
297
298 We create a DFSG-clean tag to merge to master:
299
300 =over 4
301
302     % git checkout -b pre-dfsg 1.2.3
303     % git rm evil.bin
304     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
305     % git tag -s 1.2.3+dfsg
306     % git checkout master
307     % git branch -D pre-dfsg
308
309 =back
310
311 Before merging the new 1.2.3+dfsg tag to master, you should first
312 determine whether it would be legally dangerous for the non-free
313 material to be publicly accessible in the git history on
314 B<dgit-repos>.
315
316 If it would be dangerous, there is a big problem;
317 in this case please consult your archive administrators
318 (for Debian this is the dgit administrator dgit-owner@debian.org
319 and the ftpmasters ftpmaster@ftp-master.debian.org).
320
321 =head2 When upstream releases only tarballs
322
323 The easiest way to handle this is to add a B<Files-Excluded> field to
324 I<debian/copyright>, and a B<uversionmangle> setting in
325 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
326 option detailed in gbp-import-orig(1).
327
328 =head1 FORWARDING PATCHES UPSTREAM
329
330 The basic steps are:
331
332 =over 4
333
334 =item 1.
335
336 Create a new branch based off upstream's master branch.
337
338 =item 2.
339
340 git-cherry-pick(1) commits from your master branch onto your new
341 branch.
342
343 =item 3.
344
345 Push the branch somewhere and ask upstream to merge it, or use
346 git-format-patch(1) or git-request-pull(1).
347
348 =back
349
350 For example (and it is only an example):
351
352 =over 4
353
354     % # fork foo.git on GitHub
355     % git remote add -f fork git@github.com:spwhitton/foo.git
356     % git checkout -b fix-error upstream/master
357     % git config branch.fix-error.pushRemote fork
358     % git cherry-pick master^2
359     % git push
360     % # submit pull request on GitHub
361
362 =back
363
364 Note that when you merge an upstream release containing your forwarded
365 patches, git and dgit will transparently handle "dropping" the patches
366 that have been forwarded, "retaining" the ones that haven't.
367
368 =head1 INCORPORATING NMUS
369
370 =over 4
371
372     % dgit pull
373
374 =back
375
376 Alternatively, you can apply the NMU diff to your repository.  The
377 next push will then require I<--overwrite>.
378
379 =head1 SEE ALSO
380
381 dgit(1), dgit(7)
382
383 =head1 AUTHOR
384
385 This tutorial was written and is maintained by Sean Whitton <spwhitton@spwhitton.name>.  It contains contributions from other dgit contributors too - see the dgit copyright file.