8 from invirt import builder, common
9 from invirt.config import structs as config
11 REPO_BASE = '/srv/git/invirt'
12 HOOK_BASE = '/usr/share/invirt-dev/git-hooks'
15 parser = optparse.OptionParser('%prog repo <category> <name>')
16 opts, args = parser.parse_args()
24 principal = os.environ['REMOTE_USER']
25 repo_path = os.path.join(REPO_BASE, category, '%s.git' % name)
27 if os.path.exists(repo_path):
28 print >>sys.stderr, '%s already exists!' % repo_path
31 print 'Creating new repo at %s' % repo_path
32 os.makedirs(repo_path)
33 common.captureOutput(['git', 'init', '--bare', '--shared=group'], cwd=repo_path)
34 common.captureOutput(['git', 'config', 'receive.denyNonFastForwards', 'false'], cwd=repo_path)
35 common.captureOutput(['chgrp', 'repo', '-R', '.'], cwd=repo_path)
36 print 'Replacing hooks directory with a symlink'
37 hooks_dir = os.path.join(repo_path, 'hooks')
38 shutil.rmtree(hooks_dir)
39 common.captureOutput(['chown', '-R', 'git:', repo_path])
40 if category == 'packages':
41 os.symlink(os.path.join(HOOK_BASE, 'sub'), hooks_dir)
43 os.symlink(os.path.join(HOOK_BASE, 'other'), hooks_dir)
45 builder.runHook('post-add-repo', [category, name, principal])
47 if __name__ == '__main__':