import.sgml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <chapter id="gbp.import">
  2. <title>Importing Sources</title>
  3. <sect1 id="gbp.import.existing">
  4. <title>Importing already existing &debian; packages</title>
  5. <para>Importing an already existing &debian; package into a &git; repository is as easy as:
  6. <programlisting>
  7. &gbp-import-dsc; package_0.1-1.dsc
  8. </programlisting>
  9. This will create a new &git; repository named after the imported package, put
  10. the upstream sources onto the <option>upstream-branch</option> and the
  11. &debian; patch on the <option>debian-branch</option>. In case of a &debian;
  12. native package, only the <option>debian-branch</option> is being used.
  13. You can specify alternative branch names via the
  14. <option>--upstream-branch</option> and <option>--debian-branch</option>
  15. options, or via the <option>upstream-branch</option> and
  16. <option>debian-branch</option> options in the configuration file.
  17. </para>
  18. <para>
  19. If you want to be able to exactly recreate the original tarball
  20. (orig.tar.gz) from &git;, you should also specify the
  21. <option>--pristine-tar</option> option. This is recommended.
  22. </para>
  23. <para>
  24. If you want to import further versions, you can change into your shiny new
  25. &git; repository and just continue with the same command:
  26. <programlisting>
  27. cd package/
  28. &gbp-import-dsc; package_0.1-2.dsc
  29. &gbp-import-dsc; package_0.1-3.dsc
  30. &gbp-import-dsc; package_0.2-1.dsc
  31. </programlisting>
  32. </para>
  33. <para>
  34. Or you can import all versions at once using &gbp-import-dscs;:
  35. <programlisting>
  36. &gbp-import-dscs; /path/to/history/package_*.dsc
  37. </programlisting>
  38. This will create a &git; repository if necessary and import all versions sorted
  39. by version number.
  40. </para>
  41. <para>You can also import all versions of a package known from the
  42. <ulink url="http://snapshot.debian.org/">snapshot.debian.org</ulink> service
  43. using the <option>--debsnap</option> option of &gbp-import-dscs;:
  44. <programlisting>
  45. &gbp-import-dscs; --debsnap package
  46. </programlisting>
  47. </para>
  48. </sect1>
  49. <sect1 id="gbp.import.new.upstream">
  50. <title>Importing a new upstream version</title>
  51. <para>Change into your &git; repository (which can be empty), make sure it
  52. has all local modifications committed, and run either of:
  53. <programlisting>
  54. &gbp-import-orig; <filename>/path/to/package_0.2.orig.tar.gz</filename>
  55. &gbp-import-orig; <filename>/path/to/package_0.2.tar.bz2</filename>
  56. &gbp-import-orig; <filename>/path/to/package-0.2/</filename>
  57. </programlisting>
  58. This puts the upstream sources onto the <option>upstream-branch</option> and
  59. tags them accordingly (the default tag format is
  60. <replaceable>upstream/%(version)s</replaceable>).
  61. The result is then merged onto the <option>debian-branch</option>,
  62. and a new &debian; changelog entry is created. You can again specify
  63. different branch names via the <option>--upstream-branch</option> and
  64. <option>--debian-branch</option> options.
  65. </para>
  66. <para>If you are using <filename>debian/watch</filename> to keep track of how to retrieve upstream sources, you can also simply use the <option>--uscan</option> option:
  67. <programlisting>
  68. &gbp-import-orig; --uscan
  69. </programlisting>
  70. </para>
  71. <para>You can also filter out content
  72. you don't want imported:
  73. <programlisting>
  74. &gbp-import-orig; <option>--filter</option>=<replaceable>'CVS/*'</replaceable> <filename>/path/to/package_0.2.orig.tar.gz</filename>
  75. </programlisting>
  76. The <option>--filter</option> option can be used multiple times for more
  77. complex filtering.
  78. </para>
  79. <para>
  80. If you expect a merge conflict, you can delay the merge to the
  81. <option>debian-branch</option> via the <option>--no-merge</option> option and pull in
  82. the changes from the <option>upstream-branch</option> later.
  83. </para>
  84. <para>
  85. If you want to be able to exactly recreate the original tarball
  86. (orig.tar.gz) from &git;, you should also specify the
  87. <option>--pristine-tar</option> option. This is recommended.
  88. </para>
  89. <para>To customize the commit message used by &gbp-import-orig;, use
  90. the <option>--import-msg</option> option. This string is a standard
  91. Python format string, into which the
  92. <replaceable>version</replaceable> variable is interpolated. (i.e.,
  93. use <replaceable>%(version)s</replaceable> in your message to get
  94. the imported upstream version).
  95. </para>
  96. </sect1>
  97. <sect1 id="gbp.import.convert">
  98. <title>Converting an existing &git; repository</title>
  99. <para>
  100. If the &git; repository wasn't created with &gbp-import-dsc;, you have to
  101. tell &gbp-buildpackage; and friends where to find the upstream sources.
  102. </para>
  103. <sect2>
  104. <title>Upstream sources on a branch</title>
  105. <para>
  106. If the upstream sources are already on a separate branch, things are pretty
  107. simple. You can either rename that branch to the default
  108. <option>upstream-branch</option> name <emphasis>upstream</emphasis> with:
  109. <programlisting>
  110. &gitcmd; branch upstream theupstream-branch
  111. &gitcmd; branch <option>-D</option> theupstream-branch
  112. </programlisting>
  113. or you can tell &gbp-buildpackage; the name of the branch to use as
  114. <option>upstream-branch</option>:
  115. <programlisting>
  116. <command>cat</command> &lt;&lt;EOF &gt; <filename>.git/gbp.conf</filename>
  117. [DEFAULT]
  118. # this is the upstream-branch:
  119. upstream-branch=theupstream-branch
  120. EOF
  121. </programlisting>
  122. If you then use &gbp-import-orig; to import new upstream sources, they will
  123. from now on end up on <emphasis>theupstream-branch</emphasis> and
  124. merged to the <option>debian-branch</option>.
  125. </para>
  126. </sect2>
  127. <sect2>
  128. <title>Upstream sources not on a branch</title>
  129. <para>
  130. If you don't have an upstream branch but started your repository with only
  131. the upstream sources (not the &debian; patch), you can simply branch from that
  132. point. So use &gitkcmd; or &gitcmd;-log to locate the commit-id of that commit
  133. and create the upstream branch from there, e.g.:
  134. <programlisting>
  135. COMMIT_ID=`&gitcmd; log --pretty=oneline | tail -1 | awk '{ print $1 }'`
  136. &gitcmd; branch upstream $COMMIT_ID
  137. </programlisting>
  138. The important thing here is that the <envar>COMMIT_ID</envar> specifies a
  139. point on the master branch that carried <emphasis>only</emphasis> the
  140. upstream sources and not the &debian; modifications. The above example
  141. assumes that this was the first commit to that repository.
  142. </para>
  143. <warning><para>There's currently no <emphasis>easy</emphasis> way to create the
  144. <option>upstream-branch</option> if you never had the upstream sources
  145. as a single commit. Using &gbp-import-orig; on such repositories might lead
  146. to unexpected merge results.</para></warning>
  147. <para>In order to fix this you can prepend the upstream sources as a
  148. single commit to your tree using &git;'s <ulink
  149. url="http://git.or.cz/gitwiki/GraftPoint">grafts</ulink>. Afterwards you
  150. can simply create a branch as explained above and &gbp-import-orig; will
  151. work as expected.</para>
  152. <para>Alternatively, if you are only importing source from original tarballs
  153. (for instance when converting from a Subversion repository where the
  154. mergeWithUpstream was set for svn-buildpackage), you can create an empty
  155. upstream branch with the following commands:
  156. <programlisting>
  157. <command>git checkout</command> <option>--orphan</option> <replaceable>upstream</replaceable>
  158. <command>git rm</command> <option>-rf</option> <replaceable>.</replaceable>
  159. <command>git commit</command> <option>--allow-empty</option> <option>-m</option> <replaceable>'Initial upstream branch.'</replaceable>
  160. <command>git checkout</command> <option>-f</option> <replaceable>master</replaceable>
  161. </programlisting>
  162. With Git versions lower than 1.7.2.3, the commands are slightly more complicated:
  163. <programlisting>
  164. <command>git symbolic-ref</command> <replaceable>HEAD</replaceable> <replaceable>refs/heads/upstream</replaceable>
  165. <command>git rm</command> <option>--cached</option> <option>-r</option> <replaceable>.</replaceable>
  166. <command>git commit</command> <option>--allow-empty</option> <option>-m</option> <replaceable>'Initial upstream branch.'</replaceable>
  167. <command>git checkout</command> <option>-f</option> <replaceable>master</replaceable>
  168. </programlisting>
  169. </para>
  170. </sect2>
  171. </sect1>
  172. <sect1 id="gbp.import.fromscratch">
  173. <title>Starting a &debian; package from scratch</title>
  174. <para>
  175. So far, we assumed you already have a &debian; package to start with, but
  176. what if you want to start a new package? First, create an empty repository:
  177. </para>
  178. <programlisting>
  179. <command>mkdir</command> package-0.1
  180. <command>cd</command> package-0.1
  181. <command>git init</command>
  182. </programlisting>
  183. <para>Then, you import the upstream sources, branch off the
  184. <option>upstream-branch</option> branch and add the &debian; files (e.g. via dh_make):
  185. <programlisting>
  186. &gbp-import-orig; <option>-u</option> <replaceable>0.1</replaceable> <filename>../package-0.1.tar.gz</filename>
  187. <command>dh_make</command>
  188. </programlisting>
  189. That's it, you're done. If you want to publish your new repository, you can use &gbp-create-remote-repo;.
  190. </para>
  191. </sect1>
  192. <sect1 id="gbp.import.upstream-git">
  193. <title>When upstream uses Git</title>
  194. <para>
  195. If upstream already uses git for packaging, there are several ways to handle packaging. Two of them will
  196. be described in a bit detail here:
  197. </para>
  198. <sect2 id="gbp.import.upstream.git.notarball">
  199. <title>No upstream tarballs</title>
  200. <para>If upstream doesn't build upstream tarballs, or you don't care about them, the simplest
  201. way is to clone upstream's repository and create a separate packaging branch in there.
  202. </para>
  203. <para>
  204. In order to help &gbp-buildpackage; to find upstream tags, you need to specify the format
  205. using the <option>--git-upstream-tag</option> command line option or the the <option>upstream-tag</option>
  206. configuration variable.
  207. </para>
  208. <para>
  209. A common upstream format is to put a <replaceable>v</replaceable> in front of the version number.
  210. In this case, the configuration option would look like:
  211. </para>
  212. <programlisting>
  213. [git-buildpackage]
  214. upstream-tag = v%(version)s
  215. </programlisting>
  216. <para>
  217. <replaceable>version</replaceable> will be replaced with the upstream version number as read from
  218. <filename>debian/changelog</filename>.
  219. </para>
  220. <para>If you're using &pristine-tar;, you can make &gbp-buildpackage; commit the generated tarball back to the
  221. pristine-tar branch by using the <option>--git-pristine-tar-commit</option> option. This will make sure
  222. others building your package can regenerate the tarball you generated for building the &debian; package.
  223. </para>
  224. <sect3>
  225. <title>Step by step</title>
  226. <para>To not make any assumptions about &gbp;'s configuration, the following steps have all options given
  227. in its long versions on the command line. You can add these
  228. to &gbp.conf; to save lots of typing.
  229. </para>
  230. <para>First, we clone the upstream repository. To avoid any ambiguities between the &debian; packaging repository
  231. and the upstream repository, we name the upstream repository <replaceable>upstream</replaceable> instead of the
  232. default <replaceable>origin</replaceable>.
  233. <programlisting>
  234. <command>git clone</command> --no-checkout -o upstream git://git.example.com/libgbp.git
  235. <command>cd</command> libgbp
  236. <command>git checkout</command> -b debian/sid v1.0
  237. </programlisting>
  238. The above makes sure we have <replaceable>debian/sid</replaceable> for the &debian; packaging. We didn't create
  239. any <replaceable>upstream/*</replaceable> branches; they're not needed for the packaging and only need to be
  240. kept up to date. After adding the &debian; packaging, we build the package. This assumes you're using &pristine-tar;
  241. and upstream uses a version number format as described above:
  242. <programlisting>
  243. <command>gbp buildpackage</command> --git-pristine-tar --git-pristine-tar-commit --git-upstream-tag='v%(version)s' --git-debian-branch=debian/sid
  244. </programlisting>
  245. When updating to a new upstream version, we simply fetch from upstream and merge in the new tag. Afterwards, we
  246. update the changelog and build the package:
  247. <programlisting>
  248. <command>git fetch</command> upstream
  249. <command>git merge</command> v1.1
  250. <command>gbp dch</command> --debian-branch=debian/sid --snapshot --auto debian/
  251. &gbp-buildpackage; --git-ignore-new --git-pristine-tar --git-pristine-tar-commit --git-upstream-tag='v%(version)s'
  252. </programlisting>
  253. Note that the above &gbp-dch; call makes sure we only pickup changes in the <filename>debian/</filename>
  254. directory. Since we told it to build a snapshot changelog entry and we hadn't commit the changelog yet,
  255. we need to tell &gbp-buildpackage; that the working directory is unclean via the <option>--git-ignore-new</option> option.
  256. Once everything looks good, commit the changelog and build a release version:
  257. <programlisting>
  258. <command>gbp dch</command> --release --auto --git-debian-branch=debian/sid
  259. <command>git commit</command> -m"Release 1.1-1" debian/changelog
  260. &gbp-buildpackage; --git-upstream-tag='v%(version)s' --git-debian-branch=debian/sid
  261. </programlisting>
  262. If you want to share your repository with others, you can use &gbp-create-remote-repo; and &gbp-pull; as usual.
  263. </para>
  264. </sect3>
  265. </sect2>
  266. <sect2 id="gbp.import.upstream.git.tarball">
  267. <title>Upstream tarballs</title>
  268. <para>If you want to track upstream's &git; but continue to import the upstream tarballs,
  269. e.g. to make sure the tarball uploaded
  270. to &debian; has the same checksum as upstream's, you can use the <option>--upstream-vcs-tag</option> option
  271. when importing new tarballs with &gbp-import-orig;. Assuming you have the upstream source in your
  272. repository with a tag <replaceable>v0.0.1</replaceable>, you can use:
  273. <programlisting>
  274. &gbp-import-orig; --upstream-vcs-tag=v0.0.1 foo_0.0.1.orig.tar.gz
  275. </programlisting>
  276. to add upstream's tag as additional parent to the merge commit.
  277. See <ulink url="http://bugs.debian.org/664771">#664771</ulink> for more details.
  278. </para>
  279. </sect2>
  280. </sect1>
  281. <sect1 id="gbp.branch.naming">
  282. <title>Branch layout</title>
  283. <para>
  284. By default, &gbp; uses one branch to keep the &debian; packaging called <emphasis>master</emphasis>
  285. and a branch to keep the upstream packaging called <emphasis>upstream</emphasis>.
  286. </para>
  287. <para>
  288. This layout is simple to get started but falls short if one needs to maintain several versions of
  289. the package at the same time. Therefore the following layout is recommended:
  290. </para>
  291. <variablelist>
  292. <varlistentry>
  293. <term>
  294. debian/&lt;release&gt;
  295. </term>
  296. <listitem>
  297. <para>
  298. the &debian; packaging for a release <emphasis>jessie</emphasis>,
  299. <emphasis>stretch</emphasis>, <emphasis>sid</emphasis>, <emphasis>jessie</emphasis>, <emphasis>jessie-backports</emphasis>, <emphasis>jessie-security</emphasis>
  300. or <emphasis>experimental</emphasis>.
  301. </para>
  302. </listitem>
  303. </varlistentry>
  304. <varlistentry>
  305. <term>
  306. upstream/&lt;release&gt;
  307. </term>
  308. <listitem>
  309. <para>
  310. the upstream sources for a release matching one of the above
  311. </para>
  312. </listitem>
  313. </varlistentry>
  314. <varlistentry>
  315. <term>
  316. dfsg/&lt;release&gt;
  317. </term>
  318. <listitem>
  319. <para>
  320. the DFSG-clean upstream sources in case the cleanup is done via a &git;
  321. merge from upstream to this branch.
  322. </para>
  323. </listitem>
  324. </varlistentry>
  325. </variablelist>
  326. <para>
  327. In case &pristine-tar; is being used, there will be a single <emphasis>pristine-tar</emphasis>
  328. branch that keeps all binary deltas.
  329. </para>
  330. </sect1>
  331. </chapter>
  332. <!-- LocalWords: tarballs
  333. -->