示例#1
0
def test_push_mirrors():
    tmp = maketemp()
    foo_path = os.path.join(tmp, 'foo.git')
    bar_path = os.path.join(tmp, 'bar.git')
    baz_path = os.path.join(tmp, 'baz.git')
    repository.init(path=foo_path, template=False)
    repository.init(path=bar_path, template=False)
    repository.init(path=baz_path, template=False)
    repository.fast_import(
        git_dir=foo_path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    cfg = get_config()
    cfg.set('repo foo', 'mirrors', ' '.join([bar_path,baz_path]))
    mirror.push_mirrors(cfg, foo_path)
    export_bar = os.path.join(tmp, 'export_bar')
    export_baz = os.path.join(tmp, 'export_baz')
    repository.export(
        git_dir=bar_path,
        path=export_bar,
        )
    repository.export(
        git_dir=baz_path,
        path=export_baz,
        )
    eq(os.listdir(export_bar),
       ['foo'])
    eq(os.listdir(export_baz),
       ['foo'])
示例#2
0
def test_fast_import_parent():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path=path)
    repository.fast_import(
        git_dir=path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    repository.fast_import(
        git_dir=path,
        commit_msg='another',
        committer='Sam One Else <*****@*****.**>',
        parent='refs/heads/master^0',
        files=[
            ('quux', 'thud\n'),
            ],
        )
    export = os.path.join(tmp, 'export')
    repository.export(
        git_dir=path,
        path=export,
        )
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'quux']))
示例#3
0
def test_fast_import_parent():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path=path)
    repository.fast_import(
        git_dir=path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
        ],
    )
    repository.fast_import(
        git_dir=path,
        commit_msg='another',
        committer='Sam One Else <*****@*****.**>',
        parent='refs/heads/master^0',
        files=[
            ('quux', 'thud\n'),
        ],
    )
    export = os.path.join(tmp, 'export')
    repository.export(
        git_dir=path,
        path=export,
    )
    eq(sorted(os.listdir(export)), sorted(['foo', 'quux']))
示例#4
0
def post_update(cfg, git_dir): #pragma: no cover
    """
    post-update hook for the Gitosis admin directory.

    1. Make an export of the admin repo to a clean directory.
    2. Move the gitosis.conf file to it's destination.
    3. Update the repository descriptions.
    4. Update the projects.list file.
    5. Update the repository export markers.
    6. Update the Gitosis SSH keys.
    """
    export = os.path.join(git_dir, 'gitosis-export')
    util.rmtree(export)
    repository.export(git_dir=git_dir, path=export)
    os.rename(
        os.path.join(export, 'gitosis.conf'),
        os.path.join(export, '..', 'gitosis.conf'),
        )
    # re-read config to get up-to-date settings
    cfg.read(os.path.join(export, '..', 'gitosis.conf'))
    build_reposistory_data(cfg)
    authorized_keys = cfg.ssh_authorized_keys_path
    ssh.writeAuthorizedKeys(
        path=authorized_keys,
        keydir=os.path.join(export, 'keydir'),
        )
示例#5
0
def post_update(cfg, git_dir):
    export = os.path.join(git_dir, 'gitosis-export')
    try:
        shutil.rmtree(export)
    except OSError as e:
        if e.errno == errno.ENOENT:
            pass
        else:
            raise
    repository.export(git_dir=git_dir, path=export)
    os.rename(
        os.path.join(export, 'gitosis.conf'),
        os.path.join(export, '..', 'gitosis.conf'),
    )
    # re-read config to get up-to-date settings
    cfg.read(os.path.join(export, '..', 'gitosis.conf'))
    gitweb.set_descriptions(config=cfg, )
    generated = util.getGeneratedFilesDir(config=cfg)
    gitweb.generate_project_list(
        config=cfg,
        path=os.path.join(generated, 'projects.list'),
    )
    gitdaemon.set_export_ok(config=cfg, )
    authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg)
    ssh.writeAuthorizedKeys(
        path=authorized_keys,
        keydir=os.path.join(export, 'keydir'),
    )
