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_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 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 _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_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, 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")
    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_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_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 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_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_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_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)
Beispiel #16
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_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 #20
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)
Beispiel #22
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_import_hooks(self):
        """Basic test for postimport hook"""
        repo = GitRepository.create('.')
        orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')

        script = ("echo -n branch: $GBP_BRANCH, version: %(upstreamversion)s"
                  " > hook.txt")
        eq_(mock_import(['--postimport', script, '--merge', orig]), 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream'])
        eq_(repo.get_tags(), ['upstream/1.0'])
        with open('hook.txt', 'r') as hookout:
            data = hookout.read()
        eq_(data, 'branch: master, version: 1.0')
    def test_basic_import_to_bare_repo(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)
        self._check_repo_state(repo, None, ['upstream'])
        eq_(len(repo.get_commits(until='upstream')), 1)
        eq_(repo.get_tags(), ['upstream/1.0'])

        # Import another version
        repo.set_branch('upstream')
        orig = os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')
        eq_(mock_import([orig]), 0)
        self._check_repo_state(repo, 'upstream', ['upstream'])
        eq_(len(repo.get_commits(until='upstream')), 2)
    def test_import_dir(self):
        """Test importing of unpacked sources"""
        # Unpack sources and create repo
        orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
        subprocess.Popen(['tar', 'xf', orig])
        repo = GitRepository.create('myrepo')
        os.chdir('myrepo')

        # Import dir first, fool the version to be 0.9
        eq_(mock_import(['../gbp-test'], 'gbp-test\n0.9\n'), 0)
        files = ['Makefile', 'README', 'dummy.sh']
        self.check_tree(repo, 'upstream', files)
        self._check_repo_state(repo, None, ['upstream'], [])

        # Import from unpacked and check that the contents is the same
        eq_(mock_import([orig]), 0)
        eq_(len(repo.diff('upstream/0.9', 'upstream/1.0')), 0)
    def test_basic_filtering(self):
        """Basic test for import filter"""
        repo = GitRepository.create('.')
        orig = os.path.join(DATA_DIR, 'gbp-test-1.1.with_dotgit.tar.bz2')
        # Try importing a tarball with git metadata
        eq_(mock_import([orig], 'gbp-test\n1.0\n'), 1)
        self._check_log(0, 'gbp:error: The orig tarball contains .git')

        # Try filtering out .git directory and shell scripts
        eq_(
            mock_import(['--filter=.git', '--filter=*.sh', '--merge', orig],
                        'gbp-test\n1.0\n'), 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream'])
        eq_(len(repo.get_commits(until='master')), 1)
        eq_(len(repo.get_commits(until='upstream')), 1)
        eq_(repo.get_tags(), ['upstream/1.0'])
        added_files = repo.get_commit_info('upstream')['files']['A']
        eq_(set(added_files), set(['Makefile', 'README']))
    def test_misc_options(self):
        """Test various options of git-import-orig-rpm"""
        repo = GitRepository.create('.')
        # Import one orig with default options to get 'upstream' branch
        orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
        eq_(mock_import(['-u0.8', orig]), 0)

        # Import the "native" zip to get packaging files
        orig = os.path.join(DATA_DIR, 'gbp-test-native-1.0.zip')
        base_args = [
            '--packaging-branch=pack', '--upstream-branch=orig',
            '--upstream-tag=orig/%(upstreamversion)s', '--merge'
        ]
        # Fake version to be 0.9
        extra_args = ['-u0.9', '--upstream-vcs-tag=upstream/0.8', orig]
        eq_(mock_import(base_args + extra_args), 0)
        # Check repository state
        files = []
        self._check_repo_state(repo, None, ['pack', 'orig', 'upstream'], files)
        eq_(len(repo.get_commits(until='pack')), 2)
        # Check tags
        tags = repo.get_tags()
        eq_(set(tags), set(['upstream/0.8', 'orig/0.9']))

        # Change to packaging branch and create new commit
        repo.set_branch('pack')
        shutil.copy2('.git/HEAD', 'my_new_file')
        repo.add_files('.')
        repo.commit_all('My new commit')
        # Import a new version, name should be taken from spec
        orig = os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')
        extra_args = [
            '--packaging-dir=packaging', '--no-interactive', '-u1.1', orig
        ]
        eq_(mock_import(base_args + extra_args, ''), 0)
        # Threeupstream versions, "my new" commit and one merge commit
        eq_(len(repo.get_commits(until='pack')), 5)
        tags = repo.get_tags()
        eq_(set(tags), set(['upstream/0.8', 'orig/0.9', 'orig/1.1']))
    def test_import_tars(self):
        """Test importing of tarballs, with and without merging"""
        repo = GitRepository.create('.')
        # Import first version, with --merge
        orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')
        eq_(mock_import(['--merge', orig]), 0)
        files = ['Makefile', 'README', 'dummy.sh']
        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
        eq_(len(repo.get_commits(until='master')), 1)
        eq_(len(repo.get_commits(until='upstream')), 1)
        eq_(repo.get_tags(), ['upstream/1.0'])

        # Import second version, don't merge to master branch
        orig = os.path.join(DATA_DIR, 'gbp-test-1.1.tar.bz2')
        eq_(mock_import([orig]), 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
        eq_(len(repo.get_commits(until='master')), 1)
        eq_(len(repo.get_commits(until='upstream')), 2)
        eq_(repo.get_tags(), ['upstream/1.0', 'upstream/1.1'])
        # Check that master is based on v1.0
        sha1 = repo.rev_parse("%s^0" % 'upstream/1.0')
        eq_(repo.get_merge_base('master', 'upstream'), sha1)
    def test_archive_from_spec(self):
        """Test taking archive file path from spec file"""
        repo = GitRepository.create('.')
        orig = os.path.join(DATA_DIR, 'gbp-test-1.0.tar.bz2')

        # Test non-existent spec file
        eq_(mock_import([]), 1)
        self._check_log(0, '.*No archive to import specified and no spec file')

        # Test non-existent archive
        self._create_dummy_spec('dummy.spec', source='non-existent.tar.gz')
        eq_(mock_import([]), 1)
        self._check_log(-1, '.*unable to find \S+non-existent.tar.gz')

        # Test failing download
        self._create_dummy_spec('dummy.spec', source='foo://bar.tar.gz')
        eq_(mock_import([]), 1)
        self._check_log(-1, '.*Download failed')

        # Test existing archive
        self._create_dummy_spec('dummy.spec', source=orig)
        eq_(mock_import([]), 0)
        self._check_repo_state(repo, None, ['upstream'], ['dummy.spec'])
Beispiel #30
0
    def test_invalid_args(self):
        """See that gbp-rpm-ch fails gracefully when called with invalid args"""
        GitRepository.create('.')

        with assert_raises(SystemExit):
            mock_ch(['--invalid-opt'])
 def test_invalid_args(self):
     """Check graceful exit when called with invalid args"""
     GitRepository.create('.')
     with assert_raises(SystemExit):
         mock_gbp(['--git-invalid-arg'])
 def setup(self):
     """Test case setup"""
     super(TestPristineTar, self).setup()
     self.repo = GitRepository.create('repo')
Beispiel #33
0
 def test_invalid_args(self):
     """Check graceful exit when called with invalid args"""
     GitRepository.create('.')
     with assert_raises(SystemExit):
         mock_gbp(['--git-invalid-arg'])
Beispiel #34
0
 def setUp(self):
     ComponentTestBase.setUp(self)
     self.target = GitRepository.create('target', bare=True)
Beispiel #35
0
 def setUp(self):
     ComponentTestBase.setUp(self)
     self.target = GitRepository.create('target', bare=True)
    def test_invalid_args(self):
        """See that gbp-rpm-ch fails gracefully when called with invalid args"""
        GitRepository.create('.')

        with assert_raises(SystemExit):
            mock_ch(['--invalid-opt'])