chiark / gitweb /
03ccdfe84acb0e2e4310f455d5307293d7e8bd26
[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 If you prefer linear histories, see dgit-maint-gbp(7)
20 for a workflow based on git-buildpackage, or roll your own.
21
22 =item
23
24 Maintaining convenient and powerful git workflows takes priority over
25 the usefulness of the raw Debian source package.  The Debian archive
26 is thought of as an output format.
27
28 For example, we don't spend time curating a series of quilt patches.
29 However, the information such a series would contain is readily
30 available from B<dgit-repos>.
31
32 =item
33
34 It is more important to have the Debian package's git history be a
35 descendent of upstream's git history than to use exactly the orig.tar
36 that upstream makes available for download.
37
38 =back
39
40 =head1 GIT CONFIGURATION
41
42 Add the following to your ~/.gitconfig to teach git-archive(1) how to
43 compress orig tarballs:
44
45 =over 4
46
47     [tar "tar.xz"]
48         command = xz -c
49     [tar "tar.gz"]
50         command = gzip -c
51
52 =back
53
54 =head1 INITIAL DEBIANISATION
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 detachs 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.  Generate one with git-archive(1):
97
98 =over 4
99
100     % git archive -o ../foo_1.2.2.orig.tar.xz 1.2.2
101
102 =back
103
104 If you are using the version 1.0 source package format, replace 'xz'
105 with 'gz'.
106
107 This tarball is ephemeral and easily regenerated, so we don't commit
108 it anywhere (e.g. with tools like pristine-tar(1)).
109
110 =head3 Verifying upstream's tarball releases
111
112 =over 4
113
114 It can be a good idea to compare upstream's released tarballs with the
115 release tags, at least for the first upload of the package.  If they
116 are different, you might need to add some additional steps to your
117 I<debian/rules>, such as running autotools.
118
119 A convenient way to perform this check is to import the tarball as
120 described in the following section, using a different value for
121 'upstream-tag', and then use git-diff(1) to compare the imported
122 tarball to the release tag.  If they are the same, you can use
123 upstream's tarball instead of running git-archive(1).
124
125 =back
126
127 =head2 When upstream releases only tarballs
128
129 We need a virtual upstream branch with virtual release tags.
130 gbp-import-orig(1) can manage this for us.  To begin
131
132 =over 4
133
134     % mkdir foo
135     % cd foo
136     % git init
137
138 =back
139
140 Now create I<debian/gbp.conf>:
141
142 =over 4
143
144     [DEFAULT]
145     upstream-branch = upstream
146     debian-branch = master
147     upstream-tag = %(version)s
148
149     sign-tags = True
150     pristine-tar = False
151     pristine-tar-commit = False
152
153 =back
154
155 Then we can import the upstream version:
156
157 =over 4
158
159     % git add debian/gbp.conf && git commit -m "create gbp.conf"
160     % gbp import-orig ../foo_1.2.2.orig.tar.xz
161
162 =back
163
164 You are now ready to proceed as above, making commits to both the
165 upstream source and the I<debian/> directory.
166
167 If you want to maintain a copy of your repository on
168 B<alioth.debian.org>, you should push both the origin and the upstream
169 branches:
170
171 =over 4
172
173     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
174     % git push --follow-tags -u origin master upstream
175
176 =back
177
178 =head1 SOURCE PACKAGE CONFIGURATION
179
180 =head2 debian/source/options
181
182 We set some source package options such that dgit can transparently
183 handle the "dropping" and "refreshing" of changes to the upstream
184 source:
185
186 =over 4
187
188     single-debian-patch
189     auto-commit
190
191 =back
192
193 You don't need to create this file if you are using the version 1.0
194 source package format.
195
196 =head2 Sample text for README.source
197
198 It is a good idea to explain how a user can obtain a break down of the
199 changes to the upstream source:
200
201 =over 4
202
203 The Debian packaging of foo is maintained using dgit.  For the sake of
204 an efficient workflow, Debian modifications to the upstream source are
205 squashed into a single diff, rather than a series of quilt patches.
206 To obtain a patch queue for package version 1.2.3-1:
207
208 =over 4
209
210     # apt-get install dgit
211     % dgit clone foo
212     % cd foo
213     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
214
215 =back
216
217 See dgit(1), dgit(7) and dgit-maint-merge(7) for more information.
218
219 =back
220
221 =head1 BUILDING AND UPLOADING
222
223 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
224 push> as detailed in dgit(1).  If any command fails, dgit will provide
225 a carefully-worded error message explaining what you should do.  If
226 it's not clear, file a bug against dgit.  Remember to pass I<--new>
227 for the first upload.
228
229 As an alternative to B<dgit build> and friends, you can use a tool
230 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
231 HEAD has exactly the contents of the source package.  gitpkg(1) is
232 highly configurable, and one dgit user reports using it to produce and
233 test multiple source packages, from different branches corresponding
234 to each of the current Debian suites.
235
236 If you want to skip dgit's checks while iterating on a problem with
237 the package build (for example, you don't want to commit your changes
238 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
239
240 =head1 NEW UPSTREAM RELEASES
241
242 =head2 When upstream tags releases in git
243
244 It's a good idea to preview the merge of the new upstream release.
245 First, just check for any new or deleted files that may need
246 accounting for in your copyright file:
247
248 =over 4
249
250     % git remote update
251     % git diff --stat master..1.2.3 -- . ':!debian'
252
253 =back
254
255 You can then review the full merge diff:
256
257 =over 4
258
259     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
260
261 =back
262
263 Once you're satisfied with what will be merged, update your package:
264
265 =over 4
266
267     % git archive ../foo_1.2.3.orig.tar.xz 1.2.3
268     % git merge 1.2.3
269     % dch -v1.2.3-1 New upstream release.
270     % git add debian/changelog && git commit -m changelog
271
272 =back
273
274 and you are ready to try a build.
275
276 Again, if you are using the version 1.0 source package format, replace
277 'xz' with 'gz'.
278
279 =head2 When upstream releases only tarballs
280
281 Either
282
283 =over 4
284
285     % gbp import-orig ../foo_1.2.2.orig.tar.xz
286
287 =back
288
289 or if you have a working watch file
290
291 =over 4
292
293     % gbp import-orig --uscan
294
295 =back
296
297 =head1 HANDLING DFSG-NON-FREE MATERIAL
298
299 =head2 When upstream tags releases in git
300
301 We create a DFSG-clean tag to merge to master:
302
303 =over 4
304
305     % git checkout -b pre-dfsg 1.2.3
306     % git rm evil.bin
307     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
308     % git tag -s 1.2.3+dfsg
309     % git checkout master
310     % git branch -D pre-dfsg
311
312 =back
313
314 Before merging the new 1.2.3+dfsg tag to master, you should first
315 determine whether it would be legally dangerous for the non-free
316 material to be publicly accessible in the git history on
317 B<dgit-repos>.
318
319 If it would be dangerous, there is a big problem;
320 in this case please consult your archive administrators
321 (for Debian this is the dgit administrator dgit-owner@debian.org
322 and the ftpmasters ftpmaster@ftp-master.debian.org).
323
324 =head2 When upstream releases only tarballs
325
326 The easiest way to handle this is to add a B<Files-Excluded> field to
327 I<debian/copyright>, and a B<uversionmangle> setting in
328 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
329 option detailed in gbp-import-orig(1).
330
331 =head1 FORWARDING PATCHES UPSTREAM
332
333 The basic steps are:
334
335 =over 4
336
337 =item 1.
338
339 Create a new branch based off upstream's master branch.
340
341 =item 2.
342
343 git-cherry-pick(1) commits from your master branch onto your new
344 branch.
345
346 =item 3.
347
348 Push the branch somewhere and ask upstream to merge it, or use
349 git-format-patch(1) or git-request-pull(1).
350
351 =back
352
353 For example (and it is only an example):
354
355 =over 4
356
357     % # fork foo.git on GitHub
358     % git remote add -f fork git@github.com:spwhitton/foo.git
359     % git checkout -b fix-error upstream/master
360     % git config branch.fix-error.pushRemote fork
361     % git cherry-pick master^2
362     % git push
363     % # submit pull request on GitHub
364
365 =back
366
367 Note that when you merge an upstream release containing your forwarded
368 patches, git and dgit will transparently handle "dropping" the patches
369 that have been forwarded, "retaining" the ones that haven't.
370
371 =head1 INCORPORATING NMUS
372
373 =over 4
374
375     % dgit pull
376
377 =back
378
379 Alternatively, you can apply the NMU diff to your repository.  The
380 next push will then require I<--overwrite>.
381
382 =head1 SEE ALSO
383
384 dgit(1), dgit(7)
385
386 =head1 AUTHOR
387
388 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.