chiark / gitweb /
dgit(1): Clarify --no-chase-dsc-distro
[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, the information such a series would contain is readily
27 available from B<dgit-repos>.
28
29 =item
30
31 It is more important to have the Debian package's git history be a
32 descendent of upstream's git history than to use exactly the orig.tar
33 that upstream makes available for download.
34
35 =back
36
37 =head1 GIT CONFIGURATION
38
39 Add the following to your ~/.gitconfig to teach git-archive(1) how to
40 compress orig tarballs:
41
42 =over 4
43
44     [tar "tar.xz"]
45         command = xz -c
46     [tar "tar.gz"]
47         command = gzip -c
48
49 =back
50
51 =head1 INITIAL DEBIANISATION
52
53 This section explains how to start using this workflow with a new
54 package.  It should be skipped when converting an existing package to
55 this workflow.
56
57 =head2 When upstream tags releases in git
58
59 Suppose that the latest stable upstream release is 1.2.2, and this has
60 been tagged '1.2.2' by upstream.
61
62 =over 4
63
64     % git clone -oupstream https://some.upstream/foo.git
65     % cd foo
66     % git verify-tag 1.2.2
67     % git reset --hard 1.2.2
68     % git branch --unset-upstream
69
70 =back
71
72 The final command detachs your master branch from the upstream remote,
73 so that git doesn't try to push anything there, or merge unreleased
74 upstream commits.  If you want to maintain a copy of your packaging
75 branch on B<alioth.debian.org> in addition to B<dgit-repos>, you can
76 do something like this:
77
78 =over 4
79
80     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
81     % git push --follow-tags -u origin master
82
83 =back
84
85 Now go ahead and Debianise your package.  Just make commits on the
86 master branch, adding things in the I<debian/> directory.  If you need
87 to patch the upstream source, just make commits that change files
88 outside of the I<debian/> directory.  It is best to separate commits
89 that touch I<debian/> from commits that touch upstream source, so that
90 the latter can be cherry-picked by upstream.
91
92 Note that there is no need to maintain a separate 'upstream' branch,
93 unless you also happen to be involved in upstream development.  We
94 work with upstream tags rather than any branches, except when
95 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
96
97 Finally, you need an orig tarball.  Generate one with git-archive(1):
98
99 =over 4
100
101     % git archive -o ../foo_1.2.2.orig.tar.xz 1.2.2
102
103 =back
104
105 If you are using the version 1.0 source package format, replace 'xz'
106 with 'gz'.
107
108 This tarball is ephemeral and easily regenerated, so we don't commit
109 it anywhere (e.g. with tools like pristine-tar(1)).
110
111 =head3 Verifying upstream's tarball releases
112
113 =over 4
114
115 It can be a good idea to compare upstream's released tarballs with the
116 release tags, at least for the first upload of the package.  If they
117 are different, you might need to add some additional steps to your
118 I<debian/rules>, such as running autotools.
119
120 A convenient way to perform this check is to import the tarball as
121 described in the following section, using a different value for
122 'upstream-tag', and then use git-diff(1) to compare the imported
123 tarball to the release tag.  If they are the same, you can use
124 upstream's tarball instead of running git-archive(1).
125
126 =back
127
128 =head2 When upstream releases only tarballs
129
130 We need a virtual upstream branch with virtual release tags.
131 gbp-import-orig(1) can manage this for us.  To begin
132
133 =over 4
134
135     % mkdir foo
136     % cd foo
137     % git init
138
139 =back
140
141 Now create I<debian/gbp.conf>:
142
143 =over 4
144
145     [DEFAULT]
146     upstream-branch = upstream
147     debian-branch = master
148     upstream-tag = %(version)s
149
150     sign-tags = True
151     pristine-tar = False
152     pristine-tar-commit = False
153
154 =back
155
156 Then we can import the upstream version:
157
158 =over 4
159
160     % git add debian/gbp.conf && git commit -m "create gbp.conf"
161     % gbp import-orig ../foo_1.2.2.orig.tar.xz
162
163 =back
164
165 You are now ready to proceed as above, making commits to both the
166 upstream source and the I<debian/> directory.
167
168 If you want to maintain a copy of your repository on
169 B<alioth.debian.org>, you should push both the origin and the upstream
170 branches:
171
172 =over 4
173
174     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
175     % git push --follow-tags -u origin master upstream
176
177 =back
178
179 =head1 CONVERTING AN EXISTING PACKAGE
180
181 This section explains how to convert an existing Debian package to
182 this workflow.  It should be skipped when debianising a new package.
183
184 =head2 No existing git history
185
186 =over 4
187
188     % dgit clone foo
189     % cd foo
190     % git remote add -f upstream https://some.upstream/foo.git
191
192 =back
193
194 =head2 Existing git history using another workflow
195
196 First, dump any existing patch queue:
197
198 =over 4
199
200     % git rm -rf debian/patches
201     % git commit -m "drop existing quilt patch queue"
202
203 =back
204
205 Then make new upstream tags available:
206
207 =over 4
208
209     % git remote add -f upstream https://some.upstream/foo.git
210
211 =back
212
213 Now you simply need to ensure that your git HEAD is dgit-compatible,
214 i.e., it is exactly what you would get if you ran B<dpkg-buildpackage
215 -i\.git/ -I.git -S> and then unpacked the resultant source package.
216
217 To achieve this, you might need to delete
218 I<debian/source/local-options>.  One way to have dgit check your
219 progress is to run B<dgit build-source>.
220
221 The first dgit push will require I<--overwrite>.
222
223 =head1 SOURCE PACKAGE CONFIGURATION
224
225 =head2 debian/source/options
226
227 We set some source package options such that dgit can transparently
228 handle the "dropping" and "refreshing" of changes to the upstream
229 source:
230
231 =over 4
232
233     single-debian-patch
234     auto-commit
235
236 =back
237
238 You don't need to create this file if you are using the version 1.0
239 source package format.
240
241 =head2 Sample text for debian/source/patch-header
242
243 It is a good idea to explain how a user can obtain a break down of the
244 changes to the upstream source:
245
246 =over 4
247
248 The Debian packaging of foo is maintained using dgit.  For the sake of
249 an efficient workflow, Debian modifications to the upstream source are
250 squashed into a single diff, rather than a series of quilt patches.
251 To obtain a patch queue for package version 1.2.3-1:
252
253 =over 4
254
255     # apt-get install dgit
256     % dgit clone foo
257     % cd foo
258     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
259
260 =back
261
262 See dgit(1), dgit(7) and dgit-maint-merge(7) for more information.
263
264 =back
265
266 Alternatively, this text could be added to README.source. However,
267 this might distract from more important information present in the
268 latter file.
269
270 =head1 BUILDING AND UPLOADING
271
272 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
273 push> as detailed in dgit(1).  If any command fails, dgit will provide
274 a carefully-worded error message explaining what you should do.  If
275 it's not clear, file a bug against dgit.  Remember to pass I<--new>
276 for the first upload.
277
278 As an alternative to B<dgit build> and friends, you can use a tool
279 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
280 HEAD has exactly the contents of the source package.  gitpkg(1) is
281 highly configurable, and one dgit user reports using it to produce and
282 test multiple source packages, from different branches corresponding
283 to each of the current Debian suites.
284
285 If you want to skip dgit's checks while iterating on a problem with
286 the package build (for example, you don't want to commit your changes
287 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
288
289 =head1 NEW UPSTREAM RELEASES
290
291 =head2 When upstream tags releases in git
292
293 It's a good idea to preview the merge of the new upstream release.
294 First, just check for any new or deleted files that may need
295 accounting for in your copyright file:
296
297 =over 4
298
299     % git remote update
300     % git diff --stat master..1.2.3 -- . ':!debian'
301
302 =back
303
304 You can then review the full merge diff:
305
306 =over 4
307
308     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
309
310 =back
311
312 Once you're satisfied with what will be merged, update your package:
313
314 =over 4
315
316     % git archive -o ../foo_1.2.3.orig.tar.xz 1.2.3
317     % git merge 1.2.3
318     % dch -v1.2.3-1 New upstream release.
319     % git add debian/changelog && git commit -m changelog
320
321 =back
322
323 and you are ready to try a build.
324
325 Again, if you are using the version 1.0 source package format, replace
326 'xz' with 'gz'.
327
328 =head2 When upstream releases only tarballs
329
330 You will need the I<debian/gbp.conf> from "When upstream releases only
331 tarballs", above.
332
333 Then, either
334
335 =over 4
336
337     % gbp import-orig ../foo_1.2.2.orig.tar.xz
338
339 =back
340
341 or if you have a working watch file
342
343 =over 4
344
345     % gbp import-orig --uscan
346
347 =back
348
349 =head1 HANDLING DFSG-NON-FREE MATERIAL
350
351 =head2 When upstream tags releases in git
352
353 We create a DFSG-clean tag to merge to master:
354
355 =over 4
356
357     % git checkout -b pre-dfsg 1.2.3
358     % git rm evil.bin
359     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
360     % git tag -s 1.2.3+dfsg
361     % git checkout master
362     % git branch -D pre-dfsg
363
364 =back
365
366 Before merging the new 1.2.3+dfsg tag to master, you should first
367 determine whether it would be legally dangerous for the non-free
368 material to be publicly accessible in the git history on
369 B<dgit-repos>.
370
371 If it would be dangerous, there is a big problem;
372 in this case please consult your archive administrators
373 (for Debian this is the dgit administrator dgit-owner@debian.org
374 and the ftpmasters ftpmaster@ftp-master.debian.org).
375
376 =head2 When upstream releases only tarballs
377
378 The easiest way to handle this is to add a B<Files-Excluded> field to
379 I<debian/copyright>, and a B<uversionmangle> setting in
380 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
381 option detailed in gbp-import-orig(1).
382
383 =head1 FORWARDING PATCHES UPSTREAM
384
385 The basic steps are:
386
387 =over 4
388
389 =item 1.
390
391 Create a new branch based off upstream's master branch.
392
393 =item 2.
394
395 git-cherry-pick(1) commits from your master branch onto your new
396 branch.
397
398 =item 3.
399
400 Push the branch somewhere and ask upstream to merge it, or use
401 git-format-patch(1) or git-request-pull(1).
402
403 =back
404
405 For example (and it is only an example):
406
407 =over 4
408
409     % # fork foo.git on GitHub
410     % git remote add -f fork git@github.com:spwhitton/foo.git
411     % git checkout -b fix-error upstream/master
412     % git config branch.fix-error.pushRemote fork
413     % git cherry-pick master^2
414     % git push
415     % # submit pull request on GitHub
416
417 =back
418
419 Note that when you merge an upstream release containing your forwarded
420 patches, git and dgit will transparently handle "dropping" the patches
421 that have been forwarded, "retaining" the ones that haven't.
422
423 =head1 INCORPORATING NMUS
424
425 =over 4
426
427     % dgit pull
428
429 =back
430
431 Alternatively, you can apply the NMU diff to your repository.  The
432 next push will then require I<--overwrite>.
433
434 =head1 SEE ALSO
435
436 dgit(1), dgit(7)
437
438 =head1 AUTHOR
439
440 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.