chiark / gitweb /
changelog: finalise 8.3
[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.  Make commits on the master
96 branch, adding things in the I<debian/> directory, or patching the
97 upstream source.  For technical reasons, B<it is essential that your
98 first commit introduces the debian/ directory containing at least one
99 file, and does nothing else.> In other words, make a commit
100 introducing I<debian/> before patching the upstream source.
101
102 Finally, you need an orig tarball:
103
104 =over 4
105
106     % git deborig
107
108 =back
109
110 See git-deborig(1) if this fails.
111
112 This tarball is ephemeral and easily regenerated, so we don't commit
113 it anywhere (e.g. with tools like pristine-tar(1)).
114
115 =head3 Comparing upstream's tarball releases
116
117 =over 4
118
119 The above assumes that you know how to build the package from git and
120 that doing so is straightforward.
121
122 If, as a user of the upstream source, you usually build from upstream
123 tarball releases, rather than upstream git tags, you will sometimes
124 find that the git tree doesn't contain everything that is in the
125 tarball.
126
127 Additional build steps may be needed.  For example, you may need your
128 I<debian/rules> to run autotools.
129
130 You can compare the upstream tarball release, and upstream git tag,
131 within git, by importing the tarball into git as described in the
132 next section, using a different value for 'upstream-tag', and then
133 using git-diff(1) to compare the imported tarball to the release tag.
134
135 =back
136
137 =head2 When upstream releases only tarballs
138
139 Because we want to work in git, we need a virtual upstream branch with
140 virtual release tags.  gbp-import-orig(1) can manage this for us.  To
141 begin
142
143 =over 4
144
145     % mkdir foo
146     % cd foo
147     % git init
148
149 =back
150
151 Now create I<debian/gbp.conf>:
152
153 =over 4
154
155     [DEFAULT]
156     upstream-branch = upstream
157     debian-branch = master
158     upstream-tag = %(version)s
159
160     sign-tags = True
161     pristine-tar = False
162     pristine-tar-commit = False
163
164     [import-orig]
165     merge-mode = merge
166
167 =back
168
169 gbp-import-orig(1) requires a pre-existing upstream branch:
170
171 =over 4
172
173     % git add debian/gbp.conf && git commit -m "create gbp.conf"
174     % git checkout --orphan upstream
175     % git rm -rf .
176     % git commit --allow-empty -m "initial, empty branch for upstream source"
177     % git checkout -f master
178
179 =back
180
181 Then we can import the upstream version:
182
183 =over 4
184
185     % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
186
187 =back
188
189 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
190 will need it whenever we import a new upstream version, we must push
191 it somewhere.  The usual choice is B<salsa.debian.org>:
192
193 =over 4
194
195     % git remote add -f origin salsa.debian.org:Debian/foo.git
196     % git push --follow-tags -u origin master upstream
197
198 =back
199
200 You are now ready to proceed as above, making commits to the
201 I<debian/> directory and to the upstream source.  As above, for
202 technical reasons, B<it is essential that your first commit introduces
203 the debian/ directory containing at least one file, and does nothing
204 else.>  In other words, make a commit introducing I<debian/> before
205 patching the upstream source.
206
207 =head1 CONVERTING AN EXISTING PACKAGE
208
209 This section explains how to convert an existing Debian package to
210 this workflow.  It should be skipped when debianising a new package.
211
212 If you have an existing git history that you have pushed to an
213 ordinary git server like B<salsa.debian.org>, we start with that.  If
214 you don't already have it locally, you'll need to clone it, and obtain
215 the corresponding orig.tar from the archive:
216
217 =over 4
218
219     % git clone salsa.debian.org:Debian/foo
220     % cd foo
221     % dgit setup-new-tree
222     % origtargz
223
224 =back
225
226 If you don't have any existing git history, or you have history only
227 on the special B<dgit-repos> server, we start with B<dgit clone>:
228
229 =over 4
230
231     % dgit clone foo
232     % cd foo
233
234 =back
235
236 Then we make new upstream tags available:
237
238 =over 4
239
240     % git remote add -f upstream https://some.upstream/foo.git
241
242 =back
243
244 We now use a B<git debrebase convert-from-*> command to convert your
245 existing history to the git-debrebase(5) data model.  Which command
246 you should use depends on some facts about your repository:
247
248 =over 4
249
250 =item (A) There is no delta queue.
251
252 If there do not exist any Debian patches, use
253
254 =over 4
255
256     % git debrebase convert-from-gbp
257
258 =back
259
260 =item (B) There is a delta queue, and patches are unapplied.
261
262 This is the standard git-buildpackage(1) workflow: there are Debian
263 patches, but the upstream source is committed to git without those
264 patches applied.  Use
265
266 =over 4
267
268     % git debrebase convert-from-gbp
269
270 =back
271
272 If you were not previously using dgit to upload your package (i.e. you
273 were not using the workflow described in dgit-maint-gbp(7)), and you
274 happen to have run B<dgit fetch sid> in this clone of the repository,
275 you will need to pass I<--fdiverged> to this command.
276
277 =item (C) There is a delta queue, and patches are applied.
278
279 Use
280
281 =over 4
282
283     % git debrebase convert-from-dgit-view
284
285 =back
286
287 =back
288
289 Finally, you need to ensure that your git HEAD is dgit-compatible,
290 i.e., it is exactly what you would get if you deleted .git, invoked
291 B<dpkg-buildpackage -S>, and then unpacked the resultant source
292 package.
293
294 To achieve this, you might need to delete
295 I<debian/source/local-options>.  One way to have dgit check your
296 progress is to run B<dgit build-source>.
297
298 =head1 GIT CONFIGURATION
299
300 git-debrebase(1) does not yet support using B<git merge> to merge
301 divergent branches of development (see "OTHER MERGES" in
302 git-debrebase(5)).  You should configure git such that B<git pull>
303 does not try to merge:
304
305 =over 4
306
307     % git config --local pull.rebase true
308
309 =back
310
311 Now when you pull work from other Debian contributors, git will rebase
312 your work on top of theirs.
313
314 If you use this clone for upstream development in addition to
315 Debian packaging work, you may not want to set this global setting.
316 Instead, see the B<branch.autoSetupRebase> and
317 B<branch.E<lt>nameE<gt>.rebase> settings in git-config(5).
318
319 =head1 IMPORTING NEW UPSTREAM RELEASES
320
321 There are two steps: obtaining git refs that correspond to the new
322 release, and importing that release using git-debrebase(1).
323
324 =head2 Obtaining the release
325
326 =head3 When upstream tags releases in git
327
328 =over 4
329
330     % git remote update
331
332 =back
333
334 =head3 When upstream releases only tarballs
335
336 You will need the I<debian/gbp.conf> from "When upstream releases only
337 tarballs", above.  You will also need your upstream branch.  Above, we
338 pushed this to B<salsa.debian.org>.  You will need to clone or fetch
339 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
340
341 Then, either
342
343 =over 4
344
345     % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
346
347 =back
348
349 or if you have a working watch file
350
351 =over 4
352
353     % gbp import-orig --no-merge --uscan
354
355 =back
356
357 =head2 Importing the release
358
359 =over 4
360
361     % git debrebase new-upstream 1.2.3
362
363 =back
364
365 This invocation of git-debrebase(1) involves a git rebase.  You may
366 need to resolve conflicts if the Debian delta queue does not apply
367 cleanly to the new upstream source.
368
369 If all went well, you can now review the merge of the new upstream
370 release:
371
372 =over 4
373
374     git diff debian/1.2.2-1..HEAD -- . ':!debian'
375
376 =back
377
378 Pass I<--stat> just to see the list of changed files, which is useful
379 to determine whether there are any new or deleted files to may need
380 accounting for in your copyright file.
381
382 If you obtained a tarball from upstream, you are ready to try a build.
383 If you merged a git tag from upstream, you will first need to generate
384 a tarball:
385
386 =over 4
387
388     % git deborig
389
390 =back
391
392 =head1 EDITING THE DEBIAN PACKAGING
393
394 Just make commits on master that change the contents of I<debian/>.
395
396 =head1 EDITING THE DELTA QUEUE
397
398 =head2 Adding new patches
399
400 Adding new patches is straightforward: just make commits touching only
401 files outside of the I<debian/> directory.  You can also use tools
402 like git-revert(1), git-am(1) and git-cherry-pick(1).
403
404 =head2 Editing patches: starting a debrebase
405
406 git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
407 edit, re-order and delete patches.  Run
408
409 =over 4
410
411     % git debrebase -i
412
413 =back
414
415 to start an interactive rebase.  You can edit, re-order and delete
416 commits just as you would during B<git rebase -i>.
417
418 =head2 Editing patches: finishing a debrebase
419
420 After completing the git rebase, your branch will not be a
421 fast-forward of the git HEAD you had before the rebase.  This means
422 that we cannot push the branch anywhere.  If you are ready to upload,
423 B<dgit push> or B<dgit push-source> will take care of fixing this up
424 for you.
425
426 If you are not yet ready to upload, and want to push your branch to a
427 git remote such as B<salsa.debian.org>,
428
429 =over 4
430
431     % git debrebase conclude
432
433 =back
434
435 Note that each time you conclude a debrebase you introduce a
436 pseudomerge into your git history, which may make it harder to read.
437 Try to do all of the editing of the delta queue that you think will be
438 needed for this editing session in a single debrebase, so that there
439 is a single debrebase stitch.
440
441 =head1 BUILDING AND UPLOADING
442
443 You can use dpkg-buildpackage(1) for test builds.  When you are ready
444 to build for an upload, use B<dgit sbuild>, B<dgit pbuilder> or B<dgit
445 cowbuilder>.
446
447 Upload with B<dgit push> or B<dgit push-source>.  Remember to pass
448 I<--new> if the package is new in the target suite.
449
450 In some cases where you used B<git debrebase convert-from-gbp> since
451 the last upload, it is not possible for dgit to make your history
452 fast-forwarding from the history on B<dgit-repos>.  In such cases you
453 will have to pass I<--overwrite> to dgit.  git-debrebase will normally
454 tell you if this is will be needed.
455
456 Right before uploading, if you did not just already do so, you might
457 want to have git-debrebase(1) shuffle your branch such that the Debian
458 delta queue appears right at the tip of the branch you will push:
459
460 =over 4
461
462     % git debrebase
463     % dgit push-source
464
465 =back
466
467 Note that this will introduce a new pseudomerge.
468
469 After dgit pushing, be sure to git push to B<salsa.debian.org>, if
470 you're using that.
471
472 =head1 HANDLING DFSG-NON-FREE MATERIAL
473
474 =head2 Illegal material
475
476 Here we explain how to handle material that is merely DFSG-non-free.
477 Material which is legally dangerous (for example, files which are
478 actually illegal) cannot be handled this way.
479
480 If you encounter possibly-legally-dangerous material in the upstream
481 source code you should seek advice.  It is often best not to make a
482 fuss on a public mailing list (at least, not at first).  Instead,
483 email your archive administrators.  For Debian that is
484  To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
485
486 =head2 DFSG-non-free: When upstream tags releases in git
487
488 Our approach is to maintain a DFSG-clean upstream branch, and create
489 tags on this branch for each release that we want to import.  We then
490 import those tags per "Importing the release", above.  In the case of
491 a new package, we base our initial Debianisation on our first
492 DFSG-clean tag.
493
494 For the first upstream release that requires DFSG filtering:
495
496 =over 4
497
498     % git checkout -b upstream-dfsg 1.2.3
499     % git rm evil.bin
500     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
501     % git tag -s 1.2.3+dfsg
502     % git checkout master
503
504 =back
505
506 Now either proceed with "Importing the release" on the 1.2.3+dfsg tag,
507 or in the case of a new package,
508
509 =over 4
510
511     % git branch --unset-upstream
512     % git reset --hard 1.2.3+dfsg
513
514 =back
515
516 and proceed with "INITIAL DEBIANISATION".
517
518 For subsequent releases (whether or not they require additional
519 filtering):
520
521 =over 4
522
523     % git checkout upstream-dfsg
524     % git merge 1.2.4
525     % git rm further-evil.bin # if needed
526     % git commit -m "upstream version 1.2.4 DFSG-cleaned" # if needed
527     % git tag -s 1.2.4+dfsg
528     % git checkout master
529     % # proceed with "Importing the release" on 1.2.4+dfsg tag
530
531 =back
532
533 Our upstream-dfsg branch cannot be pushed to B<dgit-repos>, but since
534 we will need it whenever we import a new upstream version, we must
535 push it somewhere.  Assuming that you have already set up an origin
536 remote per the above,
537
538 =over 4
539
540     % git push --follow-tags -u origin master upstream-dfsg
541
542 =back
543
544 =head2 DFSG-non-free: When upstream releases only tarballs
545
546 The easiest way to handle this is to add a B<Files-Excluded> field to
547 I<debian/copyright>, and a B<uversionmangle> setting in
548 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
549 option detailed in gbp-import-orig(1).
550
551 =head1 INCORPORATING NMUS
552
553 In the simplest case,
554
555 =over 4
556
557     % dgit fetch
558     % git merge --ff-only dgit/dgit/sid
559
560 =back
561
562 If that fails, because your branch and the NMUers work represent
563 divergent branches of development, you have a number of options.  Here
564 we describe the two simplest.
565
566 Note that you should not try to resolve the divergent branches by
567 editing files in I<debian/patches>.  Changes there would either cause
568 trouble, or be overwritten by git-debrebase(1).
569
570 =head2 Rebasing your work onto the NMU
571
572 =over 4
573
574     % git rebase dgit/dgit/sid
575
576 =back
577
578 If the NMUer added new commits modifying the upstream source, you will
579 probably want to debrebase before your next upload to tidy those up.
580
581 For example, the NMUer might have used git-revert(1) to unapply one of
582 your patches.  A debrebase can be used to strip both the patch and the
583 reversion from the delta queue.
584
585 =head2 Manually applying the debdiff
586
587 If you cannot rebase because you have already pushed to
588 B<salsa.debian.org>, say, you can manually apply the NMU debdiff,
589 commit and debrebase.  The next B<dgit push> will require
590 I<--overwrite>.
591
592 =head1 HINTS AND TIPS
593
594 =head2 Minimising pseudomerges
595
596 Above we noted that each time you conclude a debrebase, you introduce
597 a pseudomerge into your git history, which may make it harder to read.
598
599 A simple convention you can use to minimise the number of pseudomerges
600 is to B<git debrebase conclude> only right before you upload or push
601 to B<salsa.debian.org>.
602
603 It is possible, though much less convenient, to reduce the number of
604 pseudomerges yet further.  We debrebase only (i) when importing a new
605 release, and (ii) right before uploading.  Instead of editing the
606 existing delta queue, you append fixup commits (and reversions of
607 commits) that alter the upstream source to the required state.  You
608 can push and pull to and from B<salsa.debian.org> during this.  Just
609 before uploading, you debrebase, once, to tidy everything up.
610
611 =head2 The debian/patches directory
612
613 In this workflow, I<debian/patches> is purely an output of
614 git-debrebase(1).  You should not make changes there.  They will
615 either cause trouble, or be ignored and overwritten by
616 git-debrebase(1).
617
618 I<debian/patches> will often be out-of-date because git-debrebase(1)
619 will only regenerate it when it needs to.  So you should not rely on
620 the information in that directory.  When preparing patches to forward
621 upstream, you should use git-format-patch(1) on git commits, rather
622 than sending files from I<debian/patches>.
623
624 =head2 Upstream branches
625
626 In this workflow, we specify upstream tags rather than any branches.
627
628 Except when (i) upstream releases only tarballs, (ii) we require DFSG
629 filtering, or (iii) you also happen to be involved in upstream
630 development, we do not maintain any local branch corresponding to
631 upstream, except temporary branches used to prepare patches for
632 forwarding, and the like.
633
634 The idea here is that from Debian's point of view, upstream releases
635 are immutable points in history.  We want to make sure that we are
636 basing our Debian package on a properly identified upstream version,
637 rather than some arbitrary commit on some branch.  Tags are more
638 useful for this.
639
640 Upstream's branches remain available as the git remote tracking
641 branches for your upstream remote, e.g. I<remotes/upstream/master>.
642
643 =head2 The first ever dgit push
644
645 If this is the first ever dgit push of the package, consider passing
646 I<--deliberately-not-fast-forward> instead of I<--overwrite>.  This
647 avoids introducing a new origin commit into your git history.  (This
648 origin commit would represent the most recent non-dgit upload of the
649 package, but this should already be represented in your git history.)
650
651 =head2 Inspecting the history
652
653 The git history made by git-debrebase can seem complicated.
654 Here are some suggestions for helpful invocations of gitk and git.
655 They can be adapted for other tools like tig(1), git-log(1), magit, etc.
656
657 History of package in Debian, disregarding history from upstream:
658
659 =over
660
661     % gitk --first-parent
662
663 In a laundered branch, the delta queue is at the top.
664
665 =back
666
667 History of the packaging, excluding the delta queue:
668
669     % gitk :/debian :!/debian/patches
670
671 Just the delta queue (i.e. Debian's changes to upstream):
672
673     % gitk --first-parent -- :/ :!/debian
674
675 Full history including old versions of the delta queue:
676
677 =over
678
679     % gitk --date-order
680
681 The "Declare fast forward" commits you see have an older history
682 (usually, an older delta queue) as one parent,
683 and a newer history as the other.
684 --date-order makes gitk show the delta queues in the right order.
685
686 =back
687
688 Complete diff since the last upload:
689
690 =over
691
692     % git diff dgit/dgit/sid..HEAD -- :/ :!/debian/patches
693
694 This includes changes to upstream files.
695
696 =back
697
698 Interdiff of delta queue since last upload, if you really want it:
699
700     % git debrebase make-patches
701     % git diff dgit/dgit/sid..HEAD -- debian/patches
702
703 And of course there is:
704
705     % git debrebase status
706
707 =head2 Alternative ways to start a debrebase
708
709 Above we started an interactive debrebase by invoking git-debrebase(1)
710 like this:
711
712 =over 4
713
714     % git debrebase -i
715
716 =back
717
718 It is also possible to perform a non-interactive rebase, like this:
719
720 =over 4
721
722     % git debrebase -- [git-rebase options...]
723
724 =back
725
726
727 A third alternative is to have git-debrebase(1) shuffle all the Debian
728 changes to the end of your branch, and then manipulate them yourself
729 using git-rebase(1) directly.  For example,
730
731 =over 4
732
733     % git debrebase
734     % git rebase -i HEAD~5      # there are 4 Debian patches
735
736 =back
737
738 If you take this approach, you should be very careful not to start the
739 rebase too early,
740 including before the most recent pseudomerge.
741 git-rebase without a base argument will often
742 start the rebase too early,
743 and should be avoided.
744 Run git-debrebase instead.
745 See also "ILLEGAL OPERATIONS" in git-debrebase(5).
746
747 =head1 SEE ALSO
748
749 dgit(1), dgit(7), git-debrebase(1), git-debrebase(5)
750
751 =head1 AUTHOR
752
753 This tutorial was written and is maintained by Sean Whitton
754 <spwhitton@spwhitton.name>.  It contains contributions from other dgit
755 contributors too - see the dgit copyright file.