Skip to content
This repository was archived by the owner on Nov 1, 2025. It is now read-only.

Commit bdd947c

Browse files
committed
refactor(source): refactor strip git dotfiles logic
Signed-off-by: bachnxuan <bachnxuan@gmail.com>
1 parent 1206d10 commit bdd947c

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

kernel_builder/utils/source.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from shutil import rmtree
23
from dataclasses import dataclass, field
34
from pathlib import Path
45
from re import Pattern
@@ -46,6 +47,20 @@ def restore_simplified(simplified: str) -> str:
4647
url = urlunparse(("https", host, "/" + repo, "", "", ""))
4748
return url
4849

50+
def _strip_git_dotfiles(self, parent: Path) -> None:
51+
SAFE_GIT_DOTFILES = [
52+
parent / ".git",
53+
parent / ".github",
54+
]
55+
56+
for path in SAFE_GIT_DOTFILES:
57+
if not path.exists():
58+
continue
59+
elif path.is_dir():
60+
rmtree(path)
61+
else:
62+
path.unlink(missing_ok=True)
63+
4964
def clone_repo(
5065
self, repo: dict[str, str], *, depth: int = 1, args: list[str] | None = None
5166
) -> None:
@@ -68,7 +83,8 @@ def clone_repo(
6883
self.restore_simplified(repo["url"]),
6984
repo["to"],
7085
)
71-
(Path(repo["to"]) / ".git").unlink(missing_ok=True)
86+
# Strip git dotfiles
87+
self._strip_git_dotfiles(Path(repo["to"]))
7288

7389
def clone_sources(self) -> None:
7490
"""

0 commit comments

Comments
 (0)