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