def test_submodules(tmpdir): foo_url = create_git_repo_with_submodules(tmpdir.strpath) work = tmpdir.mkdir("work") foo = work.mkdir("foo") git = qisrc.git.Git(foo.strpath) git.clone(foo_url) bar = foo.join("bar") assert qisrc.git.is_submodule(bar.strpath) assert not qisrc.git.is_submodule(foo.strpath) git.update_submodules() assert qisrc.git.is_submodule(bar.strpath)
def clone_project(worktree, url, src=None, branch=None, remote="origin"): """ Add a project to a worktree given its url. If src is not given, it will be guessed from the url """ should_add = True if not src: src = url.split("/")[-1].replace(".git", "") if os.path.isabs(src): src = os.path.relpath(src, worktree.root) src = qisys.sh.to_posix_path(src) else: src = qisys.sh.to_posix_path(src) conflict_project = worktree.get_project(src, raises=False) if conflict_project: mess = "Could not add project from %s in %s\n" % (url, src) mess += "This path is already registered for worktree in %s\n" % \ worktree.root raise Exception(mess) path = os.path.join(worktree.root, src) path = qisys.sh.to_native_path(path) if os.path.exists(path): mess = "Could not add project from %s in %s\n" % (url, src) mess += "This path already exists\n" raise Exception(mess) ui.info(ui.green, "Git clone: %s -> %s" % (url, path)) dirname = os.path.dirname(path) qisys.sh.mkdir(dirname, recursive=True) git = qisrc.git.Git(path) if branch: git.clone(url, "-b", branch, "-o", remote) else: git.clone(url, "-o", remote) git.update_submodules() if should_add: worktree.add_project(path) return worktree.get_project(src)