def test_misc_options(self):
        """Test various options of git-import-srpm"""
        srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')

        eq_(mock_import(['--no-pristine-tar',
                    '--packaging-branch=pack',
                    '--upstream-branch=orig',
                    '--packaging-dir=packaging',
                    '--packaging-tag=ver_%(upstreamversion)s-rel_%(release)s',
                    '--upstream-tag=orig/%(upstreamversion)s',
                    '--author-is-committer',
                    srpm]), 0)
        # Check repository state
        repo = GitRepository('gbp-test2')
        files = {'Makefile', 'README', 'dummy.sh', 'packaging/bar.tar.gz',
                 'packaging/foo.txt', 'packaging/gbp-test2.spec',
                 'packaging/gbp-test2-alt.spec', 'packaging/my.patch',
                 'packaging/my2.patch', 'packaging/my3.patch'}
        self._check_repo_state(repo, 'pack', ['pack', 'orig'], files)
        eq_(len(repo.get_commits()), 2)
        # Check packaging dir
        eq_(len(repo.get_commits(paths='packaging')), 1)
        # Check tags
        tags = repo.get_tags()
        eq_(set(tags), set(['orig/2.0', 'ver_2.0-rel_0']))
        # Check git committer/author
        info = repo.get_commit_info('pack')
        eq_(info['author'].name, 'Markus Lehtonen')
        eq_(info['author'].email, '*****@*****.**')
        eq_(info['author'].name, info['committer'].name)
        eq_(info['author'].email, info['committer'].email)
    def test_tagging_native(self):
        """Test tagging of native packages with import-srpm"""
        srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')

        # Invalid packaging tag keywords
        eq_(
            mock_import([
                '--no-pristine-tar', '--packaging-tag=%(foo)s', srpm,
                '--native'
            ]), 1)
        self._check_log(-1, ".*Missing value 'foo' in {.*")

        # Try with good keywords, with --skip-packaging-tag.
        # Upstream tag format should not matter
        eq_(
            mock_import([
                '--no-pristine-tar', '--vendor=foo', '--native',
                '--skip-packaging-tag',
                '--packaging-tag=%(vendor)s/%(version)s',
                '--upstream-tag=%(foo)s', srpm
            ]), 0)
        repo = GitRepository('gbp-test-native')
        eq_(len(repo.get_tags()), 0)

        # Run again, now creating packaging tag
        eq_(
            mock_import([
                '--no-pristine-tar', '--vendor=foo', '--native',
                '--packaging-tag=%(vendor)s/%(version)s',
                '--upstream-tag=%(foo)s', srpm
            ]), 0)
        eq_(repo.describe('HEAD'), 'foo/1.0-1')
 def test_multiple_versions(self):
     """Test importing of multiple versions"""
     srpms = [ os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm'),
               os.path.join(DATA_DIR, 'gbp-test-1.0-1.other.src.rpm'),
               os.path.join(DATA_DIR, 'gbp-test-1.1-1.src.rpm') ]
     eq_(mock_import(['--no-pristine-tar', srpms[0]]), 0)
     repo = GitRepository('gbp-test')
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
     eq_(len(repo.get_commits()), 2)
     # Try to import same version again
     eq_(mock_import([srpms[1]]), 0)
     eq_(len(repo.get_commits()), 2)
     eq_(len(repo.get_commits(until='upstream')), 1)
     eq_(mock_import(['--no-pristine-tar', '--allow-same-version', srpms[1]]), 0)
     # Added new version of packaging
     eq_(len(repo.get_commits()), 3)
     eq_(len(repo.get_commits(until='upstream')), 1)
     # Import new version
     eq_(mock_import(['--no-pristine-tar', srpms[2]]), 0)
     files = {'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
              'gbp-test.spec', 'my.patch', 'my2.patch', 'my3.patch'}
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     eq_(len(repo.get_commits()), 5)
     eq_(len(repo.get_commits(until='upstream')), 2)
     # Check number of tags
     eq_(len(repo.get_tags('upstream/*')), 2)
     eq_(len(repo.get_tags('packaging/*')), 3)
 def test_invalid_config_file(self):
     """Test invalid config file"""
     # Create dummy invalid config file and try to import (should fail)
     GitRepository.create('.')
     with open('.gbp.conf', 'w') as conffd:
         conffd.write('foobar\n')
     eq_(mock_import(['foo']), 1)
     self._check_log(0, 'gbp:error: File contains no section headers.')
 def test_basic_import_pristine_tar(self):
     """Test importing of non-native src.rpm, with pristine-tar"""
     srpm = os.path.join(DATA_DIR, "gbp-test-1.0-1.src.rpm")
     eq_(mock_import(["--pristine-tar", srpm]), 0)
     # Check repository state
     repo = GitRepository("gbp-test")
     self._check_repo_state(repo, "master", ["master", "upstream", "pristine-tar"])
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
 def test_import_no_orig_src(self):
     """Test importing of (native) srpm without orig tarball"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-native2-2.0-0.src.rpm')
     eq_(mock_import([srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test-native2')
     self._check_repo_state(repo, 'master', ['master'])
     # Only one commit: packaging files
     eq_(len(repo.get_commits()), 1)
 def test_import_no_orig_src(self):
     """Test importing of (native) srpm without orig tarball"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-native2-2.0-0.src.rpm')
     eq_(mock_import([srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test-native2')
     self._check_repo_state(repo, 'master', ['master'])
     # Only one commit: packaging files
     eq_(len(repo.get_commits()), 1)
 def test_invalid_config_file(self):
     """Test invalid config file"""
     # Create dummy invalid config file and run pq-rpm
     GitRepository.create('.')
     with open('.gbp.conf', 'w') as conffd:
         conffd.write('foobar\n')
     eq_(mock_pq(['foo']), 1)
     self._check_log(0, 'gbp:error: Invalid config file: File contains no '
                        'section headers.')
 def test_basic_native_import(self):
     """Test importing of native src.rpm"""
     srpm = os.path.join(DATA_DIR, "gbp-test-native-1.0-1.src.rpm")
     eq_(mock_import(["--native", srpm]), 0)
     # Check repository state
     files = {".gbp.conf", "Makefile", "README", "dummy.sh", "packaging/gbp-test-native.spec"}
     repo = GitRepository("gbp-test-native")
     self._check_repo_state(repo, "master", ["master"], files)
     # Only one commit: the imported source tarball
     eq_(len(repo.get_commits()), 1)
Beispiel #10
0
 def test_basic_import_pristine_tar(self):
     """Test importing of non-native src.rpm, with pristine-tar"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     self._check_repo_state(repo, 'master', ['master', 'upstream',
                            'pristine-tar'])
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
 def test_basic_import_pristine_tar(self):
     """Test importing of non-native src.rpm, with pristine-tar"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     self._check_repo_state(repo, 'master', ['master', 'upstream',
                            'pristine-tar'])
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
 def test_basic_native_import(self):
     """Test importing of native src.rpm"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')
     eq_(mock_import(['--native', srpm]), 0)
     # Check repository state
     files = {'.gbp.conf', 'Makefile', 'README', 'dummy.sh',
              'packaging/gbp-test-native.spec'}
     repo = GitRepository('gbp-test-native')
     self._check_repo_state(repo, 'master', ['master'], files)
     # Only one commit: the imported source tarball
     eq_(len(repo.get_commits()), 1)
 def test_basic_import(self):
     """Test importing of non-native src.rpm"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--no-pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     files =  {'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
               'gbp-test.spec', 'my.patch', 'my2.patch', 'my3.patch'}
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
 def test_basic_import(self):
     """Test importing of non-native src.rpm"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--no-pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     files =  {'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
               'gbp-test.spec', 'my.patch', 'my2.patch', 'my3.patch'}
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
 def test_basic_native_import(self):
     """Test importing of native src.rpm"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')
     eq_(mock_import(['--native', srpm]), 0)
     # Check repository state
     files = {'.gbp.conf', 'Makefile', 'README', 'dummy.sh',
              'packaging/gbp-test-native.spec'}
     repo = GitRepository('gbp-test-native')
     self._check_repo_state(repo, 'master', ['master'], files)
     # Only one commit: the imported source tarball
     eq_(len(repo.get_commits()), 1)
    def test_basic_import2(self):
        """Import package with multiple spec files and full url patch"""
        srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')
        eq_(mock_import(['--no-pristine-tar', srpm]), 0)
        # Check repository state
        repo = GitRepository('gbp-test2')
        files = {'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
                 'gbp-test2.spec', 'gbp-test2-alt.spec', 'my.patch',
                 'my2.patch', 'my3.patch'}
        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)

        # Two commits: upstream and packaging files
        eq_(len(repo.get_commits()), 2)
    def test_basic_import2(self):
        """Import package with multiple spec files and full url patch"""
        srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')
        eq_(mock_import(['--no-pristine-tar', srpm]), 0)
        # Check repository state
        repo = GitRepository('gbp-test2')
        files = {'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
                 'gbp-test2.spec', 'gbp-test2-alt.spec', 'my.patch',
                 'my2.patch', 'my3.patch'}
        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)

        # Two commits: upstream and packaging files
        eq_(len(repo.get_commits()), 2)
 def test_basic_import_orphan(self):
     """
     Test importing of non-native src.rpm to separate packaging and
     development branches
     """
     srpm = os.path.join(DATA_DIR, "gbp-test2-2.0-0.src.rpm")
     eq_(mock_import(["--no-pristine-tar", "--orphan-packaging", srpm]), 0)
     # Check repository state
     repo = GitRepository("gbp-test2")
     files = {"bar.tar.gz", "foo.txt", "gbp-test2.spec", "gbp-test2-alt.spec", "my.patch", "my2.patch", "my3.patch"}
     self._check_repo_state(repo, "master", ["master", "upstream"], files)
     # Only one commit: the packaging files
     eq_(len(repo.get_commits()), 1)
