示例#1
0
def test_push_inits_no_stdout_spam():
    # git init has a tendency to spew to stdout, and that confuses
    # e.g. a git push
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    generated = os.path.join(tmp, "generated")
    os.mkdir(generated)
    cfg.set("gitosis", "generate-files-in", generated)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    old_stdout = os.dup(1)
    try:
        new_stdout = os.tmpfile()
        os.dup2(new_stdout.fileno(), 1)
        dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo'")
    finally:
        os.dup2(old_stdout, 1)
        os.close(old_stdout)
    new_stdout.seek(0)
    got = new_stdout.read()
    new_stdout.close()
    eq(got, "")
    eq(os.listdir(repositories), ["foo.git"])
    assert os.path.isfile(os.path.join(repositories, "foo.git", "HEAD"))
示例#2
0
def test_push_inits_if_needed_existsWithExtension():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    os.mkdir(os.path.join(repositories, "foo.git"))
    dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo'")
    eq(os.listdir(repositories), ["foo.git"])
    # it should *not* have HEAD here as we just mkdirred it and didn't
    # create it properly, and the mock repo didn't have anything in
    # it.. having HEAD implies serve ran git init, which is supposed
    # to be unnecessary here
    eq(os.listdir(os.path.join(repositories, "foo.git")), [])
示例#3
0
def test_push_inits_if_needed_haveExtension():
    # a push to a non-existent repository (but where config authorizes
    # you to do that) will create the repository on the fly
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    generated = os.path.join(tmp, "generated")
    os.mkdir(generated)
    cfg.set("gitosis", "generate-files-in", generated)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo.git'")
    eq(os.listdir(repositories), ["foo.git"])
    assert os.path.isfile(os.path.join(repositories, "foo.git", "HEAD"))
示例#4
0
def test_push_inits_sets_export_ok():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    generated = os.path.join(tmp, "generated")
    os.mkdir(generated)
    cfg.set("gitosis", "generate-files-in", generated)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    cfg.add_section("repo foo")
    cfg.set("repo foo", "daemon", "yes")
    dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo'")
    eq(os.listdir(repositories), ["foo.git"])
    path = os.path.join(repositories, "foo.git", "git-daemon-export-ok")
    assert os.path.exists(path)
示例#5
0
def test_push_inits_subdir_parent_missing():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    generated = os.path.join(tmp, "generated")
    os.mkdir(generated)
    cfg.set("gitosis", "generate-files-in", generated)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo/bar")
    dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo/bar.git'")
    eq(os.listdir(repositories), ["foo"])
    foo = os.path.join(repositories, "foo")
    util.check_mode(foo, 0750, is_dir=True)
    eq(os.listdir(foo), ["bar.git"])
    assert os.path.isfile(os.path.join(repositories, "foo", "bar.git", "HEAD"))
示例#6
0
def test_simple_write_space():
    tmp = util.maketemp()
    repository.init(os.path.join(tmp, "foo.git"))
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    got = dcontrol.serve(cfg=cfg, user="******", command="git receive-pack 'foo'")
    eq(got, "git receive-pack '%s/foo.git'" % tmp)
示例#7
0
def test_push_inits_updates_projects_list():
    tmp = util.maketemp()
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    repositories = os.path.join(tmp, "repositories")
    os.mkdir(repositories)
    cfg.set("gitosis", "repositories", repositories)
    generated = os.path.join(tmp, "generated")
    os.mkdir(generated)
    cfg.set("gitosis", "generate-files-in", generated)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writable", "foo")
    cfg.add_section("repo foo")
    cfg.set("repo foo", "gitweb", "yes")
    os.mkdir(os.path.join(repositories, "gitosis-admin.git"))
    dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo'")
    eq(sorted(os.listdir(repositories)), sorted(["foo.git", "gitosis-admin.git"]))
    path = os.path.join(generated, "projects.list")
    assert os.path.exists(path)
    got = util.readFile(path)
    eq(got, "foo.git\n")
示例#8
0
def test_absolute():
    # as the only convenient way to use non-standard SSH ports with
    # git is via the ssh://user@host:port/path syntax, and that syntax
    # forces absolute urls, just force convert absolute paths to
    # relative paths; you'll never really want absolute paths via
    # gitosis, anyway.
    tmp = util.maketemp()
    repository.init(os.path.join(tmp, "foo.git"))
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "readonly", "foo")
    got = dcontrol.serve(cfg=cfg, user="******", command="git-upload-pack '/foo'")
    eq(got, "git-upload-pack '%s/foo.git'" % tmp)
示例#9
0
def test_typo_writeable():
    tmp = util.maketemp()
    repository.init(os.path.join(tmp, "foo.git"))
    cfg = RawConfigParser()
    cfg.add_section("gitosis")
    cfg.set("gitosis", "repositories", tmp)
    cfg.add_section("group foo")
    cfg.set("group foo", "members", "jdoe")
    cfg.set("group foo", "writeable", "foo")
    log = logging.getLogger("dcontrol.serve")
    buf = StringIO()
    handler = logging.StreamHandler(buf)
    log.addHandler(handler)
    try:
        got = dcontrol.serve(cfg=cfg, user="******", command="git-receive-pack 'foo'")
    finally:
        log.removeHandler(handler)
    eq(got, "git-receive-pack '%s/foo.git'" % tmp)
    handler.flush()
    eq(buf.getvalue(), "Repository 'foo' config has typo \"writeable\", shou" + 'ld be "writable"\n')