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