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