示例#1
0
文件: init.py 项目: kent74cn/gitosis
def initial_commit(git_dir, cfg, pubkey, user):
    repository.fast_import(
        git_dir=git_dir,
        commit_msg="Automatic creation of gitosis repository.",
        committer="Gitosis Admin <%s>" % user,
        files=[("keydir/%s.pub" % user, pubkey), ("gitosis.conf", cfg)],
    )
示例#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_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'])
示例#4
0
def test_dcontrol1():
    tmp = util.maketemp()
    projname = "foo"

    git_dir = os.path.join(tmp, projname + ".git")
    repository.init(path=git_dir)
    repository.fast_import(
        git_dir=git_dir,
        committer="John Doe 2 <*****@*****.**>",
        commit_msg="""\
Allow jdoe write access to foo
""",
        files=[("foo", "content"), ("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 foo")
    eq(got[5:], [])
示例#5
0
def test_has_initial_commit_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' "$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=tmp)
    repository.fast_import(git_dir=tmp, commit_msg="fakecommit", committer="John Doe <*****@*****.**>", files=[])
    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
        got = repository.has_initial_commit(git_dir=tmp)
    finally:
        os.environ["PATH"] = good_path
        os.environ.pop("GITOSIS_UNITTEST_COOKIE", None)
    eq(got, True)
    got = readFile(os.path.join(tmp, "cookie"))
    eq(got, magic_cookie)
示例#6
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']))
示例#7
0
def initial_commit(git_dir, cfg, pubkey, user):
    repository.fast_import(
        git_dir=git_dir,
        commit_msg='Automatic creation of gitosis repository.',
        committer='Gitosis Admin <%s>' % user,
        files=[
            ('keydir/%s.pub' % user, pubkey),
            ],
        )
示例#8
0
def initial_commit(git_dir, cfg, pubkey, user):
    """Import the initial files into the gitosis-admin repository."""
    repository.fast_import(
        git_dir=git_dir,
        commit_msg='Automatic creation of gitosis repository.',
        committer='Gitosis Admin <%s>' % user,
        files=[
            ('keydir/%s.pub' % user, pubkey),
            ('gitosis.conf', cfg),
            ],
        )
示例#9
0
def test_has_initial_commit_yes():
    tmp = maketemp()
    repository.init(path=tmp)
    repository.fast_import(
        git_dir=tmp,
        commit_msg='fakecommit',
        committer='John Doe <*****@*****.**>',
        files=[],
    )
    got = repository.has_initial_commit(git_dir=tmp)
    eq(got, True)
示例#10
0
def test_has_initial_commit_yes():
    tmp = maketemp()
    repository.init(path=tmp)
    repository.fast_import(
        git_dir=tmp,
        commit_msg='fakecommit',
        committer='John Doe <*****@*****.**>',
        files=[],
        )
    got = repository.has_initial_commit(git_dir=tmp)
    eq(got, True)
示例#11
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:], [])
示例#12
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:], [])
示例#13
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),
    )
示例#14
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),
        )
示例#15
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),
    )
示例#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_fast_import_environment():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path=path)
    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' "$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)
    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.fast_import(
            git_dir=path,
            commit_msg='foo initial bar',
            committer='Mr. Unit Test <*****@*****.**>',
            files=[
                ('foo', 'bar\n'),
            ],
        )
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    eq(
        sorted(os.listdir(tmp)),
        sorted([
            'mockbin',
            'cookie',
            'repo.git',
        ]),
    )
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(got, magic_cookie)
示例#18
0
def test_fast_import_environment():
    tmp = maketemp()
    path = os.path.join(tmp, 'repo.git')
    repository.init(path=path)
    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' "$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)
    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.fast_import(
            git_dir=path,
            commit_msg='foo initial bar',
            committer='Mr. Unit Test <*****@*****.**>',
            files=[
                ('foo', 'bar\n'),
                ],
            )
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    eq(
        sorted(os.listdir(tmp)),
        sorted([
                'mockbin',
                'cookie',
                'repo.git',
                ]),
        )
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(got, magic_cookie)
示例#19
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"]))
示例#20
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'])
示例#21
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'])
示例#22
0
def test_fast_import_environment():
    tmp = maketemp()
    path = os.path.join(tmp, "repo.git")
    repository.init(path=path)
    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' "$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)
    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.fast_import(
            git_dir=path,
            commit_msg="foo initial bar",
            committer="Mr. Unit Test <*****@*****.**>",
            files=[("foo", "bar\n")],
        )
    finally:
        os.environ["PATH"] = good_path
        os.environ.pop("GITOSIS_UNITTEST_COOKIE", None)
    eq(sorted(os.listdir(tmp)), sorted(["mockbin", "cookie", "repo.git"]))
    got = readFile(os.path.join(tmp, "cookie"))
    eq(got, magic_cookie)