示例#6
0
def test_init_admin_repository():
    tmp = maketemp()
    admin_repository = os.path.join(tmp, 'admin.git')
    pubkey = (
        'ssh-somealgo '
        +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
    user = '******'
    cfg = GitosisRawConfigParser()
    init.init_admin_repository(
        git_dir=admin_repository,
        pubkey=pubkey,
        user=user,
        config=cfg,
        )
    eq(os.listdir(tmp), ['admin.git'])
    hook = os.path.join(
        tmp,
        'admin.git',
        'hooks',
        'post-update',
        )
    util.check_mode(hook, 0755, is_file=True)
    got = util.readFile(hook).splitlines()
    assert 'gitosis-run-hook post-update' in got
    export_dir = os.path.join(tmp, 'export')
    repository.export(git_dir=admin_repository,
                      path=export_dir)
    eq(sorted(os.listdir(export_dir)),
       sorted(['gitosis.conf', 'keydir']))
    eq(os.listdir(os.path.join(export_dir, 'keydir')),
       ['jdoe.pub'])
    got = util.readFile(
        os.path.join(export_dir, 'keydir', 'jdoe.pub'))
    eq(got, pubkey)
    # the only thing guaranteed of initial config file ordering is
    # that [gitosis] is first
    got = util.readFile(os.path.join(export_dir, 'gitosis.conf'))
    # We can't gaurentee this anymore
    got = got.splitlines()[0]
    eq(got, '[gitosis]')
    cfg.read(os.path.join(export_dir, 'gitosis.conf'))
    eq(sorted(cfg.sections()),
       sorted([
        'gitosis',
        'group gitosis-admin',
        ]))
    eq(cfg.items('gitosis'), [])
    eq(sorted(cfg.items('group gitosis-admin')),
       sorted([
        ('writable', 'gitosis-admin'),
        ('members', 'jdoe'),
        ]))
示例#7
0
def test_export_simple():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[
            ('foo', 'content'),
            ('bar/quux', 'another'),
            ],
        )
    export = os.path.join(tmp, 'export')
    repository.export(git_dir=git_dir, path=export)
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'bar']))
    eq(readFile(os.path.join(export, 'foo')), 'content')
    eq(os.listdir(os.path.join(export, 'bar')), ['quux'])
    eq(readFile(os.path.join(export, 'bar', 'quux')), 'another')
    child = subprocess.Popen(
        args=[
            'git',
            '--git-dir=%s' % git_dir,
            'cat-file',
            'commit',
            'HEAD',
            ],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
        )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError('git exit status %d' % returncode)
    eq(got[0].split(None, 1)[0], 'tree')
    eq(got[1].rsplit(None, 2)[0],
       'author John Doe <*****@*****.**>')
    eq(got[2].rsplit(None, 2)[0],
       'committer John Doe <*****@*****.**>')
    eq(got[3], '')
    eq(got[4], 'Reverse the polarity of the neutron flow.')
    eq(got[5], '')
    eq(got[6], 'Frobitz the quux and eschew obfuscation.')
    eq(got[7:], [])
示例#8
0
def test_export_simple():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[
            ('foo', 'content'),
            ('bar/quux', 'another'),
            ],
        )
    export = os.path.join(tmp, 'export')
    repository.export(git_dir=git_dir, path=export)
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'bar']))
    eq(readFile(os.path.join(export, 'foo')), 'content')
    eq(os.listdir(os.path.join(export, 'bar')), ['quux'])
    eq(readFile(os.path.join(export, 'bar', 'quux')), 'another')
    child = subprocess.Popen(
        args=[
            'git',
            '--git-dir=%s' % git_dir,
            'cat-file',
            'commit',
            'HEAD',
            ],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
        )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError('git exit status %d' % returncode)
    eq(got[0].split(None, 1)[0], 'tree')
    eq(got[1].rsplit(None, 2)[0],
       'author John Doe <*****@*****.**>')
    eq(got[2].rsplit(None, 2)[0],
       'committer John Doe <*****@*****.**>')
    eq(got[3], '')
    eq(got[4], 'Reverse the polarity of the neutron flow.')
    eq(got[5], '')
    eq(got[6], 'Frobitz the quux and eschew obfuscation.')
    eq(got[7:], [])
