@@ -0,0 +1,1468 @@
+import tempfile%0Aimport typer%0Afrom pathlib import Path%0Aimport subprocess%0Aimport shlex%0Aimport shutil%0Afrom contextlib import contextmanager%0A%0A%0A@contextmanager%0Adef make_tempdir():%0A    d = Path(tempfile.mkdtemp())%0A    yield d%0A    shutil.rmtree(str(d))%0A%0A%0A%0Adef clone_repo(repo, temp_dir):%0A    subprocess.check_call(%5B%0A        %22git%22,%0A        %22clone%22,%0A        repo,%0A        temp_dir,%0A        %22--no-checkout%22,%0A        %22--depth%22, %221%22,%0A        %22--config%22, %22core.sparseCheckout=true%22%0A    %5D)%0A%0A%0Adef checkout_and_fetch(temp_dir):%0A    subprocess.check_call(%5B%0A        %22git%22,%0A        %22-C%22, temp_dir,%0A        %22fetch%22%0A    %5D)%0A    subprocess.check_call(%5B%0A        %22git%22,%0A        %22-C%22, temp_dir,%0A        %22checkout%22%0A    %5D)%0A%0A%0Adef set_sparse_checkout_dir(temp_dir, subpath):%0A    with (temp_dir / %22.git%22 / %22info%22 / %22sparse-checkout%22).open(%22w%22) as file_:%0A        file_.write(subpath)%0A%0A%0Adef main(repo: str, subpath: str, dest: Path):%0A    with make_tempdir() as temp_dir:%0A        clone_repo(repo, temp_dir)%0A        print(%22After clone%22, list(temp_dir.iterdir()))%0A        set_sparse_checkout_dir(temp_dir, subpath)%0A        checkout_and_fetch(temp_dir)%0A        print(%22After checkout%22, list(temp_dir.iterdir()))%0A        assert (temp_dir / subpath) in list(temp_dir.iterdir())%0A        shutil.copytree(temp_dir / subpath, dest / subpath, dirs_exist_ok=True)%0A    print(%22Exists after cleanup?%22, temp_dir.exists())%0A    print(%22Destination%22, list(dest.iterdir()))%0A%0A%0Aif __name__ == %22__main__%22:%0A    typer.run(main)%0A

Add example of how to do sparse-checkout