chiark / gitweb /
dgit-maint-{merge,debrebase}(7): Use git fetch --all --tags
[dgit.git] / dgit-maint-merge.7.pod
1 =head1 NAME
2
3 dgit - tutorial for package maintainers, using a workflow centered around git-merge(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>.  The workflow makes the
9 following opinionated assumptions:
10
11 =over 4
12
13 =item
14
15 Git histories should be the non-linear histories produced by
16 git-merge(1), preserving all information about divergent development
17 that was later brought together.
18
19 =item
20
21 Maintaining convenient and powerful git workflows takes priority over
22 the usefulness of the raw Debian source package.  The Debian archive
23 is thought of as an output format.
24
25 For example, we don't spend time curating a series of quilt patches.
26 However,
27 in straightforward cases,
28 the information such a series would contain is readily
29 available from B<dgit-repos>.
30
31 =item
32
33 It is more important to have the Debian package's git history be a
34 descendent of upstream's git history than to use exactly the orig.tar
35 that upstream makes available for download.
36
37 =back
38
39 This workflow is less suitable for some packages.
40 When the Debian delta contains multiple pieces which interact,
41 or which you aren't going to be able to upstream soon,
42 it might be preferable to
43 maintain the delta as a rebasing patch series.
44 For such a workflow see for example
45 dgit-maint-debrebase(7) and dgit-maint-gbp(7).
46
47 =head1 INITIAL DEBIANISATION
48
49 This section explains how to start using this workflow with a new
50 package.  It should be skipped when converting an existing package to
51 this workflow.
52
53 =head2 When upstream tags releases in git
54
55 Suppose that the latest stable upstream release is 1.2.2, and this has
56 been tagged '1.2.2' by upstream.
57
58 =over 4
59
60     % git clone -oupstream https://some.upstream/foo.git
61     % cd foo
62     % git verify-tag 1.2.2
63     % git reset --hard 1.2.2
64     % git branch --unset-upstream
65
66 =back
67
68 The final command detaches your master branch from the upstream remote,
69 so that git doesn't try to push anything there, or merge unreleased
70 upstream commits.  If you want to maintain a copy of your packaging
71 branch on B<salsa.debian.org> in addition to B<dgit-repos>, you can
72 do something like this:
73
74 =over 4
75
76     % git remote add -f origin salsa.debian.org:Debian/foo.git
77     % git push --follow-tags -u origin master
78
79 =back
80
81 Now go ahead and Debianise your package.  Just make commits on the
82 master branch, adding things in the I<debian/> directory.  If you need
83 to patch the upstream source, just make commits that change files
84 outside of the I<debian/> directory.  It is best to separate commits
85 that touch I<debian/> from commits that touch upstream source, so that
86 the latter can be cherry-picked by upstream.
87
88 Note that there is no need to maintain a separate 'upstream' branch,
89 unless you also happen to be involved in upstream development.  We
90 work with upstream tags rather than any branches, except when
91 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
92
93 Finally, you need an orig tarball:
94
95 =over 4
96
97     % git deborig
98
99 =back
100
101 See git-deborig(1) if this fails.
102
103 This tarball is ephemeral and easily regenerated, so we don't commit
104 it anywhere (e.g. with tools like pristine-tar(1)).
105
106 =head3 Verifying upstream's tarball releases
107
108 =over 4
109
110 It can be a good idea to compare upstream's released tarballs with the
111 release tags, at least for the first upload of the package.  If they
112 are different, you might need to add some additional steps to your
113 I<debian/rules>, such as running autotools.
114
115 A convenient way to perform this check is to import the tarball as
116 described in the following section, using a different value for
117 'upstream-tag', and then use git-diff(1) to compare the imported
118 tarball to the release tag.  If they are the same, you can use
119 upstream's tarball instead of running git-deborig(1).
120
121 =back
122
123 =head3 Using untagged upstream commits
124
125 =over 4
126
127 Sometimes upstream does not tag their releases, or you want to package
128 an unreleased git snapshot.  In such a case you can create your own
129 upstream release tag, of the form B<upstream/>I<ver>, where I<ver> is
130 the upstream version you plan to put in I<debian/changelog>.  The
131 B<upstream/> prefix ensures that your tag will not clash with any tags
132 upstream later creates.
133
134 For example, suppose that the latest upstream release is 1.2.2 and you
135 want to package git commit ab34c21 which was made on 2013-12-11.  A
136 common convention is to use the upstream version number
137 1.2.2+git20131211.ab34c21 and so you could use
138
139 =over 4
140
141     % git tag -s upstream/1.2.2+git20131211.ab34c21 ab34c21
142
143 =back
144
145 to obtain a release tag, and then proceed as above.
146
147 =back
148
149 =head2 When upstream releases only tarballs
150
151 We need a virtual upstream branch with virtual release tags.
152 gbp-import-orig(1) can manage this for us.  To begin
153
154 =over 4
155
156     % mkdir foo
157     % cd foo
158     % git init
159
160 =back
161
162 Now create I<debian/gbp.conf>:
163
164 =over 4
165
166     [DEFAULT]
167     upstream-branch = upstream
168     debian-branch = master
169     upstream-tag = %(version)s
170
171     sign-tags = True
172     pristine-tar = False
173     pristine-tar-commit = False
174
175     [import-orig]
176     merge-mode = merge
177
178 =back
179
180 gbp-import-orig(1) requires a pre-existing upstream branch:
181
182 =over 4
183
184     % git add debian/gbp.conf && git commit -m "create gbp.conf"
185     % git checkout --orphan upstream
186     % git rm -rf .
187     % git commit --allow-empty -m "initial, empty branch for upstream source"
188     % git checkout -f master
189
190 =back
191
192 Then we can import the upstream version:
193
194 =over 4
195
196     % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
197
198 =back
199
200 Our upstream branch cannot be pushed to B<dgit-repos>, but since we
201 will need it whenever we import a new upstream version, we must push
202 it somewhere.  The usual choice is B<salsa.debian.org>:
203
204 =over 4
205
206     % git remote add -f origin salsa.debian.org:Debian/foo.git
207     % git push --follow-tags -u origin master upstream
208
209 =back
210
211 You are now ready to proceed as above, making commits to both the
212 upstream source and the I<debian/> directory.
213
214 =head1 CONVERTING AN EXISTING PACKAGE
215
216 This section explains how to convert an existing Debian package to
217 this workflow.  It should be skipped when debianising a new package.
218
219 =head2 No existing git history
220
221 =over 4
222
223     % dgit clone foo
224     % cd foo
225     % git remote add -f upstream https://some.upstream/foo.git
226
227 =back
228
229 =head2 Existing git history using another workflow
230
231 First, if you don't already have the git history locally, clone it,
232 and obtain the corresponding orig.tar from the archive:
233
234 =over 4
235
236     % git clone git.debian.org:collab-maint/foo
237     % cd foo
238     % origtargz
239
240 =back
241
242 Now dump any existing patch queue:
243
244 =over 4
245
246     % git rm -rf debian/patches
247     % git commit -m "drop existing quilt patch queue"
248
249 =back
250
251 Then make new upstream tags available:
252
253 =over 4
254
255     % git remote add -f upstream https://some.upstream/foo.git
256
257 =back
258
259 =for dgit-test dpkg-source-ignores begin
260
261 Now you simply need to ensure that your git HEAD is dgit-compatible,
262 i.e., it is exactly what you would get if you ran
263 B<dpkg-buildpackage -i'(?:^|/)\.git(?:/|$)' -I.git -S>
264 and then unpacked the resultant source package.
265
266 =for dgit-test dpkg-source-ignores end
267
268 To achieve this, you might need to delete
269 I<debian/source/local-options>.  One way to have dgit check your
270 progress is to run B<dgit build-source>.
271
272 The first dgit push will require I<--overwrite>.  If this is the first
273 ever dgit push of the package, consider passing
274 I<--deliberately-not-fast-forward> instead of I<--overwrite>.  This
275 avoids introducing a new origin commit into your git history.  (This
276 origin commit would represent the most recent non-dgit upload of the
277 package, but this should already be represented in your git history.)
278
279 =head1 SOURCE PACKAGE CONFIGURATION
280
281 =head2 debian/source/options
282
283 We set some source package options such that dgit can transparently
284 handle the "dropping" and "refreshing" of changes to the upstream
285 source:
286
287 =over 4
288
289     single-debian-patch
290     auto-commit
291
292 =back
293
294 You don't need to create this file if you are using the version 1.0
295 source package format.
296
297 =head2 Sample text for debian/source/patch-header
298
299 It is a good idea to explain how a user can obtain a breakdown of the
300 changes to the upstream source:
301
302 =over 4
303
304 The Debian packaging of foo is maintained in git,
305 using the merging workflow described in dgit-maint-merge(7).
306 There isn't a patch queue that can be represented as a quilt series.
307
308 A detailed breakdown of the changes is available from their
309 canonical representation -
310 git commits in the packaging repository.
311 For example, to see the changes made by the Debian maintainer in the
312 first upload of upstream version 1.2.3, you could use:
313
314 =over 4
315
316     % git clone https://git.dgit.debian.org/foo
317     % cd foo
318     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
319
320 =back
321
322 (If you have dgit, use `dgit clone foo`,
323 rather than plain `git clone`.)
324
325 A single combined diff, containing all the changes, follows.
326
327 =back
328
329 If you are using the version 1.0 source package format, this text
330 should be added to README.source instead.  The version 1.0 source
331 package format ignores debian/source/patch-header.
332
333 If you're using the version 3.0 (quilt) source package format, you
334 could add this text to README.source instead of
335 debian/source/patch-header, but this might distract from more
336 important information present in README.source.
337
338 =head1 BUILDING AND UPLOADING
339
340 Use B<dgit build>, B<dgit sbuild>, B<dgit pbuilder>, B<dgit
341 cowbuilder>, B<dgit push-source>, and B<dgit push> as detailed in
342 dgit(1).  If any command fails, dgit will provide a carefully-worded
343 error message explaining what you should do.  If it's not clear, file
344 a bug against dgit.  Remember to pass I<--new> for the first upload.
345
346 As an alternative to B<dgit build> and friends, you can use a tool
347 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
348 HEAD has exactly the contents of the source package.  gitpkg(1) is
349 highly configurable, and one dgit user reports using it to produce and
350 test multiple source packages, from different branches corresponding
351 to each of the current Debian suites.
352
353 If you want to skip dgit's checks while iterating on a problem with
354 the package build (for example, you don't want to commit your changes
355 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
356
357 =head1 NEW UPSTREAM RELEASES
358
359 =head2 Obtaining the release
360
361 =head3 When upstream tags releases in git
362
363 =over 4
364
365     % git fetch --all --tags
366
367 =back
368
369 If you want to package an untagged upstream commit (because upstream
370 does not tag releases or because you want to package an upstream
371 development snapshot), see "Using untagged upstream commits" above.
372
373 =head3 When upstream releases only tarballs
374
375 You will need the I<debian/gbp.conf> from "When upstream releases only
376 tarballs", above.  You will also need your upstream branch.  Above, we
377 pushed this to B<salsa.debian.org>.  You will need to clone or fetch
378 from there, instead of relying on B<dgit clone>/B<dgit fetch> alone.
379
380 Then, either
381
382 =over 4
383
384     % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
385
386 =back
387
388 or if you have a working watch file
389
390 =over 4
391
392     % gbp import-orig --no-merge --uscan
393
394 =back
395
396 =head2 Reviewing & merging the release
397
398 It's a good idea to preview the merge of the new upstream release.
399 First, just check for any new or deleted files that may need
400 accounting for in your copyright file:
401
402 =over 4
403
404     % git diff --name-status --diff-filter=ADR master..1.2.3 -- . ':!debian'
405
406 =back
407
408 You can then review the full merge diff:
409
410 =over 4
411
412     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
413
414 =back
415
416 Once you're satisfied with what will be merged, update your package:
417
418 =over 4
419
420     % git merge 1.2.3
421     % dch -v1.2.3-1 New upstream release.
422     % git add debian/changelog && git commit -m changelog
423
424 =back
425
426 If you obtained a tarball from upstream, you are ready to try a build.
427 If you merged a git tag from upstream, you will first need to generate
428 a tarball:
429
430 =over 4
431
432     % git deborig
433
434 =back
435
436 =head1 HANDLING DFSG-NON-FREE MATERIAL
437
438 =head2 When upstream tags releases in git
439
440 We create a DFSG-clean tag to merge to master:
441
442 =over 4
443
444     % git checkout -b pre-dfsg 1.2.3
445     % git rm evil.bin
446     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
447     % git tag -s 1.2.3+dfsg
448     % git checkout master
449     % git branch -D pre-dfsg
450
451 =back
452
453 Before merging the new 1.2.3+dfsg tag to master, you should first
454 determine whether it would be legally dangerous for the non-free
455 material to be publicly accessible in the git history on
456 B<dgit-repos>.
457
458 If it would be dangerous, there is a big problem;
459 in this case please consult your archive administrators
460 (for Debian this is the dgit administrator dgit-owner@debian.org
461 and the ftpmasters ftpmaster@ftp-master.debian.org).
462
463 =head2 When upstream releases only tarballs
464
465 The easiest way to handle this is to add a B<Files-Excluded> field to
466 I<debian/copyright>, and a B<uversionmangle> setting in
467 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
468 option detailed in gbp-import-orig(1).
469
470 =head1 FORWARDING PATCHES UPSTREAM
471
472 The basic steps are:
473
474 =over 4
475
476 =item 1.
477
478 Create a new branch based off upstream's master branch.
479
480 =item 2.
481
482 git-cherry-pick(1) commits from your master branch onto your new
483 branch.
484
485 =item 3.
486
487 Push the branch somewhere and ask upstream to merge it, or use
488 git-format-patch(1) or git-request-pull(1).
489
490 =back
491
492 For example (and it is only an example):
493
494 =over 4
495
496     % # fork foo.git on GitHub
497     % git remote add -f fork git@github.com:spwhitton/foo.git
498     % git checkout -b fix-error upstream/master
499     % git config branch.fix-error.pushRemote fork
500     % git cherry-pick master^2
501     % git push
502     % # submit pull request on GitHub
503
504 =back
505
506 Note that when you merge an upstream release containing your forwarded
507 patches, git and dgit will transparently handle "dropping" the patches
508 that have been forwarded, "retaining" the ones that haven't.
509
510 =head1 INCORPORATING NMUS
511
512 =over 4
513
514     % dgit pull
515
516 =back
517
518 Alternatively, you can apply the NMU diff to your repository.  The
519 next push will then require I<--overwrite>.
520
521 =head1 SEE ALSO
522
523 dgit(1), dgit(7)
524
525 =head1 AUTHOR
526
527 This tutorial was written and is maintained by Sean Whitton <spwhitton@spwhitton.name>.  It contains contributions from other dgit contributors too - see the dgit copyright file.