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