Beispiel #19
0
 def test_basic_import_orphan(self):
     """
     Test importing of non-native src.rpm to separate packaging and
     development branches
     """
     srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')
     eq_(mock_import(['--no-pristine-tar', '--orphan-packaging', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test2')
     files = {'bar.tar.gz', 'foo.txt', 'gbp-test2.spec',
              'gbp-test2-alt.spec', 'my.patch', 'my2.patch', 'my3.patch'}
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Only one commit: the packaging files
     eq_(len(repo.get_commits()), 1)
 def test_basic_import_orphan(self):
     """
     Test importing of non-native src.rpm to separate packaging and
     development branches
     """
     srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')
     eq_(mock_import(['--no-pristine-tar', '--orphan-packaging', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test2')
     files = {'bar.tar.gz', 'foo.txt', 'gbp-test2.spec',
              'gbp-test2-alt.spec', 'my.patch', 'my2.patch', 'my3.patch'}
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Only one commit: the packaging files
     eq_(len(repo.get_commits()), 1)
 def test_import_compressed_patches(self):
     """Test importing of non-native src.rpm with compressed patches"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.1-2.src.rpm')
     eq_(mock_import([srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     files = set([
         'Makefile', 'README', 'AUTHORS', 'NEWS', 'bar.tar.gz', 'dummy.sh',
         'foo.txt', 'gbp-test.spec', 'my.patch', 'mydir/myfile.txt'
     ])
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Four commits: upstream, packaging files, three patches and the removal
     # of imported patches
     eq_(len(repo.get_commits()), 6)
 def test_basic_import(self):
     """Test importing of non-native src.rpm"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--no-pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     files = set([
         'Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
         'gbp-test.spec', 'my.patch', 'mydir/myfile.txt'
     ])
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
     # Four commits: upstream, packaging files, one patch and the removal
     # of imported patches
     eq_(len(repo.get_commits()), 4)
Beispiel #23
0
    def parse_config_files(self):
        """
        Parse the possible config files and set appropriate values
        default values
        """
        parser = configparser.SafeConfigParser()
        # Fill in the built in values
        self.config = dict(self.__class__.defaults)
        # Update with the values from the defaults section. This is needed
        # in case the config file doesn't have a [<command>] section at all
        config_files = self.get_config_files()
        try:
            repo = GitRepository(".")
        except GitRepositoryError:
            repo = None
        # Read all config files
        for filename in config_files:
            self._read_config_file(parser, repo, filename)
        self.config.update(dict(parser.defaults()))

        # Make sure we read any legacy sections prior to the real subcommands
        # section i.e. read [gbp-pull] prior to [pull]
        if (self.command.startswith('gbp-')
                or self.command.startswith('git-')):
            cmd = self.command[4:]
            oldcmd = self.command
            if parser.has_section(oldcmd):
                self.config.update(dict(parser.items(oldcmd, raw=True)))
                gbp.log.warn("Old style config section [%s] found "
                             "please rename to [%s]" % (oldcmd, cmd))
        else:
            cmd = self.command
            for prefix in ['gbp', 'git']:
                oldcmd = '%s-%s' % (prefix, self.command)
                if parser.has_section(oldcmd):
                    self.config.update(dict(parser.items(oldcmd, raw=True)))
                    gbp.log.warn("Old style config section [%s] found "
                                 "please rename to [%s]" % (oldcmd, cmd))

        # Update with command specific settings
        if parser.has_section(cmd):
            # Don't use items() until we got rid of the compat sections
            # since this pulls in the defaults again
            self.config.update(dict(parser._sections[cmd].items()))

        for section in self.sections:
            if parser.has_section(section):
                self.config.update(dict(parser._sections[section].items()))
            else:
                raise configparser.NoSectionError(
                    "Mandatory section [%s] does not exist." % section)

        # filter can be either a list or a string, always build a list:
        if self.config['filter']:
            if self.config['filter'].startswith('['):
                self.config['filter'] = eval(self.config['filter'])
            else:
                self.config['filter'] = [self.config['filter']]
        else:
            self.config['filter'] = []
    def test_invalid_args(self):
        """See that pq-rpm fails gracefully when called with invalid args"""
        GitRepository.create('.')
        # Test empty args
        eq_(mock_pq([]), 1)
        self._check_log(0, 'gbp:error: No action given.')
        self._clear_log()

        # Test invalid command
        eq_(mock_pq(['mycommand']), 1)
        self._check_log(0, "gbp:error: Unknown action 'mycommand'")
        self._clear_log()

        # Test invalid cmdline options
        with assert_raises(SystemExit):
            mock_pq(['--invalid-arg=123'])
    def test_import_to_existing(self):
        """Test importing to an existing repo"""
        srpm = os.path.join(DATA_DIR, "gbp-test-1.0-1.src.rpm")

        # Create new repo
        repo = GitRepository.create("myrepo")
        os.chdir("myrepo")
        shutil.copy2(".git/HEAD", "foobar")
        repo.add_files(".")
        repo.commit_all("First commit")

        # Test importing to non-clean repo
        shutil.copy2(".git/HEAD", "foobaz")
        eq_(mock_import(["--create-missing", srpm]), 1)
        self._check_log(0, "gbp:error: Repository has uncommitted changes")
        self._clear_log()
        os.unlink("foobaz")

        # The first import should fail because upstream branch is missing
        eq_(mock_import([srpm]), 1)
        self._check_log(-1, "Also check the --create-missing-branches")
        eq_(mock_import(["--no-pristine-tar", "--create-missing", srpm]), 0)
        self._check_repo_state(repo, "master", ["master", "upstream"])
        # Four commits: our initial, upstream and packaging files
        eq_(len(repo.get_commits()), 3)

        # The import should fail because missing packaging-branch
        srpm = os.path.join(DATA_DIR, "gbp-test-1.1-1.src.rpm")
        eq_(mock_import(["--packaging-branch=foo", srpm]), 1)
        self._check_log(-1, "Also check the --create-missing-branches")
 def setup_class(cls):
     """Initializations only made once per test run"""
     super(RpmRepoTestBase, cls).setup_class()
     cls.manifest = RepoManifest(
         os.path.join(RPM_TEST_DATA_DIR, 'test-repo-manifest.xml'))
     cls.orig_repos = {}
     for prj, brs in cls.manifest.projects_iter():
         repo = GitRepository.create(
             os.path.join(cls._tmproot, '%s.repo' % prj))
         try:
             repo.add_remote_repo('origin', RPM_TEST_DATA_DIR, fetch=True)
         except GitRepositoryError:
             # Workaround for older git working on submodules initialized
             # with newer git
             gitfile = os.path.join(RPM_TEST_DATA_DIR, '.git')
             if os.path.isfile(gitfile):
                 with open(gitfile) as fobj:
                     link = fobj.readline().replace('gitdir:', '').strip()
                 link_dir = os.path.join(RPM_TEST_DATA_DIR, link)
                 repo.remove_remote_repo('origin')
                 repo.add_remote_repo('origin', link_dir, fetch=True)
             else:
                 raise
         # Fetch all remote refs of the orig repo, too
         repo.fetch('origin',
                    tags=True,
                    refspec='refs/remotes/*:refs/upstream/*')
         for branch, rev in six.iteritems(brs):
             repo.create_branch(branch, rev)
         repo.force_head('master', hard=True)
         cls.orig_repos[prj] = repo
 def setup_class(cls):
     """Initializations only made once per test run"""
     super(RpmRepoTestBase, cls).setup_class()
     cls.manifest = RepoManifest(os.path.join(RPM_TEST_DATA_DIR,
                                              'test-repo-manifest.xml'))
     cls.orig_repos = {}
     for prj, brs in cls.manifest.projects_iter():
         repo = GitRepository.create(os.path.join(cls._tmproot,
                                     '%s.repo' % prj))
         try:
             repo.add_remote_repo('origin', RPM_TEST_DATA_DIR, fetch=True)
         except GitRepositoryError:
             # Workaround for older git working on submodules initialized
             # with newer git
             gitfile = os.path.join(RPM_TEST_DATA_DIR, '.git')
             if os.path.isfile(gitfile):
                 with open(gitfile) as fobj:
                     link = fobj.readline().replace('gitdir:', '').strip()
                 link_dir = os.path.join(RPM_TEST_DATA_DIR, link)
                 repo.remove_remote_repo('origin')
                 repo.add_remote_repo('origin', link_dir, fetch=True)
             else:
                 raise
         # Fetch all remote refs of the orig repo, too
         repo.fetch('origin', tags=True,
                    refspec='refs/remotes/*:refs/upstream/*')
         for branch, rev in brs.iteritems():
             repo.create_branch(branch, rev)
         repo.force_head('master', hard=True)
         cls.orig_repos[prj] = repo
    def test_import_to_existing(self):
        """Test importing to an existing repo"""
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')

        # Create new repo
        repo = GitRepository.create('myrepo')
        os.chdir('myrepo')
        shutil.copy2('.git/HEAD', 'foobar')
        repo.add_files('.')
        repo.commit_all('First commit')

        # Test importing to non-clean repo
        shutil.copy2('.git/HEAD', 'foobaz')
        eq_(mock_import(['--create-missing', srpm]), 1)
        self._check_log(0, 'gbp:error: Repository has uncommitted changes')
        self._clear_log()
        os.unlink('foobaz')

        # The first import should fail because upstream branch is missing
        eq_(mock_import([srpm]), 1)
        self._check_log(-1, 'Also check the --create-missing-branches')
        eq_(mock_import(['--no-pristine-tar', '--create-missing', srpm]), 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream'])
        # Four commits: our initial, upstream, packaging files, one patch,
        # and the removal of imported patches
        eq_(len(repo.get_commits()), 5)

        # The import should fail because missing packaging-branch
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.1-1.src.rpm')
        eq_(mock_import(['--packaging-branch=foo', srpm]), 1)
        self._check_log(-1, 'Also check the --create-missing-branches')
    def test_noninteractive(self):
        """Test non-interactive mode"""
        repo = GitRepository.create('testrepo')
        orig = os.path.join(DATA_DIR, 'gbp-test-native-1.0.zip')
        orig_renamed = os.path.join(os.path.abspath('.'), 'foo.zip')
        shutil.copy(orig, orig_renamed)
        os.chdir('testrepo')

        # Guessing name and version should fail
        eq_(mock_import(['--no-interactive', orig_renamed]), 1)
        self._check_log(-1, "gbp:error: Couldn't determine upstream package")

        # Guessing from the original archive should succeed
        eq_(mock_import(['--no-interactive', '--merge', orig], stdin_data=''),
            0)
        files = [
            '.gbp.conf', 'Makefile', 'README', 'dummy.sh',
            'packaging/gbp-test-native.spec'
        ]
        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
        eq_(len(repo.get_commits(until='master')), 1)

        # Import "new" version, this time package name should be taken from spec
        eq_(mock_import(['--no-interactive', orig_renamed], stdin_data=''), 1)
        self._check_log(-1, "gbp:error: Couldn't determine upstream version")
Beispiel #30
0
def main(argv):
    retval = 0

    (options, args) = parse_args(argv)
    if not options:
        return 1

    if len(args) < 2:
        gbp.log.err("Need a repository to clone.")
        return 1
    else:
        source = args[1]

    clone_to, auto_name = (os.path.curdir, True) if len(args) < 3 else (args[2], False)
    try:
        GitRepository(clone_to)
        gbp.log.err("Can't run inside a git repository.")
        return 1
    except GitRepositoryError:
        pass

    try:
        repo = DebianGitRepository.clone(clone_to, source, options.depth,
                                         auto_name=auto_name)
        os.chdir(repo.path)

        # Reparse the config files of the cloned repository so we pick up the
        # branch information from there:
        (options, args) = parse_args(argv)

        # Track all branches:
        if options.all:
            remotes = repo.get_remote_branches()
            for remote in remotes:
                local = remote.replace("origin/", "", 1)
                if not repo.has_branch(local) and \
                    local != "HEAD":
                        repo.create_branch(local, remote)
        else: # only track gbp's default branches
            branches = [ options.debian_branch, options.upstream_branch ]
            if options.pristine_tar:
                branches += [ repo.pristine_tar_branch ]
            gbp.log.debug('Will track branches: %s' % branches)
            for branch in branches:
                remote = 'origin/%s' % branch
                if repo.has_branch(remote, remote=True) and \
                    not repo.has_branch(branch):
                        repo.create_branch(branch, remote)

        repo.set_branch(options.debian_branch)

    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError as err:
        if len(err.__str__()):
            gbp.log.err(err)
        retval = 1

    return retval
 def _init_repo_with_dummy_packaging():
     """Create a dummy packaging branch with one commit"""
     repo = GitRepository.create('.')
     shutil.copy2('.git/HEAD', 'foobar')
     repo.add_files('.')
     repo.commit_all('First commit')
     return repo
 def test_pristine_import_to_bare(self):
     """Test importing inside bare git repository"""
     repo = GitRepository.create('.', bare=True)
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     eq_(mock_import([orig]), 0)
     # No pristine-tar branch should be present
     self._check_repo_state(repo, None, ['upstream'])
    def test_import_to_existing(self):
        """Test importing to an existing repo"""
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')

        # Create new repo
        repo = GitRepository.create('myrepo')
        os.chdir('myrepo')
        shutil.copy2('.git/HEAD', 'foobar')
        repo.add_files('.')
        repo.commit_all('First commit')

        # Test importing to non-clean repo
        shutil.copy2('.git/HEAD', 'foobaz')
        eq_(mock_import(['--create-missing', srpm]), 1)
        self._check_log(0, 'gbp:error: Repository has uncommitted changes')
        self._clear_log()
        os.unlink('foobaz')

        # The first import should fail because upstream branch is missing
        eq_(mock_import([srpm]), 1)
        self._check_log(-1, 'Also check the --create-missing-branches')
        eq_(mock_import(['--no-pristine-tar', '--create-missing', srpm]), 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream'])
        # Four commits: our initial, upstream and packaging files
        eq_(len(repo.get_commits()), 3)

        # The import should fail because missing packaging-branch
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.1-1.src.rpm')
        eq_(mock_import(['--packaging-branch=foo', srpm]), 1)
        self._check_log(-1, 'Also check the --create-missing-branches')
    def test_invalid_args(self):
        """
        See that import-orig-rpm fails gracefully when called with invalid args
        """
        repo = GitRepository.create('.')
        origs = [
            os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2'),
            os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')
        ]
        # Test multiple archives
        eq_(mock_import([] + origs), 1)
        self._check_log(0, 'gbp:error: More than one archive specified')
        self._clear_log()

        # Test invalid archive
        false_orig = os.path.join(RPM_TEST_DATA_DIR, 'gbp-test-1.0-1.src.rpm')
        eq_(mock_import([false_orig], 'foo\n1\n'), 1)
        self._check_log(0, "gbp:error: Unsupported archive format")
        self._clear_log()

        # Test non-existing archive
        eq_(mock_import(['none.tar.bz2'], 'foo\n1\n'), 1)
        self._check_log(0, "gbp:error: UpstreamSource: unable to find")
        self._clear_log()

        # Check that nothing is in the repo
        self._check_repo_state(repo, None, [])

        # Test invalid cmdline options
        assert_raises(SystemExit, mock_import, ['--invalid-arg=123'])
        """
    def test_misc_options(self):
        """Test various options of git-import-srpm"""
        srpm = os.path.join(DATA_DIR, 'gbp-test2-2.0-0.src.rpm')

        eq_(mock_import(['--no-pristine-tar',
                         '--packaging-branch=pack',
                         '--upstream-branch=orig',
                         '--packaging-dir=packaging',
                         '--packaging-tag=ver_%(upstreamversion)s-rel_%(release)s',
                         '--upstream-tag=orig/%(upstreamversion)s',
                         '--author-is-committer',
                         srpm]), 0)
        # Check repository state
        repo = GitRepository('gbp-test2')
        files = {'Makefile', 'README', 'dummy.sh', 'packaging/bar.tar.gz',
                 'packaging/foo.txt', 'packaging/gbp-test2.spec',
                 'packaging/gbp-test2-alt.spec', 'packaging/my.patch',
                 'packaging/my2.patch', 'packaging/my3.patch'}
        self._check_repo_state(repo, 'pack', ['pack', 'orig'], files)
        eq_(len(repo.get_commits()), 2)
        # Check packaging dir
        eq_(len(repo.get_commits(paths='packaging')), 1)
        # Check tags
        tags = repo.get_tags()
        eq_(set(tags), set(['orig/2.0', 'ver_2.0-rel_0']))
        # Check git committer/author
        info = repo.get_commit_info('pack')
        eq_(info['author'].name, 'Markus Lehtonen')
        eq_(info['author'].email, '*****@*****.**')
        eq_(info['author'].name, info['committer'].name)
        eq_(info['author'].email, info['committer'].email)

        # Create a new commit by committing an empty tree
        commit = repo.commit_tree('4b825dc642cb6eb9a060e54bf8d69288fbee4904',
                                  msg="Empty commit", parents=[])
        repo.create_tag('foo/1.0', msg="New tag", commit=commit)
        # Just blindly import another package on top of this to test more options
        os.chdir('gbp-test2')
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
        eq_(mock_import(['--upstream-vcs-tag=foo/%(version)s',
                         '--upstream-branch=orig',
                         '--packaging-branch=pack',
                         srpm]), 0)
        parents = repo.get_commits(until='orig', num=1, options='--format=%P')[0].split()
        eq_(len(parents), 2)
        ok_(commit in parents)
        ok_(repo.rev_parse('orig/2.0^{}') in parents)
    def test_misc_options(self):
        """Test various options of git-import-srpm"""
        srpm = os.path.join(DATA_DIR, "gbp-test2-2.0-0.src.rpm")

        eq_(
            mock_import(
                [
                    "--no-pristine-tar",
                    "--packaging-branch=pack",
                    "--upstream-branch=orig",
                    "--packaging-dir=packaging",
                    "--packaging-tag=ver_%(upstreamversion)s-rel_%(release)s",
                    "--upstream-tag=orig/%(upstreamversion)s",
                    "--author-is-committer",
                    srpm,
                ]
            ),
            0,
        )
        # Check repository state
        repo = GitRepository("gbp-test2")
        files = {
            "Makefile",
            "README",
            "dummy.sh",
            "packaging/bar.tar.gz",
            "packaging/foo.txt",
            "packaging/gbp-test2.spec",
            "packaging/gbp-test2-alt.spec",
            "packaging/my.patch",
            "packaging/my2.patch",
            "packaging/my3.patch",
        }
        self._check_repo_state(repo, "pack", ["pack", "orig"], files)
        eq_(len(repo.get_commits()), 2)
        # Check packaging dir
        eq_(len(repo.get_commits(paths="packaging")), 1)
        # Check tags
        tags = repo.get_tags()
        eq_(set(tags), set(["orig/2.0", "ver_2.0-rel_0"]))
        # Check git committer/author
        info = repo.get_commit_info("pack")
        eq_(info["author"].name, "Markus Lehtonen")
        eq_(info["author"].email, "*****@*****.**")
        eq_(info["author"].name, info["committer"].name)
        eq_(info["author"].email, info["committer"].email)
Beispiel #37
0
 def test_target_dir(self):
     """Test importing to target dir"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--no-pristine-tar', srpm, 'targetdir']), 0)
     # Check repository state
     assert os.path.exists('targetdir')
     repo = GitRepository('targetdir')
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
 def test_import_zip(self):
     """Test importing of zip archive"""
     repo = GitRepository.create('.')
     # Import zip with, no master branch should be present
     orig = os.path.join(DATA_DIR, 'gbp-test-native-1.0.zip')
     eq_(mock_import([orig]), 0)
     self._check_repo_state(repo, None, ['upstream'], [])
     eq_(repo.get_tags(), ['upstream/1.0'])
    def test_tagging(self):
        """Test tag options of import-srpm"""
        srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')

        # Invalid packaging tag keywords
        eq_(mock_import(['--no-pristine-tar', '--packaging-tag=%(foo)s', srpm]),
            1)
        self._check_log(-1, ".*Missing value 'foo' in *.*")
        # Remove upstream tag
        repo = GitRepository('gbp-test')
        repo.delete_tag('upstream/1.0')

        # Invalid upstream tag keywords
        eq_(mock_import(['--no-pristine-tar', '--upstream-tag=%(foo)s', srpm]),
            1)
        self._check_log(-1, ".*Missing value 'foo' in.*")

        # Try with good keywords, with --skip-packaging-tag
        eq_(mock_import(['--no-pristine-tar', '--vendor=foo',
                         '--skip-packaging-tag',
                         '--packaging-tag=%(vendor)s/%(version)s',
                         '--upstream-tag=upst/%(version)s', srpm]), 0)
        eq_(repo.describe('upstream'), 'upst/1.0')
        eq_(len(repo.get_tags()), 1)

        # Re-import, creating packaging tag
        eq_(mock_import(['--no-pristine-tar', '--vendor=foo',
                         '--packaging-tag=%(vendor)s/%(version)s',
                         '--upstream-tag=upst/%(version)s', srpm]), 0)
        eq_(repo.describe('HEAD'), 'foo/1.0-1')
        eq_(len(repo.get_tags()), 2)
Beispiel #40
0
 def test_filter(self):
     """Test filter option"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     eq_(mock_import(['--no-pristine-tar', '--filter=README', '--filter=mydir', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test')
     files = set(['Makefile', 'dummy.sh', 'bar.tar.gz', 'foo.txt',
                  'gbp-test.spec', 'my.patch', 'my2.patch', 'my3.patch'])
     self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
 def test_hook_error(self):
     """Test postimport hook failure"""
     repo = GitRepository.create('.')
     orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     eq_(mock_import(['--postimport=_notexist.sh', '--merge', orig]), 1)
     self._check_log(-2, "gbp:error: '_notexist.sh' failed:")
     self._check_log(-1, 'gbp:error: Import of %s failed' % orig)
     # Other parts of the import should've succeeded
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
 def test_unsupported_archive(self):
     """Test importing of src.rpm with a zip source archive"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')
     eq_(mock_import(['--pristine-tar', srpm]), 0)
     # Check repository state
     repo = GitRepository('gbp-test-native')
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
     # Check that a warning is printed
     self._check_log(-1, "gbp:warning: Ignoring pristine-tar")
 def test_basic_import_to_bare_repo(self):
     """Test importing of srpm to a bare git repository"""
     srpm = os.path.join(DATA_DIR, "gbp-test-1.0-1.src.rpm")
     # Create new repo
     repo = GitRepository.create("myrepo", bare=True)
     os.chdir("myrepo")
     eq_(mock_import([srpm]), 0)
     self._check_repo_state(repo, "master", ["master", "upstream"])
     # Patch import to bare repos not supported -> only 2 commits
     eq_(len(repo.get_commits(until="master")), 2)
 def test_basic_import_to_bare_repo(self):
     """Test importing of srpm to a bare git repository"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     # Create new repo
     repo = GitRepository.create('myrepo', bare=True)
     os.chdir('myrepo')
     eq_(mock_import([srpm]), 0)
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
     # Patch import to bare repos not supported -> only 2 commits
     eq_(len(repo.get_commits(until='master')), 2)
 def test_basic_import_to_bare_repo(self):
     """Test importing of srpm to a bare git repository"""
     srpm = os.path.join(DATA_DIR, 'gbp-test-1.0-1.src.rpm')
     # Create new repo
     repo = GitRepository.create('myrepo', bare=True)
     os.chdir('myrepo')
     eq_(mock_import([srpm]), 0)
     self._check_repo_state(repo, 'master', ['master', 'upstream'])
     # Patch import to bare repos not supported -> only 2 commits
     eq_(len(repo.get_commits(until='master')), 2)
 def test_invalid_config_file(self):
     """Test invalid config file"""
     # Create and commit dummy invalid config file
     repo = GitRepository.create(".")
     with open(".gbp.conf", "w") as conffd:
         conffd.write("foobar\n")
     repo.add_files(".gbp.conf")
     repo.commit_all("Add conf")
     eq_(mock_gbp([]), 1)
     self._check_log(0, "gbp:error: File contains no section headers.")
Beispiel #47
0
 def test_invalid_config_file(self):
     """Test invalid config file"""
     # Create and commit dummy invalid config file
     repo = GitRepository.create('.')
     with open('.gbp.conf', 'w') as conffd:
         conffd.write('foobar\n')
     repo.add_files('.gbp.conf')
     repo.commit_all('Add conf')
     eq_(mock_gbp([]), 1)
     self._check_log(0, 'gbp:error: File contains no section headers.')
 def test_basic_import(self):
     """Test importing of non-native src.rpm"""
     srpm = os.path.join(DATA_DIR, "gbp-test-1.0-1.src.rpm")
     eq_(mock_import(["--no-pristine-tar", srpm]), 0)
     # Check repository state
     repo = GitRepository("gbp-test")
     files = {
         "Makefile",
         "README",
         "bar.tar.gz",
         "dummy.sh",
         "foo.txt",
         "gbp-test.spec",
         "my.patch",
         "my2.patch",
         "my3.patch",
     }
     self._check_repo_state(repo, "master", ["master", "upstream"], files)
     # Two commits: upstream and packaging files
     eq_(len(repo.get_commits()), 2)
Beispiel #49
0
 def import_debian_tarball(cls, debian=DEFAULT_OVERLAY, opts=None):
     """Import a 3.0 (quilt) debian dir for overlay mode"""
     repo = GitRepository.create(os.path.split('/')[-1].split('_')[0])
     UnpackTarArchive(debian, repo.path)()
     repo.add_files('.')
     repo.commit_files('.', msg="debian dir")
     expected_branches = ['master']
     ComponentTestBase._check_repo_state(repo, 'master', expected_branches)
     eq_(len(repo.get_commits()), 1)
     os.chdir(repo.path)
     return repo
Beispiel #50
0
    def test_import_dir(self):
        """Test importing of directories"""
        eq_(mock_import(['--no-pristine-tar', 'gbp-test-1.0-1-unpack']), 0)
        # Check repository state
        repo = GitRepository('gbp-test')
        self._check_repo_state(repo, 'master', ['master', 'upstream'])

        # Check that importing dir with multiple spec files fails
        eq_(mock_import(['multi-unpack']), 1)
        self._check_log(-1, 'gbp:error: Failed determine spec file: '
                        'Multiple spec files found')
Beispiel #51
0
 def import_debian_tarball(cls, debian=DEFAULT_OVERLAY, opts=None):
     """Import a 3.0 (quilt) debian dir for overlay mode"""
     repo = GitRepository.create(os.path.split('/')[-1].split('_')[0])
     UnpackTarArchive(debian, repo.path)()
     repo.add_files('.')
     repo.commit_files('.', msg="debian dir")
     expected_branches = ['master']
     ComponentTestBase._check_repo_state(repo, 'master', expected_branches)
     eq_(len(repo.get_commits()), 1)
     os.chdir(repo.path)
     return repo
 def test_branch_update(self):
     """Check that the working copy is kept in sync with branch HEAD"""
     repo = GitRepository.create('.')
     orig1 = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
     orig2 = os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')
     eq_(mock_import(['--merge', orig1]), 0)
     repo.set_branch('upstream')
     eq_(mock_import([orig2]), 0)
     files = ['Makefile', 'README', 'dummy.sh']
     self._check_repo_state(repo, 'upstream', ['master', 'upstream'], files)
     eq_(len(repo.get_commits(until='upstream')), 2)
    def test_basic_import2(self):
        """Import package with multiple spec files and full url patch"""
        srpm = os.path.join(DATA_DIR, "gbp-test2-2.0-0.src.rpm")
        eq_(mock_import(["--no-pristine-tar", srpm]), 0)
        # Check repository state
        repo = GitRepository("gbp-test2")
        files = {
            "Makefile",
            "README",
            "bar.tar.gz",
            "dummy.sh",
            "foo.txt",
            "gbp-test2.spec",
            "gbp-test2-alt.spec",
            "my.patch",
            "my2.patch",
            "my3.patch",
        }
        self._check_repo_state(repo, "master", ["master", "upstream"], files)

        # Two commits: upstream and packaging files
        eq_(len(repo.get_commits()), 2)
 def test_multiple_versions(self):
     """Test importing of multiple versions"""
     srpms = [
         os.path.join(DATA_DIR, "gbp-test-1.0-1.src.rpm"),
         os.path.join(DATA_DIR, "gbp-test-1.0-1.other.src.rpm"),
         os.path.join(DATA_DIR, "gbp-test-1.1-1.src.rpm"),
     ]
     eq_(mock_import(["--no-pristine-tar", srpms[0]]), 0)
     repo = GitRepository("gbp-test")
     self._check_repo_state(repo, "master", ["master", "upstream"])
     eq_(len(repo.get_commits()), 2)
     # Try to import same version again
     eq_(mock_import([srpms[1]]), 0)
     eq_(len(repo.get_commits()), 2)
     eq_(len(repo.get_commits(until="upstream")), 1)
     eq_(mock_import(["--no-pristine-tar", "--allow-same-version", srpms[1]]), 0)
     # Added new version of packaging
     eq_(len(repo.get_commits()), 3)
     eq_(len(repo.get_commits(until="upstream")), 1)
     # Import new version
     eq_(mock_import(["--no-pristine-tar", srpms[2]]), 0)
     files = {
         "Makefile",
         "README",
         "bar.tar.gz",
         "dummy.sh",
         "foo.txt",
         "gbp-test.spec",
         "my.patch",
         "my2.patch",
         "my3.patch",
     }
     self._check_repo_state(repo, "master", ["master", "upstream"], files)
     eq_(len(repo.get_commits()), 5)
     eq_(len(repo.get_commits(until="upstream")), 2)
     # Check number of tags
     eq_(len(repo.get_tags("upstream/*")), 2)
     eq_(len(repo.get_tags("packaging/*")), 3)
    def test_tagging_native(self):
        """Test tagging of native packages with import-srpm"""
        srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')

        # Invalid packaging tag keywords
        eq_(mock_import(['--no-pristine-tar', '--packaging-tag=%(foo)s',
                         srpm, '--native']), 1)
        self._check_log(-1, ".*Missing value 'foo' in {.*")

        # Try with good keywords, with --skip-packaging-tag.
        # Upstream tag format should not matter
        eq_(mock_import(['--no-pristine-tar', '--vendor=foo', '--native',
                         '--skip-packaging-tag',
                         '--packaging-tag=%(vendor)s/%(version)s',
                         '--upstream-tag=%(foo)s', srpm]), 0)
        repo = GitRepository('gbp-test-native')
        eq_(len(repo.get_tags()), 0)

        # Run again, now creating packaging tag
        eq_(mock_import(['--no-pristine-tar', '--vendor=foo', '--native',
                         '--packaging-tag=%(vendor)s/%(version)s',
                         '--upstream-tag=%(foo)s', srpm]), 0)
        eq_(repo.describe('HEAD'), 'foo/1.0-1')
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    dscs = []
    ret = 0
    verbose = False
    dsc_key = cmp_to_key(DscCompareVersions())
    use_debsnap = False

    try:
        import_args = argv[1:]

        if '--verbose' in import_args:
            verbose = True
        gbp.log.setup(False, verbose)

        if '--ignore-repo-config' in import_args:
            set_gbp_conf_files()
            import_args.remove('--ignore-repo-config')
        # Not using Configparser since we want to pass all unknown options
        # unaltered to gbp import-dsc
        if '--debsnap' in import_args:
            use_debsnap = True
            import_args.remove('--debsnap')
            if import_args == []:
                print_help()
                raise GbpError
            pkg = import_args[-1]
            import_args = import_args[:-1]
        else:
            for arg in argv[::-1]:
                if arg.endswith('.dsc'):
                    dscs.append(DscFile.parse(arg))
                    import_args.remove(arg)

        if not use_debsnap and not dscs:
            print_help()
            raise GbpError

        if use_debsnap:
            dirs['tmp'] = os.path.abspath(tempfile.mkdtemp())
            dscs = [DscFile.parse(f) for f in fetch_snapshots(pkg, dirs['tmp'])]

        dscs.sort(key=dsc_key)
        importer = GitImportDsc(import_args)

        try:
            repo = GitRepository('.')
            (clean, out) = repo.is_clean()
            if not clean:
                gbp.log.err("Repository has uncommitted changes, "
                            "commit these first: ")
                raise GbpError(out)
            else:
                dirs['pkg'] = dirs['top']
        except GitRepositoryError:
            # no git repository there yet
            dirs['pkg'] = os.path.join(dirs['top'], dscs[0].pkg)

        if importer.importdsc(dscs[0]):
            raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
        os.chdir(dirs['pkg'])

        for dsc in dscs[1:]:
            if importer.importdsc(dsc):
                raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except (GbpError, gbpc.CommandExecFailed, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    finally:
        if 'tmp' in dirs:
            gbpc.RemoveTree(dirs['tmp'])()
        os.chdir(dirs['top'])

    if not ret:
        gbp.log.info('Everything imported under %s' % dirs['pkg'])
    return ret
Beispiel #57
0
def main(argv):
    retval = 0

    (options, args) = parse_args(argv)
    if not options:
        return 1

    gbp.log.setup(options.color, options.verbose, options.color_scheme)

    if len(args) < 2:
        gbp.log.err("No action given.")
        return 1
    else:
        action = args[1]

    if args[1] in ["export", "import", "rebase", "drop", "switch"]:
        pass
    elif args[1] in ["apply"]:
        if len(args) != 3:
            gbp.log.err("No patch name given.")
            return 1
        else:
            patchfile = args[2]
    else:
        gbp.log.err("Unknown action '%s'." % args[1])
        return 1

    try:
        repo = GitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        current = repo.get_branch()
        if action == "export":
            export_patches(repo, current, options)
        elif action == "import":
            series = SERIES_FILE
            tries = options.time_machine if (options.time_machine > 0) else 1
            import_quilt_patches(repo, current, series, tries, options.force)
            current = repo.get_branch()
            gbp.log.info("Patches listed in '%s' imported on '%s'" %
                          (series, current))
        elif action == "drop":
            drop_pq(repo, current)
        elif action == "rebase":
            rebase_pq(repo, current)
        elif action == "apply":
            patch = Patch(patchfile)
            maintainer = get_maintainer_from_control(repo)
            apply_single_patch(repo, current, patch, maintainer, options.topic)
        elif action == "switch":
            switch_pq(repo, current)
    except CommandExecFailed:
        retval = 1
    except (GbpError, GitRepositoryError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        retval = 1

    return retval