示例#9
0
def test_export_environment():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    mockbindir = os.path.join(tmp, 'mockbin')
    os.mkdir(mockbindir)
    mockgit = os.path.join(mockbindir, 'git')
    writeFile(
        mockgit, '''\
#!/bin/sh
set -e
# git wrapper for gitosis unit tests
printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie"

# strip away my special PATH insert so system git will be found
PATH="${PATH#*:}"

exec git "$@"
''')
    os.chmod(mockgit, 0o755)
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[
            ('foo', 'content'),
            ('bar/quux', 'another'),
        ],
    )
    export = os.path.join(tmp, 'export')
    magic_cookie = '%d' % random.randint(1, 100000)
    good_path = os.environ['PATH']
    try:
        os.environ['PATH'] = '%s:%s' % (mockbindir, good_path)
        os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie
        repository.export(git_dir=git_dir, path=export)
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(
        got,
        # export runs git twice
        '%s\n%s\n' % (magic_cookie, magic_cookie),
    )
示例#10
0
def test_export_environment():
    tmp = maketemp()
    git_dir = os.path.join(tmp, "repo.git")
    mockbindir = os.path.join(tmp, "mockbin")
    os.mkdir(mockbindir)
    mockgit = os.path.join(mockbindir, "git")
    writeFile(
        mockgit,
        """\
#!/bin/sh
set -e
# git wrapper for gitosis unit tests
printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie"

# strip away my special PATH insert so system git will be found
PATH="${PATH#*:}"

exec git "$@"
""",
    )
    os.chmod(mockgit, 0755)
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer="John Doe <*****@*****.**>",
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[("foo", "content"), ("bar/quux", "another")],
    )
    export = os.path.join(tmp, "export")
    magic_cookie = "%d" % random.randint(1, 100000)
    good_path = os.environ["PATH"]
    try:
        os.environ["PATH"] = "%s:%s" % (mockbindir, good_path)
        os.environ["GITOSIS_UNITTEST_COOKIE"] = magic_cookie
        repository.export(git_dir=git_dir, path=export)
    finally:
        os.environ["PATH"] = good_path
        os.environ.pop("GITOSIS_UNITTEST_COOKIE", None)
    got = readFile(os.path.join(tmp, "cookie"))
    eq(
        got,
        # export runs git twice
        "%s\n%s\n" % (magic_cookie, magic_cookie),
    )
示例#11
0
def test_export_environment():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    mockbindir = os.path.join(tmp, 'mockbin')
    os.mkdir(mockbindir)
    mockgit = os.path.join(mockbindir, 'git')
    writeFile(mockgit, '''\
#!/bin/sh
set -e
# git wrapper for gitosis unit tests
printf '%s\n' "$GITOSIS_UNITTEST_COOKIE" >>"$(dirname "$0")/../cookie"

# strip away my special PATH insert so system git will be found
PATH="${PATH#*:}"

exec git "$@"
''')
    os.chmod(mockgit, 0755)
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[
            ('foo', 'content'),
            ('bar/quux', 'another'),
            ],
        )
    export = os.path.join(tmp, 'export')
    magic_cookie = '%d' % random.randint(1, 100000)
    good_path = os.environ['PATH']
    try:
        os.environ['PATH'] = '%s:%s' % (mockbindir, good_path)
        os.environ['GITOSIS_UNITTEST_COOKIE'] = magic_cookie
        repository.export(git_dir=git_dir, path=export)
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(
        got,
        # export runs git twice
        '%s\n%s\n' % (magic_cookie, magic_cookie),
        )
示例#12
0
def test_mirror():
    tmp = maketemp()
    main_path = os.path.join(tmp, "main.git")
    mirror_path = os.path.join(tmp, "mirror.git")
    repository.init(path=main_path, template=False)
    repository.init(path=mirror_path, template=False)
    repository.fast_import(
        git_dir=main_path,
        commit_msg="foo initial bar",
        committer="Mr. Unit Test <*****@*****.**>",
        files=[("foo", "bar\n")],
    )
    repository.mirror(main_path, mirror_path)
    export = os.path.join(tmp, "export")
    repository.export(git_dir=mirror_path, path=export)
    eq(os.listdir(export), ["foo"])
