chiark / gitweb /
dgit-maint-debrebase(7): begin incorporating feedback
[dgit.git] / dgit-maint-debrebase.7.pod
1 =head1 NAME
2
3 dgit - tutorial for package maintainers, using a workflow centered around git-debrebase(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>.  We maintain the Debian delta
9 as a series of git commits on our master branch.  We use
10 git-debrebase(1) to shuffle our branch such that this series of git
11 commits appears at the end of the branch.  All the public git history
12 is fast-forwarding, i.e., we do not rewrite and force-push.
13
14 Some advantages of this workflow:
15
16 =over 4
17
18 =item
19
20 Manipulate the patch queue using the full power of git-rebase(1),
21 instead of relying on quilt(1), and without having to switch back and
22 forth between patches-applied and patches-unapplied branches when
23 committing changes and trying to build, as with gbp-pq(1).
24
25 =item
26
27 Avoid the git tree being dirtied by the application or unapplication
28 of patches, as they are always applied.
29
30 =item
31
32 Benefit from dgit's safety catches.  In particular, ensure that your
33 upload always matches exactly your git HEAD.
34
35 =item
36
37 Provide your full git history in a standard format on B<dgit-repos>,
38 where it can benefit downstream dgit users, such as people using dgit
39 to do an NMU (see dgit-nmu-simple(7) and dgit-user(7)).
40
41 =item
42
43 Minimise the amount you need to know about 3.0 (quilt) in order to
44 maintain Debian source packages which use that format.
45
46 =back
47
48 This workflow is appropriate for packages where the Debian delta
49 contains multiple pieces which interact, or which you don't expect to
50 be able to upstream soon.  For packages with simple and/or short-lived
51 Debian deltas, use of git-debrebase(1) might introduce unneeded
52 complexity (for examples, see "BEHAVIOUR TO AVOID" below).  For such
53 packages, consider the workflow described in dgit-maint-merge(7).
54
55 =head1 INITIAL DEBIANISATION
56
57 This section explains how to start using this workflow with a new
58 package.  It should be skipped when converting an existing package to
59 this workflow.
60
61 =head2 When upstream tags releases in git
62
63 Suppose that the latest stable upstream release is 1.2.2, and this has
64 been tagged '1.2.2' by upstream.
65
66 =over 4
67
68     % git clone -oupstream https://some.upstream/foo.git
69     % cd foo
70     % git verify-tag 1.2.2
71     % git reset --hard 1.2.2
72     % git branch --unset-upstream
73
74 =back
75
76 The final command detaches your master branch from the upstream
77 remote, so that git doesn't try to push anything there, or merge
78 unreleased upstream commits.  To maintain a copy of your packaging
79 branch on B<salsa.debian.org> in addition to B<dgit-repos>, you can do
80 something like this:
81
82 =over 4
83
84     % git remote add -f origin salsa.debian.org:Debian/foo.git
85     % git push --follow-tags -u origin master
86
87 =back
88
89 Now go ahead and Debianise your package.  Just make commits on the
90 master branch, adding things in the I<debian/> directory.  If you need
91 to patch the upstream source, see "EDITING THE PATCH QUEUE", below.
92 Note that there is no need to maintain a separate 'upstream' branch,
93 unless you also happen to be involved in upstream development.  We
94 work with upstream tags rather than any branches, except when
95 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
96
97 Finally, you need an orig tarball:
98
99 =over 4
100
101     % git deborig
102
103 =back
104
105 See git-deborig(1) if this fails.
106
107 This tarball is ephemeral and easily regenerated, so we don't commit
108 it anywhere (e.g. with tools like pristine-tar(1)).
109
110 =head3 Verifying upstream's tarball releases
111
112 =over 4
113
114 It can be a good idea to compare upstream's released tarballs with the
115 release tags, at least for the first upload of the package.  If they
116 are different, you might need to add some additional steps to your
117 I<debian/rules>, such as running autotools.
118
119 A convenient way to perform this check is to import the tarball as
120 described in the following section, using a different value for
121 'upstream-tag', and then use git-diff(1) to compare the imported
122 tarball to the release tag.  If they are the same, you can use
123 upstream's tarball instead of running git-deborig(1).
124
125 =back
126
127 =head2 When upstream releases only tarballs
128
129 We need a virtual upstream branch with virtual release tags.
130 gbp-import-orig(1) can manage this for us.  To begin
131
132 =over 4
133
134     % mkdir foo
135     % cd foo
136     % git init
137
138 =back
139
140 Now create I<debian/gbp.conf>:
141
142 =over 4
143
144     [DEFAULT]
145     upstream-branch = upstream
146     debian-branch = master
147     upstream-tag = %(version)s
148
149     sign-tags = True
150     pristine-tar = False
151     pristine-tar-commit = False
152
153     [import-orig]
154     merge-mode = merge
155
156 =back
157
158 gbp-import-orig(1) requires a pre-existing upstream branch:
159
160 =over 4
161
162     % git add debian/gbp.conf && git commit -m "create gbp.conf"
163     % git checkout --orphan upstream
164     % git rm -rf .
165     % git commit --allow-empty -m "initial, empty branch for upstream source"
166     % git checkout -f master
167
168 =back
169
170 Then we can import the upstream version:
171
172 =over 4
173
174     % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
175
176 =back
177
178 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
179 will need it whenever we import a new upstream version, we must push
180 it somewhere.  The usual choice is B<salsa.debian.org>:
181
182 =over 4
183
184     % git remote add -f origin salsa.debian.org:Debian/foo.git
185     % git push --follow-tags -u origin master upstream
186
187 =back
188
189 You are now ready to proceed as above, making commits to the
190 I<debian/> directory.
191
192 =head1 CONVERTING AN EXISTING PACKAGE
193
194 This section explains how to convert an existing Debian package to
195 this workflow.  It should be skipped when debianising a new package.
196
197 =head2 No existing git history
198
199 =over 4
200
201     % dgit clone foo
202     % cd foo
203     % git remote add -f upstream https://some.upstream/foo.git
204
205 =back
206
207 =head2 Existing git history using another workflow
208
209 First, if you don't already have the git history locally, clone it,
210 and obtain the corresponding orig.tar from the archive:
211
212 =over 4
213
214     % git clone salsa.debian.org:Debian/foo
215     % cd foo
216     % origtargz
217
218 =back
219
220 If your tree is patches-unapplied, you will need to make a commit
221 corresponding to each of the quilt patches.  You can use
222
223 =over 4
224
225     git debrebase convert-from-gbp
226
227 =back
228
229 or manually with gbp-pq(1):
230
231 =over 4
232
233     % gbp pq import
234     % gbp pq switch
235     % git merge --ff-only patch-queue/master
236     % gbp pq drop
237
238 =back
239
240 Then make new upstream tags available:
241
242 =over 4
243
244     % git remote add -f upstream https://some.upstream/foo.git
245
246 =back
247
248 =for dgit-test dpkg-source-ignores begin
249
250 Now you simply need to ensure that your git HEAD is dgit-compatible,
251 i.e., it is exactly what you would get if you ran
252 B<dpkg-buildpackage -i'(?:^|/)\.git(?:/|$)' -I.git -S>
253 and then unpacked the resultant source package.
254
255 =for dgit-test dpkg-source-ignores end
256
257 To achieve this, you might need to delete
258 I<debian/source/local-options>.  One way to have dgit check your
259 progress is to run B<dgit build-source>.
260
261 The first dgit push will require I<--overwrite>.  If this is the first
262 ever dgit push of the package, consider passing
263 I<--deliberately-not-fast-forward> instead of I<--overwrite>.  This
264 avoids introducing a new origin commit into your git history.  (This
265 origin commit would represent the most recent non-dgit upload of the
266 package, but this should already be represented in your git history.)
267
268 =head1 IMPORTING NEW UPSTREAM RELEASES
269
270 =head2 Obtaining the release
271
272 =head3 When upstream tags releases in git
273
274 =over 4
275
276     % git remote update
277
278 =back
279
280 =head3 When upstream releases only tarballs
281
282 You will need the I<debian/gbp.conf> from "When upstream releases only
283 tarballs", above.  You will also need your upstream branch.  Above, we
284 pushed this to B<salsa.debian.org>.  You will need to clone or fetch
285 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
286
287 Then, either
288
289 =over 4
290
291     % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
292
293 =back
294
295 or if you have a working watch file
296
297 =over 4
298
299     % gbp import-orig --no-merge --uscan
300
301 =back
302
303 =head2 Importing the release
304
305 =over 4
306
307     % git debrebase new-upstream-v0 1.2.3
308     % dch -v1.2.3-1 New upstream release.
309     % git add debian/changelog && git commit -m changelog
310
311 =back
312
313 You can now review the merge of the new upstream release:
314
315 =over 4
316
317     git diff debian/1.2.2-1..HEAD -- . ':!debian'
318
319 =back
320
321 Pass I<--stat> just to see the list of changed files, which is useful
322 to determine whether there are any new or deleted files to may need
323 accounting for in your copyright file.
324
325 If you obtained a tarball from upstream, you are ready to try a build.
326 If you merged a git tag from upstream, you will first need to generate
327 a tarball:
328
329 =over 4
330
331     % git deborig
332
333 =back
334
335 =head1 EDITING THE PATCH QUEUE
336
337 =head2 Adding new patches
338
339 Adding new patches is straightforward: just make commits touching only
340 files outside of the I<debian/> directory.  You can also use tools
341 like git-revert(1), git-am(1) and git-cherrypick(1).
342
343 =head2 Editing patches: starting a debrebase
344
345 git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
346 edit, re-order and delete patches.  Run
347
348 =over 4
349
350     % git debrebase
351
352 =back
353
354 to start an interactive rebase.  You can edit, re-order and delete
355 commits just as you would during B<git rebase -i>.  Alternatively, you
356 can perform a non-interactive rebase like this:
357
358 =over 4
359
360     % git debrebase -- [git-rebase options...]
361
362 =back
363
364 A third alternative is to have git-debrebase(1) shuffle all the Debian
365 changes to the end of your branch, and then manipulate them yourself
366 using git-rebase(1).  For example,
367
368 =over 4
369
370     % git debrebase launder
371     % git rebase -i HEAD~5      # there are 4 Debian patches
372
373 =back
374
375 If you take this approach, you should be very careful not to start the
376 rebase earlier than the beginning of the patch queue.
377
378 =head2 Editing patches: finishing a debrebase
379
380 After completing the git rebase, your branch will not be a
381 fast-forward of the git HEAD you had before the rebase.  This means
382 that we cannot push the branch anywhere.  If you are ready to upload,
383 B<dgit push> or B<dgit push-source> will take care of fixing this up
384 for you.
385
386 If you are not yet ready to upload, and want to push your branch to a
387 git remote such as B<salsa.debian.org>,
388
389 =over 4
390
391     % git debrebase launder
392     % git debrebase stitch
393
394 =back
395
396 Note that each time you stitch a debrebase you introduce a pseudomerge
397 into your git history, which may make it harder to read.  Try to do
398 all of the editing of the patch queue that you think will be needed
399 for this upload in a single debrebase, so that there is a single
400 debrebase stitch.
401
402 A strategy is to debrebase only right before you upload.  Before that
403 point, instead of editing the existing patch series, you append fixup
404 commits (and reversions of commits) that alter the upstream source to
405 the required state.  You can freely push and pull from
406 B<salsa.debian.org> during this.  Just before uploading, you debrebase
407 to tidy everything up.
408
409 =head1 BUILDING AND UPLOADING
410
411 Use B<dgit build>, B<dgit sbuild>, B<dgit push> and B<dgit
412 push-source> as detailed in dgit(1).  If any command fails, dgit will
413 provide a carefully-worded error message explaining what you should
414 do.  If it's not clear, file a bug against dgit.  Remember to pass
415 I<--new> for the first upload.
416
417 After dgit pushing, be sure to git push to B<salsa.debian.org>, if
418 you're using that.
419
420 As an alternative to B<dgit build> and friends, you can use a tool
421 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
422 HEAD has exactly the contents of the source package.  gitpkg(1) is
423 highly configurable, and one dgit user reports using it to produce and
424 test multiple source packages, from different branches corresponding
425 to each of the current Debian suites.
426
427 If you want to skip dgit's checks while iterating on a problem with
428 the package build (for example, you don't want to commit your changes
429 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
430
431 =head2 Laundering the patch queue before uploading
432
433 Just before you B<dgit push> or B<dgit push-source>, you might want to
434 have git-debrebase(1) shuffle your branch such that the Debian patch
435 queue appears at the end:
436
437 =over 4
438
439     % git debrebase launder
440     % dgit push-source
441
442 =back
443
444 Note that this will introduce a new pseudomerge.
445
446 =head1 HANDLING DFSG-NON-FREE MATERIAL
447
448 This covers only DFSG-non-free material.  Material which is legally
449 dangerous (for example, files which are actually illegal) cannot be
450 handled this way.
451
452 If you encounter possibly-legally-dangerous material in the upstream
453 source code you should seek advice.  It is often best not to make a
454 fuss on a public mailing list (at least, not at first).  Instead,
455 email your archive administrators.  For Debian that is
456  To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
457
458 =head2 When upstream tags releases in git
459
460 We create a DFSG-clean tag to import to master:
461
462 =over 4
463
464     % git checkout -b pre-dfsg 1.2.3
465     % git rm evil.bin
466     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
467     % git tag -s 1.2.3+dfsg
468     % git checkout master
469     % git branch -D pre-dfsg
470
471 =back
472
473 =head2 When upstream releases only tarballs
474
475 The easiest way to handle this is to add a B<Files-Excluded> field to
476 I<debian/copyright>, and a B<uversionmangle> setting in
477 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
478 option detailed in gbp-import-orig(1).
479
480 =head1 INCORPORATING NMUS
481
482 =over 4
483
484     % dgit pull
485
486 =back
487
488 If the NMUer added new commits modifying the upstream source, you will
489 probably want to debrebase before your next upload to tidy those up.
490
491 For example, the NMUer might have used git-revert(1) to unapply one of
492 your patches.  A debrebase will strip both the patch and the reversion
493 from the patch series.
494
495 =head1 SEE ALSO
496
497 dgit(1), dgit(7)
498
499 =head1 AUTHOR
500
501 This tutorial was written and is maintained by Sean Whitton
502 <spwhitton@spwhitton.name>.  It contains contributions from other dgit
503 contributors too - see the dgit copyright file.