示例#23
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:], [])
示例#24
0
def test_has_initial_commit_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' "$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=tmp)
    repository.fast_import(
        git_dir=tmp,
        commit_msg='fakecommit',
        committer='John Doe <*****@*****.**>',
        files=[],
    )
    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
        got = repository.has_initial_commit(git_dir=tmp)
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    eq(got, True)
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(got, magic_cookie)
示例#25
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"])
示例#26
0
def test_has_initial_commit_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' "$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=tmp)
    repository.fast_import(
        git_dir=tmp,
        commit_msg='fakecommit',
        committer='John Doe <*****@*****.**>',
        files=[],
        )
    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
        got = repository.has_initial_commit(git_dir=tmp)
    finally:
        os.environ['PATH'] = good_path
        os.environ.pop('GITOSIS_UNITTEST_COOKIE', None)
    eq(got, True)
    got = readFile(os.path.join(tmp, 'cookie'))
    eq(got, magic_cookie)
示例#27
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'])
def test_post_update_simple():
    tmp = maketemp()
    repos = os.path.join(tmp, 'repositories')
    os.mkdir(repos)
    admin_repository = os.path.join(repos, 'gitosis-admin.git')
    pubkey = (
        'ssh-somealgo '
        +'0123456789ABCDEFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
        +'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= fakeuser@fakehost')
    user = '******'
    init.init_admin_repository(
        git_dir=admin_repository,
        pubkey=pubkey,
        user=user,
        )
    repository.init(path=os.path.join(repos, 'forweb.git'))
    repository.init(path=os.path.join(repos, 'fordaemon.git'))
    repository.fast_import(
        git_dir=admin_repository,
        committer='John Doe <*****@*****.**>',
        commit_msg="""\
stuff
""",
        parent='refs/heads/master^0',
        files=[
            ('gitosis.conf', """\
[gitosis]

[group gitosis-admin]
members = theadmin
writable = gitosis-admin

[repo fordaemon]
daemon = yes

[repo forweb]
gitweb = yes
owner = John Doe
description = blah blah
"""),
            ('keydir/jdoe.pub',
             'ssh-somealgo '
             +'0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
             +'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= [email protected]'),
            ],
        )
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis', 'repositories', repos)
    generated = os.path.join(tmp, 'generated')
    os.mkdir(generated)
    cfg.set('gitosis', 'generate-files-in', generated)
    ssh = os.path.join(tmp, 'ssh')
    os.mkdir(ssh)
    cfg.set(
        'gitosis',
        'ssh-authorized-keys-path',
        os.path.join(ssh, 'authorized_keys'),
        )
    run_hook.post_update(
        cfg=cfg,
        git_dir=admin_repository,
        )
    got = readFile(os.path.join(repos, 'forweb.git', 'description'))
    eq(got, 'blah blah\n')
    got = os.listdir(generated)
    eq(got, ['projects.list'])
    got = readFile(os.path.join(generated, 'projects.list'))
    eq(
        got,
        """\
forweb.git John+Doe
""",
        )
    got = os.listdir(os.path.join(repos, 'fordaemon.git'))
    assert 'git-daemon-export-ok' in got, \
        "git-daemon-export-ok not created: %r" % got
    got = os.listdir(ssh)
    eq(got, ['authorized_keys'])
    got = readFile(os.path.join(ssh, 'authorized_keys')).splitlines(True)
    assert 'command="gitosis-serve jdoe",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-somealgo 0123456789ABCDEFBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB= [email protected]\n' in got, \
        "SSH authorized_keys line for jdoe not found: %r" % got