import os
import shutil
import subprocess
from repotypes.base import RepotypeBase
class RepotypeGit(RepotypeBase):
def __init__(self):
super().__init__('GIT')
def check_config(self, server, config):
super().check_config(server, config)
config['command'] = server.fixpath(config['command'], root = True)
config['command'] = server.fixpath(config['command'], root = True)
config['environment'] = server.fixenv(config['environment'])
def configure(self, server, config):
super().configure(server, config)
self.command = self.config['command']
self.environment = self.config['environment']
assert self.command[0] == '/'
assert not self.environment is None
def create(self, subpath):
path = self.gen_path(subpath)
print(self.name + ': Creating repository by path: ' + path)
parentpath = self.parentdir(path)
self.mkdir(parentpath)
subprocess.run([self.command, 'init', '--bare', path], env = self.environment, cwd = parentpath)
subprocess.run([self.command, 'config', 'http.receivepack', 'true'], env = self.environment, cwd = path)
def iswriteaccess(self, request, path):
if request.method == 'GET' and request.urlvars.get('service', list()).count('git-receive-pack'):
return True
if request.method == 'POST' and len(path) == 1 and path[0] == 'git-upload-pack':
return False
return request.method != 'GET'
def delete(self, subpath):
path = self.gen_path(subpath)
print(self.name + ': Deleting repository by path: ' + path)
if os.path.exists(path):
shutil.rmtree( self.gen_path(subpath) )