|
12 | 12 | from .shell import call, pwd |
13 | 13 |
|
14 | 14 |
|
| 15 | +def sanitize_sparse_paths(sparse_paths): |
| 16 | + """Strip trailing glob patterns for cone mode (e.g. 'src/*' -> 'src').""" |
| 17 | + return [p.rstrip("/*") if p.endswith("/*") else p for p in sparse_paths] |
| 18 | + |
| 19 | + |
15 | 20 | def git(*args, **kwargs): |
16 | 21 | return call("git", *args, **kwargs) |
17 | 22 |
|
@@ -69,7 +74,13 @@ def clone( |
69 | 74 | fd.write("%s/objects" % sparse_paths_repo) |
70 | 75 |
|
71 | 76 | git("-C", normpath, "sparse-checkout", "init", "--cone") |
72 | | - git("-C", normpath, "sparse-checkout", "set", *sparse_paths) |
| 77 | + git( |
| 78 | + "-C", |
| 79 | + normpath, |
| 80 | + "sparse-checkout", |
| 81 | + "set", |
| 82 | + *sanitize_sparse_paths(sparse_paths) |
| 83 | + ) |
73 | 84 | git("-C", normpath, "fetch", "origin") |
74 | 85 | git("-C", normpath, "checkout", rev) |
75 | 86 | elif settings.CACHE_DISABLE: |
@@ -245,6 +256,11 @@ def am(patch, _skip=False): |
245 | 256 | raise ShellError from e |
246 | 257 |
|
247 | 258 |
|
| 259 | +def apply_sparse_checkout(sparse_paths): |
| 260 | + """Re-apply sparse-checkout paths to an existing working tree.""" |
| 261 | + git("sparse-checkout", "set", *sanitize_sparse_paths(sparse_paths)) |
| 262 | + |
| 263 | + |
248 | 264 | def update( |
249 | 265 | type, repo, path, *, clean=True, fetch=False, rev=None |
250 | 266 | ): # pylint: disable=redefined-outer-name,unused-argument |
|
0 commit comments