chiark / gitweb /
ed7cdc060fac83be63547f2f9e60c605a8a13490
[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,
27 in straightforward cases,
28 the information such a series would contain is readily
29 available from B<dgit-repos>.
30
31 =item
32
33 It is more important to have the Debian package's git history be a
34 descendent of upstream's git history than to use exactly the orig.tar
35 that upstream makes available for download.
36
37 =back
38
39 This workflow is less suitable for some packages.
40 When the Debian delta contains multiple pieces which interact,
41 or which you aren't going to be able to upstream soon,
42 it might be preferable to
43 maintain the delta as a rebasing patch series.
44 For such a workflow see for example
45 dgit-maint-gbp(7).
46
47 =head1 INITIAL DEBIANISATION
48
49 This section explains how to start using this workflow with a new
50 package.  It should be skipped when converting an existing package to
51 this workflow.
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 detaches 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:
94
95 =over 4
96
97     % git deborig
98
99 =back
100
101 See git-deborig(1) if this fails.
102
103 This tarball is ephemeral and easily regenerated, so we don't commit
104 it anywhere (e.g. with tools like pristine-tar(1)).
105
106 =head3 Verifying upstream's tarball releases
107
108 =over 4
109
110 It can be a good idea to compare upstream's released tarballs with the
111 release tags, at least for the first upload of the package.  If they
112 are different, you might need to add some additional steps to your
113 I<debian/rules>, such as running autotools.
114
115 A convenient way to perform this check is to import the tarball as
116 described in the following section, using a different value for
117 'upstream-tag', and then use git-diff(1) to compare the imported
118 tarball to the release tag.  If they are the same, you can use
119 upstream's tarball instead of running git-deborig(1).
120
121 =back
122
123 =head2 When upstream releases only tarballs
124
125 We need a virtual upstream branch with virtual release tags.
126 gbp-import-orig(1) can manage this for us.  To begin
127
128 =over 4
129
130     % mkdir foo
131     % cd foo
132     % git init
133
134 =back
135
136 Now create I<debian/gbp.conf>:
137
138 =over 4
139
140     [DEFAULT]
141     upstream-branch = upstream
142     debian-branch = master
143     upstream-tag = %(version)s
144
145     sign-tags = True
146     pristine-tar = False
147     pristine-tar-commit = False
148
149     [import-orig]
150     merge-mode = merge
151
152 =back
153
154 gbp-import-orig(1) requires a pre-existing upstream branch:
155
156 =over 4
157
158     % git add debian/gbp.conf && git commit -m "create gbp.conf"
159     % git checkout --orphan upstream
160     % git rm -rf .
161     % git commit --allow-empty -m "initial, empty branch for upstream source"
162     % git checkout -f master
163
164 =back
165
166 Then we can import the upstream version:
167
168 =over 4
169
170     % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
171
172 =back
173
174 You are now ready to proceed as above, making commits to both the
175 upstream source and the I<debian/> directory.
176
177 If you want to maintain a copy of your repository on
178 B<alioth.debian.org>, you should push both the origin and the upstream
179 branches:
180
181 =over 4
182
183     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
184     % git push --follow-tags -u origin master upstream
185
186 =back
187
188 =head1 CONVERTING AN EXISTING PACKAGE
189
190 This section explains how to convert an existing Debian package to
191 this workflow.  It should be skipped when debianising a new package.
192
193 =head2 No existing git history
194
195 =over 4
196
197     % dgit clone foo
198     % cd foo
199     % git remote add -f upstream https://some.upstream/foo.git
200
201 =back
202
203 =head2 Existing git history using another workflow
204
205 First, dump any existing patch queue:
206
207 =over 4
208
209     % git rm -rf debian/patches
210     % git commit -m "drop existing quilt patch queue"
211
212 =back
213
214 Then make new upstream tags available:
215
216 =over 4
217
218     % git remote add -f upstream https://some.upstream/foo.git
219
220 =back
221
222 =for dgit-test dpkg-source-ignores begin
223
224 Now you simply need to ensure that your git HEAD is dgit-compatible,
225 i.e., it is exactly what you would get if you ran
226 B<dpkg-buildpackage -i'(?:^|/)\.git(?:/|$)' -I.git -S>
227 and then unpacked the resultant source package.
228
229 =for dgit-test dpkg-source-ignores end
230
231 To achieve this, you might need to delete
232 I<debian/source/local-options>.  One way to have dgit check your
233 progress is to run B<dgit build-source>.
234
235 The first dgit push will require I<--overwrite>.
236
237 =head1 SOURCE PACKAGE CONFIGURATION
238
239 =head2 debian/source/options
240
241 We set some source package options such that dgit can transparently
242 handle the "dropping" and "refreshing" of changes to the upstream
243 source:
244
245 =over 4
246
247     single-debian-patch
248     auto-commit
249
250 =back
251
252 You don't need to create this file if you are using the version 1.0
253 source package format.
254
255 =head2 Sample text for debian/source/patch-header
256
257 It is a good idea to explain how a user can obtain a breakdown of the
258 changes to the upstream source:
259
260 =over 4
261
262 The Debian packaging of foo is maintained in git,
263 using the merging workflow described in dgit-maint-merge(7).
264 There isn't a patch queue that can be represented as a quilt series.
265
266 A detailed breakdown of the changes is available from their
267 canonical representation -
268 git commits in the packaging repository.
269 For example, to see the changes made by the Debian maintainer in the
270 first upload of upstream version 1.2.3, you could use:
271
272 =over 4
273
274     % git clone https://git.dgit.debian.org/foo
275     % cd foo
276     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
277
278 =back
279
280 (If you have dgit, use `dgit clone foo`,
281 rather than plain `git clone`.)
282
283 A single combined diff, containing all the changes, follows.
284
285 =back
286
287 Alternatively, this text could be added to README.source. However,
288 this might distract from more important information present in the
289 latter file.
290
291 =head1 BUILDING AND UPLOADING
292
293 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
294 push> as detailed in dgit(1).  If any command fails, dgit will provide
295 a carefully-worded error message explaining what you should do.  If
296 it's not clear, file a bug against dgit.  Remember to pass I<--new>
297 for the first upload.
298
299 As an alternative to B<dgit build> and friends, you can use a tool
300 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
301 HEAD has exactly the contents of the source package.  gitpkg(1) is
302 highly configurable, and one dgit user reports using it to produce and
303 test multiple source packages, from different branches corresponding
304 to each of the current Debian suites.
305
306 If you want to skip dgit's checks while iterating on a problem with
307 the package build (for example, you don't want to commit your changes
308 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
309
310 =head1 NEW UPSTREAM RELEASES
311
312 =head2 Obtaining the release
313
314 =head3 When upstream tags releases in git
315
316 =over 4
317
318     % git remote update
319
320 =back
321
322 =head3 When upstream releases only tarballs
323
324 You will need the I<debian/gbp.conf> from "When upstream releases only
325 tarballs", above.
326
327 Then, either
328
329 =over 4
330
331     % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
332
333 =back
334
335 or if you have a working watch file
336
337 =over 4
338
339     % gbp import-orig --no-merge --uscan
340
341 =back
342
343 =head2 Reviewing & merging the release
344
345 It's a good idea to preview the merge of the new upstream release.
346 First, just check for any new or deleted files that may need
347 accounting for in your copyright file:
348
349 =over 4
350
351     % git diff --stat master..1.2.3 -- . ':!debian'
352
353 =back
354
355 You can then review the full merge diff:
356
357 =over 4
358
359     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
360
361 =back
362
363 Once you're satisfied with what will be merged, update your package:
364
365 =over 4
366
367     % git merge 1.2.3
368     % dch -v1.2.3-1 New upstream release.
369     % git add debian/changelog && git commit -m changelog
370
371 =back
372
373 If you obtained a tarball from upstream, you are ready to try a build.
374 If you merged a git tag from upstream, you will first need to generate
375 a tarball:
376
377 =over 4
378
379     % git deborig
380
381 =back
382
383 =head1 HANDLING DFSG-NON-FREE MATERIAL
384
385 =head2 When upstream tags releases in git
386
387 We create a DFSG-clean tag to merge to master:
388
389 =over 4
390
391     % git checkout -b pre-dfsg 1.2.3
392     % git rm evil.bin
393     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
394     % git tag -s 1.2.3+dfsg
395     % git checkout master
396     % git branch -D pre-dfsg
397
398 =back
399
400 Before merging the new 1.2.3+dfsg tag to master, you should first
401 determine whether it would be legally dangerous for the non-free
402 material to be publicly accessible in the git history on
403 B<dgit-repos>.
404
405 If it would be dangerous, there is a big problem;
406 in this case please consult your archive administrators
407 (for Debian this is the dgit administrator dgit-owner@debian.org
408 and the ftpmasters ftpmaster@ftp-master.debian.org).
409
410 =head2 When upstream releases only tarballs
411
412 The easiest way to handle this is to add a B<Files-Excluded> field to
413 I<debian/copyright>, and a B<uversionmangle> setting in
414 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
415 option detailed in gbp-import-orig(1).
416
417 =head1 FORWARDING PATCHES UPSTREAM
418
419 The basic steps are:
420
421 =over 4
422
423 =item 1.
424
425 Create a new branch based off upstream's master branch.
426
427 =item 2.
428
429 git-cherry-pick(1) commits from your master branch onto your new
430 branch.
431
432 =item 3.
433
434 Push the branch somewhere and ask upstream to merge it, or use
435 git-format-patch(1) or git-request-pull(1).
436
437 =back
438
439 For example (and it is only an example):
440
441 =over 4
442
443     % # fork foo.git on GitHub
444     % git remote add -f fork git@github.com:spwhitton/foo.git
445     % git checkout -b fix-error upstream/master
446     % git config branch.fix-error.pushRemote fork
447     % git cherry-pick master^2
448     % git push
449     % # submit pull request on GitHub
450
451 =back
452
453 Note that when you merge an upstream release containing your forwarded
454 patches, git and dgit will transparently handle "dropping" the patches
455 that have been forwarded, "retaining" the ones that haven't.
456
457 =head1 INCORPORATING NMUS
458
459 =over 4
460
461     % dgit pull
462
463 =back
464
465 Alternatively, you can apply the NMU diff to your repository.  The
466 next push will then require I<--overwrite>.
467
468 =head1 SEE ALSO
469
470 dgit(1), dgit(7)
471
472 =head1 AUTHOR
473
474 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.