|
12 | 12 |
|
13 | 13 | from dfetch.log import get_logger |
14 | 14 | from dfetch.util.cmdline import SubprocessCommandError, run_on_cmdline |
15 | | -from dfetch.util.util import in_directory, safe_rm, strip_glob_prefix |
| 15 | +from dfetch.util.util import in_directory, is_license_file, safe_rm, strip_glob_prefix |
16 | 16 | from dfetch.vcs.patch import Patch, PatchType |
17 | 17 |
|
18 | 18 | logger = get_logger(__name__) |
@@ -263,10 +263,7 @@ def _configure_sparse_checkout( |
263 | 263 |
|
264 | 264 | with open(".git/info/sparse-checkout", "a", encoding="utf-8") as f: |
265 | 265 | patterns = list(keeps or []) |
266 | | - src_pattern = f"/{src or '*'}" |
267 | | - |
268 | | - if src_pattern not in patterns: |
269 | | - patterns.append(src_pattern) |
| 266 | + patterns.append(f"/{src or '*'}") |
270 | 267 |
|
271 | 268 | if ignore: |
272 | 269 | patterns += self._determine_ignore_paths(src, ignore) |
@@ -297,11 +294,7 @@ def checkout_version( # pylint: disable=too-many-arguments |
297 | 294 | run_on_cmdline(logger, ["git", "checkout", "-b", "dfetch-local-branch"]) |
298 | 295 |
|
299 | 296 | if src or ignore: |
300 | | - self._configure_sparse_checkout( |
301 | | - src, |
302 | | - (must_keeps or []) + [f"/{src or '*'}"], |
303 | | - ignore, |
304 | | - ) |
| 297 | + self._configure_sparse_checkout(src, must_keeps or [], ignore) |
305 | 298 |
|
306 | 299 | run_on_cmdline( |
307 | 300 | logger, |
@@ -342,7 +335,12 @@ def _apply_src_and_ignore( |
342 | 335 | self._move_src_folder_up(remote, src) |
343 | 336 |
|
344 | 337 | for ignore_path in ignore or []: |
345 | | - safe_rm(glob.glob(ignore_path)) |
| 338 | + paths = [ |
| 339 | + p |
| 340 | + for p in glob.glob(ignore_path) |
| 341 | + if not (os.path.isfile(p) and is_license_file(os.path.basename(p))) |
| 342 | + ] |
| 343 | + safe_rm(paths, within=".") |
346 | 344 |
|
347 | 345 | return [s for s in submodules if os.path.exists(s.path)] |
348 | 346 |
|
|
0 commit comments