Exemple #1
0
 def test_config_set_and_get(self):
     """Set and get per-repository config values.
     """
     with Tempdir(cwd=True) as tempdir:
         git = Git()
         self.assertEquals(None, git.config_get("foo.bar"))
         git.init(quiet=True)
         git.config_set("foo.bar", "baz")
         self.assertEquals("baz", git.config_get("foo.bar"))
Exemple #2
0
class Conduit(object):
    """CVS-to-Git conduit logic
    """

    def __init__(self, directory=None):
        self.git = Git(directory)
        self.branch = 'refs/heads/cvs/HEAD'
        self._cvs = None
        self._config = {}

    def config_get(self, varname):
        """Get a Git variable from the 'cvs' section
        """
        if self._config.has_key(varname):
            return self._config[varname]
        else:
            value = self.git.config_get('cvs.' + varname)
            self._config[varname] = value
            return value

    def config_set(self, varname, value):
        """Set a Git variable in the 'cvs' section
        """
        self.git.config_set('cvs.' + varname, value)
        self._config[varname] = value

    def get_source(self):
        """Get the CVS repository source path
        """
        source = self.config_get('source')
        if source is None:
            raise NoSourceError
        return source

    def set_source(self, directory):
        """Set the CVS repository source path
        """
        self.config_set('source', directory)

    source = property(get_source, set_source)

    def get_domain(self):
        return self.config_get('domain')

    def set_domain(self, directory):
        self.config_set('domain', directory)

    domain = property(get_domain, set_domain)

    def get_cvs(self):
        if self._cvs == None:
            filename = os.path.join(self.git.git_dir, 'cvsgit.db')
            metadb = MetaDb(filename)
            self._cvs = CVS(self.source, metadb)
        return self._cvs

    cvs = property(get_cvs)

    def init(self, repository, domain=None, bare=False, quiet=True):
        self.git.init(bare=bare, quiet=quiet)

        if not self.git.is_bare() and \
                self.git.config_get('branch.master.remote') == None:
            self.git.config_set('branch.master.remote', '.')
            self.git.config_set('branch.master.merge', self.branch)
            self.git.config_set('branch.master.rebase', 'true')

        self.source = repository

        if domain:
            self.domain = domain

    def fetch(self, limit=None, quiet=True, verbose=False,
              authors=None, stop_on_unknown_author=False):
        """Fetch new changesets into the CVS tracking branch.
        """
        if quiet or verbose:
            progress = None
        else:
            progress = Progress()

        self.cvs.fetch(progress=progress, limit=limit)

        # XXX: Should not access private self.cvs.metadb.
        if authors and stop_on_unknown_author:
            unknown = []
            for author in self.cvs.metadb.all_authors():
                if not authors.has_key(author):
                    unknown.append(author)
            if len(unknown) > 0:
                raise UnknownAuthorFullnames(unknown)

        self.git.import_changesets(self.cvs.changesets(), self.branch,
                                   domain=self.domain,
                                   limit=limit,
                                   verbose=verbose,
                                   progress=progress,
                                   total=self.cvs.count_changesets(),
                                   authors=authors,
                                   stop_on_unknown_author=\
                                       stop_on_unknown_author)

    def pull(self, limit=None, quiet=True, verbose=False, authors=None,
             stop_on_unknown_author=False):
        self.fetch(limit=limit, quiet=quiet, verbose=verbose,
                   authors=authors, stop_on_unknown_author=\
                       stop_on_unknown_author)

        args = []
        if quiet:
            args.append('--quiet')

        # XXX: --quiet is not enough if branch.<branch>.rebase is true
        #self.git.pull(*args)
        import subprocess
        self.git.check_command('pull', *args, stdout=subprocess.PIPE)