Commit ae7ed14e authored by Guido Günther's avatar Guido Günther

export_orig: new command to export orig tarballs from git

Closes: #840089
parent cfd884f1
......@@ -23,6 +23,7 @@ usr/lib/python3.?/dist-packages/gbp/scripts/dch.py usr/lib/python3/dist-packages
usr/lib/python3.?/dist-packages/gbp/scripts/import_dsc.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/import_dscs.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/import_orig.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/export_orig.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/__init__.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/pq.py usr/lib/python3/dist-packages/gbp/scripts/
usr/lib/python3.?/dist-packages/gbp/scripts/pristine_tar.py usr/lib/python3/dist-packages/gbp/scripts/
......
......@@ -5,6 +5,7 @@ docs/gbp.conf.5
docs/gbp-config.1
docs/gbp-create-remote-repo.1
docs/gbp-dch.1
docs/gbp-export-orig.1
docs/gbp-import-dsc.1
docs/gbp-import-dscs.1
docs/gbp-import-orig.1
......
......@@ -7,6 +7,7 @@ MAN1S = \
gbp-config \
gbp-create-remote-repo \
gbp-dch \
gbp-export-orig \
gbp-import-dsc \
gbp-import-dscs \
gbp-import-orig \
......
......@@ -11,6 +11,7 @@
<!ENTITY gbp-import-dscs "<command>gbp&nbsp;import-dscs</command>">
<!ENTITY gbp-config "<command>gbp&nbsp;config</command>">
<!ENTITY gbp-dch "<command>gbp&nbsp;dch</command>">
<!ENTITY gbp-export-orig "<command>gbp&nbsp;export-orig</command>">
<!ENTITY gbp "<command>gbp</command>">
<!ENTITY gbp-pull "<command>gbp&nbsp;pull</command>">
<!ENTITY gbp-clone "<command>gbp&nbsp;clone</command>">
......
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [
<!ENTITY % COMMON SYSTEM "common.ent">
%COMMON;
<!ENTITY % MANPAGES SYSTEM "manpages/manpages.ent">
%MANPAGES;
]>
<reference>
<title>git-buildpackage Manual</title>
&man.gbp.exportorig;
</reference>
<refentry id="man.gbp.export.orig">
<refentryinfo>
<address>
&dhemail;
</address>
<author>
&dhfirstname;
&dhsurname;
</author>
</refentryinfo>
<refmeta><refentrytitle>gbp-export-orig</refentrytitle>
&dhsection;
</refmeta>
<refnamediv>
<refname>gbp-export-orig</refname>
<refpurpose>Export upstream tarballs from a &git; repository</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
&gbp-export-orig;
<arg><option>--verbose</option></arg>
<arg><option>--color=</option>[auto|on|off]</arg>
<arg><option>--color-scheme</option>=<replaceable>COLOR_SCHEME</replaceable></arg>
<arg><option>--upstream-branch=</option><replaceable>TREEISH</replaceable></arg>
<arg><option>--[no-]submodules</option></arg>
<arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg>
<arg><option>--upstream-tree=</option><replaceable>[TAG|BRANCH|TREEISH]</replaceable></arg>
<arg><option>--tarball-dir=</option><replaceable>DIRECTORY</replaceable></arg>
<arg><option>--force-create</option></arg>
<arg><option>--compression=</option><replaceable>TYPE</replaceable></arg>
<arg><option>--compression-level=</option><replaceable>LEVEL</replaceable></arg>
<arg rep='repeat'><option>--component=</option><replaceable>component</replaceable></arg>
<arg><option>--[no-]pristine-tar</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
&gbp-export-orig; is used to export upstream tarballs from a
&git; repository. Usually upstream tarballs are created by
&gbp-buildpackage; when needed but if you don't want to perform
a build you can use this command.
</para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term><option>--verbose</option>
</term>
<listitem>
<para>
verbose execution
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--color=</option>[auto|on|off]
</term>
<listitem>
<para>
Whether to use colored output.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--color-scheme</option>=<replaceable>COLOR_SCHEME</replaceable>
</term>
<listitem>
<para>
Colors to use in output (when color is enabled). The format for
COLOR_SCHEME is
'&lt;debug&gt;:&lt;info&gt;:&lt;warning&gt;:&lt;error&gt;'.
Numerical values and color names are accepted, empty fields imply
the default color. For example --color-scheme='cyan:34::' would
show debug messages in cyan, info messages in blue and other messages
in default (i.e. warning and error messages in red).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--upstream-branch</option>=<replaceable>BRANCH_NAME</replaceable>
</term>
<listitem>
<para>
Branch to build the orig tarball from if
<option>--upstream-tree</option> is set to
<replaceable>BRANCH</replaceable>. Default is
<replaceable>upstream</replaceable>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--[no-]submodules</option>
</term>
<listitem>
<para>
Include git submodules in the orig tarball.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--upstream-tag=</option><replaceable>TAG-FORMAT</replaceable>
</term>
<listitem>
<para>
Use this tag format when looking for tags of upstream versions,
default is <replaceable>upstream/%(version)s</replaceable>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--force-create</option>
</term>
<listitem>
<para>
Force creation of an orig tarball (overwriting a pre-existing one if
present).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--upstream-tree=</option><replaceable>[BRANCH|SLOPPY|TAG|TREEISH]</replaceable>
</term>
<listitem>
<para>
How to find the upstream sources used to generate the tarball.
<replaceable>TAG</replaceable> (the default) looks at a tag corresponding to the
version in the changelog. <replaceable>BRANCH</replaceable> looks at
the upstream branch given via the
<option>--upstream-branch</option> option. The <replaceable>SLOPPY</replaceable>
option looks at the debian branch given via
the <option>--debian-branch</option> and drops
the <filename>debian/</filename> dir.
</para>
<para>
Other values are interpreted as treeishs.
</para>
<para>
This doesn't have any effect if <option>--pristine-tar</option>
is being used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--tarball-dir=</option><replaceable>DIRECTORY</replaceable>
</term>
<listitem>
<para>
Search for original tarballs in <replaceable>DIRECTORY</replaceable>
instead of generating them.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--compression=</option><replaceable>TYPE</replaceable>
</term>
<listitem>
<para>
Specifies the upstream tarball compression type. This will be used to
locate and build the upstream tarball if necessary. The default is
<replaceable>auto</replaceable> which derives the compression type
from the pristine-tar branch if available and falls back to gzip
otherwise. Other options are <replaceable>gzip</replaceable>,
<replaceable>bzip2</replaceable>, <replaceable>lzma</replaceable> and
<replaceable>xz</replaceable>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--compression-level=</option><replaceable>LEVEL</replaceable>
</term>
<listitem>
<para>
Specifies the upstream tarball compression level if an upstream
tarball needs to be built.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--component=</option><replaceable>COMPONENT</replaceable>
</term>
<listitem>
<para>
When generating tarballs create an additional original
tarball of directory <replaceable>COMPONENT</replaceable>
in the source tree. Using additional original tarballs is
a feature of the 3.0 (quilt) source format. See
the <command>dpkg-source</command> manpage for details. Note that the
<replaceable>--pristine-tar-commit</replaceable>
option is currently incompatible with this option.
</para>
<para>
This is considered an experimental feature and might
change incompatibly.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--pristine-tar</option>
</term>
<listitem>
<para>
Use pristine-tar when generating the upstream tarball if it doesn't
exist.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>EXAMPLES</title>
<para>
Build a &debian; package using &git-pbuilder; which in turn invokes
&cowbuildercmd;. Instruct cowbuilder to build within a Wheezy chroot for
i386.
</para>
<screen>
&gbp-buildpackage; --pbuilder --arch=i386 --dist=wheezy
</screen>
</refsect1>
<refsect1>
&man.gbp.config-files;
</refsect1>
<refsect1>
<title>SEE ALSO</title>
<para>
<xref linkend="man.gbp.buildpackage"/>,
<xref linkend="man.gbp.import.orig"/>,
<xref linkend="man.gbp.pristine.tar"/>,
<xref linkend="man.gbp.conf"/>,
&man.seealso.common;
</para>
</refsect1>
<refsect1>
<title>AUTHOR</title>
<para>
&dhusername; &dhemail;
</para>
</refsect1>
</refentry>
......@@ -161,6 +161,7 @@
<xref linkend="man.gbp.dch"/>,
<xref linkend="man.gbp.pq"/>,
<xref linkend="man.gbp.pristine.tar"/>,
<xref linkend="man.gbp.export.orig"/>,
<xref linkend="man.gbp.create.remote.repo"/>,
<xref linkend="man.gbp.pull"/>,
<xref linkend="man.gbp.clone"/>,
......
......@@ -4,6 +4,7 @@
<!ENTITY man.gbp.buildpackage SYSTEM "gbp-buildpackage.sgml">
<!ENTITY man.gbp.config SYSTEM "gbp-config.sgml">
<!ENTITY man.gbp.dch SYSTEM "gbp-dch.sgml">
<!ENTITY man.gbp.exportorig SYSTEM "gbp-export-orig.sgml">
<!ENTITY man.gbp SYSTEM "gbp.sgml">
<!ENTITY man.gbp.pristine.tar SYSTEM "gbp-pristine-tar.sgml">
<!ENTITY man.gbp.pull SYSTEM "gbp-pull.sgml">
......
......@@ -38,6 +38,7 @@
&man.gbp.config;
&man.gbp.pull;
&man.gbp.pristine.tar;
&man.gbp.exportorig;
&man.gbp.pq;
&man.gbp.create.remote.repo;
&man.gbp.conf;
......
......@@ -18,12 +18,16 @@
"""Create orig tarballs from git"""
import os
import sys
import gbp.deb as du
from gbp.command_wrappers import CommandExecFailed
from gbp.deb.git import GitRepositoryError
from gbp.config import (GbpOptionParserDebian, GbpOptionGroup)
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.deb.source import DebianSource, DebianSourceError
from gbp.errors import GbpError
import gbp.log
import gbp.notifications
from gbp.scripts.common import ExitCodes
from gbp.pkg import Compressor, Archive
......@@ -107,7 +111,7 @@ def pristine_tar_build_origs(repo, source, output_dir, options):
component=component)
return True
except GitRepositoryError:
if options.pristine_tar_commit:
if hasattr(options, 'pristine_tar_commit') and options.pristine_tar_commit:
gbp.log.debug("pristine-tar checkout failed, will commit tarball "
"due to '--pristine-tar-commit'")
else:
......@@ -219,3 +223,108 @@ def guess_comp_type(repo, comp_type, source, tarball_dir):
detected = comp
comp_type = 'gzip' if detected is None else detected
return comp_type
def build_parser(name):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name), prefix='')
except GbpError as err:
gbp.log.err(err)
return None
tag_group = GbpOptionGroup(parser,
"tag options",
"options related to git tag creation")
orig_group = GbpOptionGroup(parser,
"orig tarball options",
"options related to the creation of the orig tarball")
branch_group = GbpOptionGroup(parser,
"branch options",
"branch layout options")
for group in [tag_group, orig_group, branch_group]:
parser.add_option_group(group)
parser.add_option("--verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
parser.add_config_file_option(option_name="color-scheme",
dest="color_scheme")
tag_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag")
orig_group.add_config_file_option(option_name="upstream-tree", dest="upstream_tree")
orig_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
orig_group.add_config_file_option(option_name="force-create", dest="force_create",
help="force creation of orig tarball", action="store_true")
orig_group.add_config_file_option(option_name="tarball-dir", dest="tarball_dir", type="path",
help="location to look for external tarballs")
orig_group.add_config_file_option(option_name="compression", dest="comp_type",
help="Compression type, default is '%(compression)s'")
orig_group.add_config_file_option(option_name="compression-level", dest="comp_level",
help="Compression level, default is '%(compression-level)s'")
orig_group.add_config_file_option("component", action="append", metavar='COMPONENT',
dest="components")
branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
branch_group.add_boolean_config_file_option(option_name="submodules", dest="with_submodules")
return parser
def parse_args(argv, prefix):
parser = build_parser(argv[0])
if not parser:
return None, None
options, args = parser.parse_args(argv[1:])
gbp.log.setup(options.color, options.verbose, options.color_scheme)
return options, args
def main(argv):
retval = 0
source = None
options, args = parse_args(argv, '')
if args or not options:
return ExitCodes.parse_error
try:
repo = DebianGitRepository(os.path.curdir, toplevel=False)
except GitRepositoryError:
gbp.log.err("%s is not inside a git repository" % (os.path.abspath('.')))
return 1
try:
try:
source = DebianSource(repo.path)
source.is_native()
except Exception as e:
raise GbpError("Can't determine package type: %s" % e)
output_dir = options.tarball_dir or os.path.join(repo.path, '..')
if source.is_native():
gbp.log.info("Nothing to be done for native package")
return 0
prepare_upstream_tarballs(repo, source, options, output_dir,
output_dir)
except KeyboardInterrupt:
retval = 1
gbp.log.err("Interrupted. Aborting.")
except CommandExecFailed:
retval = 1
except (GbpError, GitRepositoryError) as err:
if str(err):
gbp.log.err(err)
retval = 1
except DebianSourceError as err:
gbp.log.err(err)
source = None
retval = 1
return retval
if __name__ == '__main__':
sys.exit(main(sys.argv))
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
......@@ -177,6 +177,7 @@ cat > files.list << EOF
%{python_sitelib}/gbp/scripts/pq.py*
%{python_sitelib}/gbp/scripts/buildpackage.py*
%{python_sitelib}/gbp/scripts/dch.py*
%{python_sitelib}/gbp/scripts/export_orig.py*
%{python_sitelib}/gbp/scripts/import_dsc.py*
%{python_sitelib}/gbp/scripts/import_dscs.py*
%{python_sitelib}/gbp/scripts/import_orig.py*
......@@ -188,6 +189,7 @@ cat >> files.list << EOF
%{_mandir}/man1/gbp-buildpackage.1*
%{_mandir}/man1/gbp-create-remote-repo.1*
%{_mandir}/man1/gbp-dch.1*
%{_mandir}/man1/gbp-export-orig.1*
%{_mandir}/man1/gbp-import-dsc.1*
%{_mandir}/man1/gbp-import-dscs.1*
%{_mandir}/man1/gbp-import-orig.1*
......
# vim: set fileencoding=utf-8 :
#
# (C) 2017 Guido Günther <agx@sigxcpu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, please see
# <http://www.gnu.org/licenses/>
import os
from tests.component import (ComponentTestBase,
ComponentTestGitRepository)
from tests.component.deb import DEB_TEST_DATA_DIR
from nose.tools import ok_, assert_false, assert_true
from gbp.scripts.import_dsc import main as import_dsc
from gbp.scripts.export_orig import main as export_orig
class TestExportOrig(ComponentTestBase):
"""Test exporting of orig tarballs"""
@staticmethod
def _dsc_name(pkg, version, dir):
return os.path.join(DEB_TEST_DATA_DIR,
dir,
'%s_%s.dsc' % (pkg, version))
def test_component_generation(self):
"""Test that generating tarball and additional tarball works without pristine-tar"""
pkg = 'hello-debhelper'
dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs')
tarballs = ["../%s_2.8.orig-foo.tar.gz" % pkg,
"../%s_2.8.orig.tar.gz" % pkg]
assert import_dsc(['arg0', '--no-pristine-tar', dsc]) == 0
repo = ComponentTestGitRepository(pkg)
os.chdir(pkg)
assert_false(repo.has_branch('pristine-tar'), "Pristine-tar branch must not exist")
for t in tarballs:
self.assertFalse(os.path.exists(t), "Tarball %s must not exist" % t)
ret = export_orig(['arg0',
'--component=foo',
'--no-pristine-tar'])
ok_(ret == 0, "Exporting tarballs failed")
for t in tarballs:
self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
def test_pristinetar_component_generation(self):
"""Test that generating tarball and additional tarball works with pristine-tar"""
pkg = 'hello-debhelper'
dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs')
tarballs = ["../%s_2.8.orig-foo.tar.gz" % pkg,
"../%s_2.8.orig.tar.gz" % pkg]
assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0
repo = ComponentTestGitRepository(pkg)
os.chdir(pkg)
assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist")
for t in tarballs:
self.assertFalse(os.path.exists(t), "Tarball %s must not exist" % t)
# Make sure the tree object for importing the main tarball is recreated
repo.collect_garbage(prune='all', aggressive=True)
ret = export_orig(['arg0',
'--component=foo',
'--pristine-tar'])
ok_(ret == 0, "Exporting tarballs failed")
for t in tarballs:
self.assertTrue(os.path.exists(t), "Tarball %s not found" % t)
def test_git_archive_tree_non_existent(self):
"""Test that we're tarball generation when commits are missing"""
pkg = 'hello-debhelper'
dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs')
assert import_dsc(['arg0', '--no-pristine-tar', dsc]) == 0
repo = ComponentTestGitRepository(pkg)
os.chdir(pkg)
assert_false(repo.has_branch('pristine-tar'), "Pristine-tar branch not must exist")
ret = export_orig(['arg0',
'--component=bar', # non-existing component
'--no-pristine-tar'])
ok_(ret == 1, "Exporting tarballs must fail")
self._check_log(-1, "gbp:error: No tree for 'bar' found in "
"'upstream/2.8' to create additional tarball from")
def test_pristine_tar_commit_non_existent(self):
"""Test that we're failing if pristine-tar commit is missing"""
pkg = 'hello-debhelper'
dsc = self._dsc_name(pkg, '2.8-1', 'dsc-3.0-additional-tarballs')
assert import_dsc(['arg0', '--pristine-tar', dsc]) == 0
repo = ComponentTestGitRepository(pkg)
os.chdir(pkg)
assert_true(repo.has_branch('pristine-tar'), "Pristine-tar branch must exist")
repo.delete_branch("pristine-tar")
repo.create_branch("pristine-tar") # create a nonsense pristine-tar branch
ret = export_orig(['arg0',
'--component=foo',
'--pristine-tar'])
ok_(ret == 1, "Exporting tarballs must fail")
self._check_log(-1, ".*git show refs/heads/pristine-tar:.*failed")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment