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