chiark / gitweb /
bdfdc8bdbd839d4b9ff9a1456adbb3359b0566e4
[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) introduces unneeded complexity.
58 For such packages, consider the workflow described in
59 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, or patching
97 the upstream source.
98
99 Finally, you need an orig tarball:
100
101 =over 4
102
103     % git deborig
104
105 =back
106
107 See git-deborig(1) if this fails.
108
109 This tarball is ephemeral and easily regenerated, so we don't commit
110 it anywhere (e.g. with tools like pristine-tar(1)).
111
112 =head3 Verifying upstream's tarball releases
113
114 =over 4
115
116 It can be a good idea to compare upstream's released tarballs with the
117 release tags, at least for the first upload of the package.  If they
118 are different, you might need to add some additional steps to your
119 I<debian/rules>, such as running autotools.
120
121 A convenient way to perform this check is to import the tarball as
122 described in the following section, using a different value for
123 'upstream-tag', and then use git-diff(1) to compare the imported
124 tarball to the release tag.  If they are the same, you can use
125 upstream's tarball instead of running git-deborig(1).
126
127 =back
128
129 =head2 When upstream releases only tarballs
130
131 We need a virtual upstream branch with virtual release tags.
132 gbp-import-orig(1) can manage this for us.  To begin
133
134 =over 4
135
136     % mkdir foo
137     % cd foo
138     % git init
139
140 =back
141
142 Now create I<debian/gbp.conf>:
143
144 =over 4
145
146     [DEFAULT]
147     upstream-branch = upstream
148     debian-branch = master
149     upstream-tag = %(version)s
150
151     sign-tags = True
152     pristine-tar = False
153     pristine-tar-commit = False
154
155     [import-orig]
156     merge-mode = merge
157
158 =back
159
160 gbp-import-orig(1) requires a pre-existing upstream branch:
161
162 =over 4
163
164     % git add debian/gbp.conf && git commit -m "create gbp.conf"
165     % git checkout --orphan upstream
166     % git rm -rf .
167     % git commit --allow-empty -m "initial, empty branch for upstream source"
168     % git checkout -f master
169
170 =back
171
172 Then we can import the upstream version:
173
174 =over 4
175
176     % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
177
178 =back
179
180 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
181 will need it whenever we import a new upstream version, we must push
182 it somewhere.  The usual choice is B<salsa.debian.org>:
183
184 =over 4
185
186     % git remote add -f origin salsa.debian.org:Debian/foo.git
187     % git push --follow-tags -u origin master upstream
188
189 =back
190
191 You are now ready to proceed as above, making commits to the
192 I<debian/> directory and to the upstream source.
193
194 =head1 CONVERTING AN EXISTING PACKAGE
195
196 This section explains how to convert an existing Debian package to
197 this workflow.  It should be skipped when debianising a new package.
198
199 =head2 No existing git history
200
201 =over 4
202
203     % dgit clone foo
204     % cd foo
205     % git remote add -f upstream https://some.upstream/foo.git
206
207 =back
208
209 =head2 Existing git history using another workflow
210
211 First, if you don't already have the git history locally, clone it,
212 and obtain the corresponding orig.tar from the archive:
213
214 =over 4
215
216     % git clone salsa.debian.org:Debian/foo
217     % cd foo
218     % origtargz
219
220 =back
221
222 If your tree is patches-unapplied, you will need to make a commit
223 corresponding to each of the quilt patches.  You can use
224
225 =over 4
226
227     git debrebase convert-from-gbp
228
229 =back
230
231 or manually with gbp-pq(1):
232
233 =over 4
234
235     % gbp pq import
236     % gbp pq switch
237     % git merge --ff-only patch-queue/master
238     % gbp pq drop
239
240 =back
241
242 Then make new upstream tags available:
243
244 =over 4
245
246     % git remote add -f upstream https://some.upstream/foo.git
247
248 =back
249
250 =for dgit-test dpkg-source-ignores begin
251
252 Now you simply need to ensure that your git HEAD is dgit-compatible,
253 i.e., it is exactly what you would get if you ran
254 B<dpkg-buildpackage -i'(?:^|/)\.git(?:/|$)' -I.git -S>
255 and then unpacked the resultant source package.
256
257 =for dgit-test dpkg-source-ignores end
258
259 To achieve this, you might need to delete
260 I<debian/source/local-options>.  One way to have dgit check your
261 progress is to run B<dgit build-source>.
262
263 The first dgit push will require I<--overwrite>.
264
265 =head1 GIT CONFIGURATION
266
267 This workflow does not support using B<git merge> to merge divergent
268 branches of development (see "OTHER MERGES" in git-debrebase(5)).  You
269 should configure git such that B<git pull> does not try to merge:
270
271 =over 4
272
273     % git config --local pull.rebase true
274
275 =back
276
277 Now when you pull work from other Debian contributors, git will rebase
278 your work on top of theirs.
279
280 If you use this repository for upstream development in addition to
281 Debian packaging work, you may not want to set this global setting.
282 Instead, see the B<branch.autoSetupRebase> and
283 B<branch.E<lt>nameE<gt>.rebase> settings in git-config(5).
284
285 =head1 IMPORTING NEW UPSTREAM RELEASES
286
287 There are two steps: obtaining git refs that correspond to the new
288 release, and importing that release using git-debrebase(1).
289
290 =head2 Obtaining the release
291
292 =head3 When upstream tags releases in git
293
294 =over 4
295
296     % git remote update
297
298 =back
299
300 =head3 When upstream releases only tarballs
301
302 You will need the I<debian/gbp.conf> from "When upstream releases only
303 tarballs", above.  You will also need your upstream branch.  Above, we
304 pushed this to B<salsa.debian.org>.  You will need to clone or fetch
305 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
306
307 Then, either
308
309 =over 4
310
311     % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
312
313 =back
314
315 or if you have a working watch file
316
317 =over 4
318
319     % gbp import-orig --no-merge --uscan
320
321 =back
322
323 =head2 Importing the release
324
325 =over 4
326
327     % git debrebase new-upstream-v0 1.2.3
328     % dch -v1.2.3-1 New upstream release.
329     % git add debian/changelog && git commit -m changelog
330
331 =back
332
333 You can now review the merge of the new upstream release:
334
335 =over 4
336
337     git diff debian/1.2.2-1..HEAD -- . ':!debian'
338
339 =back
340
341 Pass I<--stat> just to see the list of changed files, which is useful
342 to determine whether there are any new or deleted files to may need
343 accounting for in your copyright file.
344
345 If you obtained a tarball from upstream, you are ready to try a build.
346 If you merged a git tag from upstream, you will first need to generate
347 a tarball:
348
349 =over 4
350
351     % git deborig
352
353 =back
354
355 =head1 EDITING THE DELTA QUEUE
356
357 =head2 Adding new patches
358
359 Adding new patches is straightforward: just make commits touching only
360 files outside of the I<debian/> directory.  You can also use tools
361 like git-revert(1), git-am(1) and git-cherrypick(1).
362
363 =head2 Editing patches: starting a debrebase
364
365 git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
366 edit, re-order and delete patches.  Run
367
368 =over 4
369
370     % git debrebase
371
372 =back
373
374 to start an interactive rebase.  You can edit, re-order and delete
375 commits just as you would during B<git rebase -i>.
376
377 =head2 Editing patches: finishing a debrebase
378
379 After completing the git rebase, your branch will not be a
380 fast-forward of the git HEAD you had before the rebase.  This means
381 that we cannot push the branch anywhere.  If you are ready to upload,
382 B<dgit push> or B<dgit push-source> will take care of fixing this up
383 for you.
384
385 If you are not yet ready to upload, and want to push your branch to a
386 git remote such as B<salsa.debian.org>,
387
388 =over 4
389
390     % git debrebase conclude
391
392 =back
393
394 Note that each time you conclude a debrebase you introduce a
395 pseudomerge into your git history, which may make it harder to read.
396 Try to do all of the editing of the delta queue that you think will be
397 needed for this upload in a single debrebase, so that there is a
398 single debrebase stitch.
399
400 =head1 BUILDING AND UPLOADING
401
402 You can use dpkg-buildpackage(1) for test builds.  When you are ready
403 to build for an upload, use B<dgit sbuild>.
404
405 Upload with B<dgit push> or B<dgit push-source>.  Remember to pass
406 I<--new> if the package is new in the target suite.
407
408 Right before uploading, if you did not just already do so, you might
409 want to have git-debrebase(1) shuffle your branch such that the Debian
410 delta queue appears right at the tip of the branch you will push:
411
412 =over 4
413
414     % git debrebase launder
415     % dgit push-source
416
417 =back
418
419 Note that this will introduce a new pseudomerge.
420
421 After dgit pushing, be sure to git push to B<salsa.debian.org>, if
422 you're using that.
423
424 =head1 HANDLING DFSG-NON-FREE MATERIAL
425
426 This covers only DFSG-non-free material.  Material which is legally
427 dangerous (for example, files which are actually illegal) cannot be
428 handled this way.
429
430 If you encounter possibly-legally-dangerous material in the upstream
431 source code you should seek advice.  It is often best not to make a
432 fuss on a public mailing list (at least, not at first).  Instead,
433 email your archive administrators.  For Debian that is
434  To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
435
436 =head2 When upstream tags releases in git
437
438 We create a DFSG-clean tag to import to master:
439
440 =over 4
441
442     % git checkout -b pre-dfsg 1.2.3
443     % git rm evil.bin
444     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
445     % git tag -s 1.2.3+dfsg
446     % git checkout master
447     % git branch -D pre-dfsg
448
449 =back
450
451 =head2 When upstream releases only tarballs
452
453 The easiest way to handle this is to add a B<Files-Excluded> field to
454 I<debian/copyright>, and a B<uversionmangle> setting in
455 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
456 option detailed in gbp-import-orig(1).
457
458 =head1 INCORPORATING NMUS
459
460 In the simplest case,
461
462 =over 4
463
464     % dgit fetch
465     % git merge --ff-only dgit/dgit/sid
466
467 =back
468
469 If that fails, because your branch and the NMUers work represent
470 divergent branches of development, you have a number of options.  Here
471 we describe the two simplest.
472
473 =head2 Rebasing your work onto the NMU
474
475 =over 4
476
477     % git rebase dgit/dgit/sid
478
479 =back
480
481 If the NMUer added new commits modifying the upstream source, you will
482 probably want to debrebase before your next upload to tidy those up.
483
484 For example, the NMUer might have used git-revert(1) to unapply one of
485 your patches.  A debrebase will strip both the patch and the reversion
486 from the delta queue.
487
488 =head2 Manually applying the debdiff
489
490 If you cannot rebase because you have already pushed to
491 B<salsa.debian.org>, say, you can manually apply the NMU debdiff,
492 commit and debrebase.  The next B<dgit push> will require
493 I<--overwrite>.
494
495 =head1 HINTS AND TIPS
496
497 =head2 Minimising pseudomerges
498
499 Above we noted that each time you conclude a debrebase, you introduce
500 a pseudomerge into your git history, which may make it harder to read.
501
502 A convention you can use to minimise the number of pseudomerges is to
503 debrebase only right before you upload.
504
505 Before that point, instead of editing the existing delta queue, you
506 append fixup commits (and reversions of commits) that alter the
507 upstream source to the required state.  You can freely push and pull
508 from B<salsa.debian.org> during this.  Just before uploading, you
509 debrebase, once, to tidy everything up.
510
511 =head2 Upstream branches
512
513 Except in the case where upstream releases only tarballs, we do not
514 maintain a separate 'upstream' branch (unless you also happen to be
515 involved in upstream development).  We work with upstream tags rather
516 than any branches, except temporary branches used to prepare patches
517 for forwarding upstream, for example.
518
519 The thought behind this is that branches are things to which one
520 expects to commit, while tags are immutable points in history.  From
521 the Debian point of the view, the upstream source is immutable.  It's
522 our packaging to which we expect to commit.
523
524 =head2 The first ever dgit push
525
526 If this is the first ever dgit push of the package, consider passing
527 I<--deliberately-not-fast-forward> instead of I<--overwrite>.  This
528 avoids introducing a new origin commit into your git history.  (This
529 origin commit would represent the most recent non-dgit upload of the
530 package, but this should already be represented in your git history.)
531
532 =head2 Alternative ways to start a debrebase
533
534 Above we started an interactive debrebase by invoking git-debrebase(1)
535 without any arguments, i.e.
536
537 =over 4
538
539     % git debrebase
540
541 =back
542
543 It is also possible to perform a non-interactive rebase, like this:
544
545 =over 4
546
547     % git debrebase -- [git-rebase options...]
548
549 =back
550
551
552 A third alternative is to have git-debrebase(1) shuffle all the Debian
553 changes to the end of your branch, and then manipulate them yourself
554 using git-rebase(1) directly.  For example,
555
556 =over 4
557
558     % git debrebase launder
559     % git rebase -i HEAD~5      # there are 4 Debian patches
560
561 =back
562
563 If you take this approach, you should be very careful not to start the
564 rebase earlier than the beginning of the delta queue.
565
566 =head1 SEE ALSO
567
568 dgit(1), dgit(7)
569
570 =head1 AUTHOR
571
572 This tutorial was written and is maintained by Sean Whitton
573 <spwhitton@spwhitton.name>.  It contains contributions from other dgit
574 contributors too - see the dgit copyright file.