示例#13
0
def test_init_admin_repository():
    tmp = maketemp()
    admin_repository = os.path.join(tmp, 'admin.git')
    pubkey = ('ssh-somealgo ' +
              '0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
              'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
              'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
              'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
    user = '******'
    init.init_admin_repository(
        git_dir=admin_repository,
        pubkey=pubkey,
        user=user,
    )
    eq(os.listdir(tmp), ['admin.git'])
    hook = os.path.join(
        tmp,
        'admin.git',
        'hooks',
        'post-update',
    )
    util.check_mode(hook, 0o755, is_file=True)
    got = util.readFile(hook).splitlines()
    assert 'gitosis-run-hook post-update' in got
    export_dir = os.path.join(tmp, 'export')
    repository.export(git_dir=admin_repository, path=export_dir)
    eq(sorted(os.listdir(export_dir)), sorted(['gitosis.conf', 'keydir']))
    eq(os.listdir(os.path.join(export_dir, 'keydir')), ['jdoe.pub'])
    got = util.readFile(os.path.join(export_dir, 'keydir', 'jdoe.pub'))
    eq(got, pubkey)
    # the only thing guaranteed of initial config file ordering is
    # that [gitosis] is first
    got = util.readFile(os.path.join(export_dir, 'gitosis.conf'))
    got = got.splitlines()[0]
    eq(got, '[gitosis]')
    cfg = RawConfigParser()
    cfg.read(os.path.join(export_dir, 'gitosis.conf'))
    eq(sorted(cfg.sections()), sorted([
        'gitosis',
        'group gitosis-admin',
    ]))
    eq(cfg.items('gitosis'), [])
    eq(sorted(cfg.items('group gitosis-admin')),
       sorted([
           ('writable', 'gitosis-admin'),
           ('members', 'jdoe'),
       ]))
示例#14
0
def test_fast_import_parent():
    tmp = maketemp()
    path = os.path.join(tmp, "repo.git")
    repository.init(path=path)
    repository.fast_import(
        git_dir=path,
        commit_msg="foo initial bar",
        committer="Mr. Unit Test <*****@*****.**>",
        files=[("foo", "bar\n")],
    )
    repository.fast_import(
        git_dir=path,
        commit_msg="another",
        committer="Sam One Else <*****@*****.**>",
        parent="refs/heads/master^0",
        files=[("quux", "thud\n")],
    )
    export = os.path.join(tmp, "export")
    repository.export(git_dir=path, path=export)
    eq(sorted(os.listdir(export)), sorted(["foo", "quux"]))
示例#15
0
def test_push_mirrors():
    tmp = maketemp()
    foo_path = os.path.join(tmp, 'foo.git')
    copy1_path = os.path.join(tmp, 'copy1.git')
    copy2_path = os.path.join(tmp, 'copy2.git')
    cfg = get_config()
    cfg.set('gitosis', 'repositories', tmp)
    cfg.set('repo foo', 'mirrors', ' '.join([copy1_path,copy2_path]))
    ## create foo repository and its mirrors (leave the mirror empty
    repository.init(path=foo_path, template=False)
    repository.init(path=copy1_path, template=False)
    repository.init(path=copy2_path, template=False)
    repository.fast_import(
        git_dir=foo_path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    
    ## push changes to mirror
    mirror.push_mirrors(cfg, foo_path)
    
    ## check content of mirrors
    export_copy1 = os.path.join(tmp, 'export1')
    repository.export(
        git_dir=copy1_path,
        path=export_copy1,
        )
    eq(os.listdir(export_copy1),
       ['foo'])
    
    export_copy2 = os.path.join(tmp, 'export2')
    repository.export(
        git_dir=copy2_path,
        path=export_copy2,
        )
    eq(os.listdir(export_copy2),
       ['foo'])
示例#16
0
def test_mirror():
    tmp = maketemp()
    main_path = os.path.join(tmp, 'main.git')
    mirror_path = os.path.join(tmp, 'mirror.git')
    repository.init(path=main_path, template=False)
    repository.init(path=mirror_path, template=False)
    repository.fast_import(
        git_dir=main_path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    repository.mirror(main_path, mirror_path)
    export = os.path.join(tmp, 'export')
    repository.export(
        git_dir=mirror_path,
        path=export,
        )
    eq(os.listdir(export),
       ['foo'])
示例#17
0
def test_export_simple():
    tmp = maketemp()
    git_dir = os.path.join(tmp, "repo.git")
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer="John Doe <*****@*****.**>",
        commit_msg="""\
Reverse the polarity of the neutron flow.

Frobitz the quux and eschew obfuscation.
""",
        files=[("foo", "content"), ("bar/quux", "another")],
    )
    export = os.path.join(tmp, "export")
    repository.export(git_dir=git_dir, path=export)
    eq(sorted(os.listdir(export)), sorted(["foo", "bar"]))
    eq(readFile(os.path.join(export, "foo")), "content")
    eq(os.listdir(os.path.join(export, "bar")), ["quux"])
    eq(readFile(os.path.join(export, "bar", "quux")), "another")
    child = subprocess.Popen(
        args=["git", "--git-dir=%s" % git_dir, "cat-file", "commit", "HEAD"],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
    )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError("git exit status %d" % returncode)
    eq(got[0].split(None, 1)[0], "tree")
    eq(got[1].rsplit(None, 2)[0], "author John Doe <*****@*****.**>")
    eq(got[2].rsplit(None, 2)[0], "committer John Doe <*****@*****.**>")
    eq(got[3], "")
    eq(got[4], "Reverse the polarity of the neutron flow.")
    eq(got[5], "")
    eq(got[6], "Frobitz the quux and eschew obfuscation.")
    eq(got[7:], [])
示例#18
0
def test_push_mirrors():
    tmp = maketemp()
    foo_path = os.path.join(tmp, "foo.git")
    bar_path = os.path.join(tmp, "bar.git")
    baz_path = os.path.join(tmp, "baz.git")
    repository.init(path=foo_path, template=False)
    repository.init(path=bar_path, template=False)
    repository.init(path=baz_path, template=False)
    repository.fast_import(
        git_dir=foo_path,
        commit_msg="foo initial bar",
        committer="Mr. Unit Test <*****@*****.**>",
        files=[("foo", "bar\n")],
    )
    cfg = get_config()
    cfg.set("repo foo", "mirrors", " ".join([bar_path, baz_path]))
    mirror.push_mirrors(cfg, foo_path)
    export_bar = os.path.join(tmp, "export_bar")
    export_baz = os.path.join(tmp, "export_baz")
    repository.export(git_dir=bar_path, path=export_bar)
    repository.export(git_dir=baz_path, path=export_baz)
    eq(os.listdir(export_bar), ["foo"])
    eq(os.listdir(export_baz), ["foo"])
示例#19
0
def post_update(cfg, git_dir=None):
    if not git_dir:
        git_dir = os.environ.get('GIT_DIR')
        if git_dir is None:
            log.error('Must have GIT_DIR set in enviroment')
            sys.exit(1)

    export = os.path.join(git_dir, 'export')
    try:
        shutil.rmtree(export)
    except OSError, e:
        if e.errno == errno.ENOENT:
            pass
        else:
            raise
    repository.export(git_dir=git_dir, path=os.path.join(export, "track"))

def regenerate_keys(cfg):
    authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg)
    ssh.writeAuthorizedKeys(
        path=authorized_keys,
        keydir=cfg.get('gitosis', 'keydir'),
        )

class Main(app.App):
    def create_parser(self):
        parser = super(Main, self).create_parser()
        parser.set_usage('%prog [OPTS] HOOK')
        parser.set_description(
            'Perform gitosis actions for a git hook')
        return parser
示例#20
0
def test_dcontrol():
    tmp = maketemp()
    git_dir = os.path.join(tmp, 'repo.git')
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer='John Doe 2 <*****@*****.**>',
        commit_msg="""\
Allow jdoe write access to repo
""",
        files=[
            ('foo', 'content'),
            ('bar/quux', 'another'),
            ],
        )
    export = os.path.join(tmp, 'export', 'var', 'sites')
    print "Second Export: " + export
    repository.export(git_dir=git_dir, path=export)
    eq(sorted(os.listdir(export)),
       sorted(['foo', 'bar']))
    eq(readFile(os.path.join(export, 'foo')), 'content')
    eq(os.listdir(os.path.join(export, 'bar')), ['quux'])
    eq(readFile(os.path.join(export, 'bar', 'quux')), 'another')
    child = subprocess.Popen(
        args=[
            'git',
            '--git-dir=%s' % git_dir,
            'cat-file',
            'commit',
            'HEAD',
            ],
        cwd=git_dir,
        stdout=subprocess.PIPE,
        close_fds=True,
        )
    got = child.stdout.read().splitlines()
    returncode = child.wait()
    if returncode != 0:
        raise RuntimeError('git exit status %d' % returncode)
    eq(got[0].split(None, 1)[0], 'tree')
    eq(got[1].rsplit(None, 2)[0],
       'author John Doe 2 <*****@*****.**>')
    eq(got[2].rsplit(None, 2)[0],
       'committer John Doe 2 <*****@*****.**>')
    eq(got[3], '')
    eq(got[4], 'Allow jdoe write access to repo')
    eq(got[5:], [])

    main_path = os.path.join(tmp, 'main.git')
    mirror_path = os.path.join(tmp, 'mirror.git')
    rep2 = repository
    rep2.init(path=main_path, template=False)
    rep2.init(path=mirror_path, template=False)
    rep2.fast_import(
        git_dir=main_path,
        commit_msg='foo initial bar',
        committer='Mr. Unit Test <*****@*****.**>',
        files=[
            ('foo', 'bar\n'),
            ],
        )
    rep2.mirror(main_path, mirror_path)
    export2 = os.path.join(tmp, 'export')
    rep2.export(
        git_dir=mirror_path,
        path=export2,
        )
    eq(os.listdir(export2),
       ['foo'])
