예제 #1
0
 def set_config(self, keys):
     """set a list of config options
     
     Arguments:
     - `keys`: a map of config options
     """
     l = logging.getLogger('git')
     for (k, v) in keys.iteritems():
         l.debug('setting %s = %s' % (k, v))
         run_cmd('git config --local --replace-all %s %s' % (k, v), self._path)
예제 #2
0
    def bind(self, ):
        """
        perform verfication and create repository (if bare)
        """
        if self._bare:
            if os.path.exists(self._path):
                raise GitException('path %s already present' % (self._path))

            run_cmd('git init --bare %s' % (self._path))
        else:
            if not is_git_repo(self._path):
                raise GitException('%s is not a git repository' % (self._path))
예제 #3
0
def is_git_repo(path):
    """
    check if a repository is present under given path
    Arguments:
    - `path`:
    """
    ret, out, err = run_cmd('git rev-parse --git-dir', path)
    if ret == 0:
        return True
    return False
예제 #4
0
    def get_config(self, keys=None):
        """get a config option for key
        
        Arguments:
        - `keys`: list of keys to get, empty list or None means all keys
        """
        l = logging.getLogger('git')
        d = {}
        # get all keys first
        ret, out, err = run_cmd('git config --local -l', self._path)
        if ret != 0:
            raise GitException('failed to obtain configuration')
        
        l.debug('wanted keys: %s' % (keys))

        # then filter only ones we are interested in
        lines = out.strip().split('\n')
        for l in lines:
            k, v = l.split('=')
            if not keys or k in keys:
                d[k] = v

        return d
예제 #5
0
 def run_gc(self, ):
     """run gc on repository
     """
     run_cmd('git gc', self._path)