chiark / gitweb /
dgit-sponsorship(7): Add import-dsc for NEW package
[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-rebase(7).
20
21 =item
22
23 Maintaining convenient and powerful git workflows takes priority over
24 the usefulness of the raw Debian source package.  The Debian archive
25 is thought of as an output format.
26
27 For example, we don't spend time curating a series of quilt patches.
28 However, 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 =head1 GIT CONFIGURATION
40
41 Add the following to your ~/.gitconfig to teach git-archive(1) how to
42 compress orig tarballs:
43
44 =over 4
45
46     [tar "tar.xz"]
47         command = xz -c
48     [tar "tar.gz"]
49         command = gzip -c
50
51 =back
52
53 =head1 INITIAL DEBIANISATION
54
55 =head2 When upstream tags releases in git
56
57 Suppose that the latest stable upstream release is 1.2.2, and this has
58 been tagged '1.2.2' by upstream.
59
60 =over 4
61
62     % git clone -oupstream https://some.upstream/foo.git
63     % cd foo
64     % git verify-tag 1.2.2
65     % git reset --hard 1.2.2
66     % git branch --unset-upstream
67
68 =back
69
70 The final command detachs your master branch from the upstream remote,
71 so that git doesn't try to push anything there, or merge unreleased
72 upstream commits.  If you want to maintain a copy of your packaging
73 branch on B<alioth.debian.org> in addition to B<dgit-repos>, you can
74 do something like this:
75
76 =over 4
77
78     % git remote add -f origin git.debian.org:/git/collab-maint/foo.git
79     % git push --follow-tags -u origin master
80
81 =back
82
83 Now go ahead and Debianise your package.  Just make commits on the
84 master branch, adding things in the I<debian/> directory.  If you need
85 to patch the upstream source, just make commits that change files
86 outside of the I<debian/> directory.  It is best to separate commits
87 that touch I<debian/> from commits that touch upstream source, so that
88 the latter can be cherry-picked by upstream.
89
90 Note that there is no need to maintain a separate 'upstream' branch,
91 unless you also happen to be involved in upstream development.  We
92 work with upstream tags rather than any branches, except when
93 forwarding patches (see FORWARDING PATCHES UPSTREAM, below).
94
95 Finally, you need an orig tarball.  Generate one with git-archive(1):
96
97 =over 4
98
99     % git archive -o ../foo_1.2.2.orig.tar.xz 1.2.2
100
101 =back
102
103 If you are using the version 1.0 source package format, replace 'xz'
104 with 'gz'.
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-archive(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 SOURCE PACKAGE CONFIGURATION
178
179 =head2 debian/source/options
180
181 We set some source package options such that dgit can transparently
182 handle the "dropping" and "refreshing" of changes to the upstream
183 source:
184
185 =over 4
186
187     single-debian-patch
188     auto-commit
189
190 =back
191
192 You don't need to create this file if you are using the version 1.0
193 source package format.
194
195 =head2 Sample text for README.source
196
197 It is a good idea to explain how a user can obtain a break down of the
198 changes to the upstream source:
199
200 =over 4
201
202 The Debian packaging of foo is maintained using dgit.  For the sake of
203 an efficient workflow, Debian modifications to the upstream source are
204 squashed into a single diff, rather than a series of quilt patches.
205 To obtain a patch queue for package version 1.2.3-1:
206
207 =over 4
208
209     # apt-get install dgit
210     % dgit clone foo
211     % cd foo
212     % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'
213
214 =back
215
216 See dgit(1), dgit(7) and dgit-maint-merge(7) for more information.
217
218 =back
219
220 =head1 BUILDING AND UPLOADING
221
222 Use B<dgit build>, B<dgit sbuild>, B<dgit build-source>, and B<dgit
223 push> as detailed in dgit(1).  If any command fails, dgit will provide
224 a carefully-worded error message explaining what you should do.  If
225 it's not clear, file a bug against dgit.  Remember to pass I<--new>
226 for the first upload.
227
228 As an alternative to B<dgit build> and friends, you can use a tool
229 like gitpkg(1).  This works because like dgit, gitpkg(1) enforces that
230 HEAD has exactly the contents of the source package.  gitpkg(1) is
231 highly configurable, and one dgit user reports using it to produce and
232 test multiple source packages, from different branches corresponding
233 to each of the current Debian suites.
234
235 If you want to skip dgit's checks while iterating on a problem with
236 the package build (for example, you don't want to commit your changes
237 to git), you can just run dpkg-buildpackage(1) or debuild(1) instead.
238
239 =head1 NEW UPSTREAM RELEASES
240
241 =head2 When upstream tags releases in git
242
243 It's a good idea to preview the merge of the new upstream release.
244 First, just check for any new or deleted files that may need
245 accounting for in your copyright file:
246
247 =over 4
248
249     % git remote update
250     % git diff --stat master..1.2.3 -- . ':!debian'
251
252 =back
253
254 You can then review the full merge diff:
255
256 =over 4
257
258     % git merge-tree `git merge-base master 1.2.3` master 1.2.3 | $PAGER
259
260 =back
261
262 Once you're satisfied with what will be merged, update your package:
263
264 =over 4
265
266     % git archive ../foo_1.2.3.orig.tar.xz 1.2.3
267     % git merge 1.2.3
268     % dch -v1.2.3-1 New upstream release.
269     % git add debian/changelog && git commit -m changelog
270
271 =back
272
273 and you are ready to try a build.
274
275 Again, if you are using the version 1.0 source package format, replace
276 'xz' with 'gz'.
277
278 =head2 When upstream releases only tarballs
279
280 Either
281
282 =over 4
283
284     % gbp import-orig ../foo_1.2.2.orig.tar.xz
285
286 =back
287
288 or if you have a working watch file
289
290 =over 4
291
292     % gbp import-orig --uscan
293
294 =back
295
296 =head1 HANDLING DFSG-NON-FREE MATERIAL
297
298 =head2 When upstream tags releases in git
299
300 We create a DFSG-clean tag to merge to master:
301
302 =over 4
303
304     % git checkout -b pre-dfsg 1.2.3
305     % git rm evil.bin
306     % git commit -m "upstream version 1.2.3 DFSG-cleaned"
307     % git tag -s 1.2.3+dfsg
308     % git checkout master
309     % git branch -D pre-dfsg
310
311 =back
312
313 Before merging the new 1.2.3+dfsg tag to master, you should first
314 determine whether it would be legally dangerous for the non-free
315 material to be publicly accessible in the git history on
316 B<dgit-repos>.
317
318 If it would be dangerous, there is a big problem;
319 in this case please consult your archive administrators
320 (for Debian this is the dgit administrator dgit-owner@debian.org
321 and the ftpmasters ftpmaster@ftp-master.debian.org).
322
323 =head2 When upstream releases only tarballs
324
325 The easiest way to handle this is to add a B<Files-Excluded> field to
326 I<debian/copyright>, and a B<uversionmangle> setting in
327 I<debian/watch>.  See uscan(1).  Alternatively, see the I<--filter>
328 option detailed in gbp-import-orig(1).
329
330 =head1 FORWARDING PATCHES UPSTREAM
331
332 The basic steps are:
333
334 =over 4
335
336 =item 1.
337
338 Create a new branch based off upstream's master branch.
339
340 =item 2.
341
342 git-cherry-pick(1) commits from your master branch onto your new
343 branch.
344
345 =item 3.
346
347 Push the branch somewhere and ask upstream to merge it, or use
348 git-format-patch(1) or git-request-pull(1).
349
350 =back
351
352 For example (and it is only an example):
353
354 =over 4
355
356     % # fork foo.git on GitHub
357     % git remote add -f fork git@github.com:spwhitton/foo.git
358     % git checkout -b fix-error upstream/master
359     % git config branch.fix-error.pushRemote fork
360     % git cherry-pick master^2
361     % git push
362     % # submit pull request on GitHub
363
364 =back
365
366 Note that when you merge an upstream release containing your forwarded
367 patches, git and dgit will transparently handle "dropping" the patches
368 that have been forwarded, "retaining" the ones that haven't.
369
370 =head1 INCORPORATING NMUS
371
372 =over 4
373
374     % dgit pull
375
376 =back
377
378 Alternatively, you can apply the NMU diff to your repository.  The
379 next push will then require I<--overwrite>.
380
381 =head1 SEE ALSO
382
383 dgit(1), dgit(7)
384
385 =head1 AUTHOR
386
387 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.