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