示例#21
0
        except GitInitError, e:
            log.warning('Auto-init failed: %r' % e)
        except GitError, e:
            log.warning('Git error in init: %r' % e)


def post_update(cfg, git_dir):
    export = os.path.join(git_dir, 'gitosis-export')
    try:
        shutil.rmtree(export)
    except OSError, e:
        if e.errno == errno.ENOENT:
            pass
        else:
            raise
    repository.export(git_dir=git_dir, path=export)
    os.rename(
        os.path.join(export, 'gitosis.conf'),
        os.path.join(export, '..', 'gitosis.conf'),
        )
    # re-read config to get up-to-date settings
    cfg.read(os.path.join(export, '..', 'gitosis.conf'))
    autoinit_repos(config=cfg)
    gitweb.set_descriptions(
        config=cfg,
        )
    generated = util.getGeneratedFilesDir(config=cfg)
    gitweb.generate_project_list(
        config=cfg,
        path=os.path.join(generated, 'projects.list'),
        )
示例#22
0
from gitosis import ssh
from gitosis import gitweb
from gitosis import gitdaemon
from gitosis import app
from gitosis import util

def post_update(cfg, git_dir):
    export = os.path.join(git_dir, 'gitosis-export')
    try:
        shutil.rmtree(export)
    except OSError, e:
        if e.errno == errno.ENOENT:
            pass
        else:
            raise
    repository.export(git_dir=git_dir, path=export)
    os.rename(
        os.path.join(export, 'gitosis.conf'),
        os.path.join(export, '..', 'gitosis.conf'),
        )
    # re-read config to get up-to-date settings
    cfg.read(os.path.join(export, '..', 'gitosis.conf'))
    gitweb.set_descriptions(
        config=cfg,
        )
    generated = util.getGeneratedFilesDir(config=cfg)
    gitweb.generate_project_list(
        config=cfg,
        path=os.path.join(generated, 'projects.list'),
        )
    gitdaemon.set_export_ok(