예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
def main(argv):
    """Entry point for gbp-submit-bb"""
    retval = 0

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

    try:
        repo = GitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("The command must be run under a Git repository")
        return 1

    try:
        remote = guess_remote(repo, options)

        tag_fields = {
            'nowtime': datetime.now().strftime('%Y%m%d.%H%M%S'),
            'target': options.target
        }
        tag_name = format_msg(options.submit_tag, tag_fields)

        gbp.log.info("Tagging %s" % tag_name)
        repo.create_tag(tag_name,
                        msg=options.message,
                        commit=options.commit,
                        sign=options.sign_tags,
                        keyid=options.keyid,
                        annotate=True)

        gbp.log.info("Pushing to remote %s" % remote)
        try:
            repo.push_tag(remote, tag_name)
        except GitRepositoryError as err:
            gbp.log.err(err)
            gbp.log.info("Removing tag %s" % tag_name)
            repo.delete_tag(tag_name)
            raise GbpError("Git push failed!")

    except (GbpError, GitRepositoryError) as err:
        if len(err.__str__()):
            gbp.log.err(err)
        retval = 1

    return retval