예제 #1
0
def test_git_get_local_branches(tmpdir):
    tmpdir = tmpdir.strpath
    git = qisrc.git.Git(tmpdir)
    # pylint: disable-msg=E1101
    with pytest.raises(Exception):
        git.get_local_branches()
    write_readme(tmpdir, "readme\n")
    git.call("init")
    git.call("add", ".")
    git.commit("-m", "initial commit")
    assert git.get_local_branches() == ["master"]
    git.checkout("-b", "devel")
    assert git.get_local_branches() == ["devel", "master"]
예제 #2
0
def push_file(tmp, git_path, filename, contents, branch="master"):
    """ Push a file to the given url. Assumes the repository
    has been created with :py:func:`create_git_repo` with the same
    path

    """
    tmp_src = os.path.join(tmp, "src", git_path)
    tmp_srv = os.path.join(tmp, "srv", git_path + ".git")
    git = qisrc.git.Git(tmp_src)
    if branch in git.get_local_branches():
        git.checkout("-f", branch)
    else:
        git.checkout("-b", branch)
    dirname = os.path.dirname(filename)
    qibuild.sh.mkdir(os.path.join(tmp_src, dirname), recursive=True)
    with open(os.path.join(tmp_src, filename), "w") as fp:
        fp.write(contents)
    git.add(filename)
    git.commit("-m", "added %s" % filename)
    git.push(tmp_srv, "%s:%s" % (branch, branch))