Skip to content

Commit c1b4c29

Browse files
committed
Tranquillity
The Way takes no action, but leaves nothing undone. When you accept this The world will flourish, In harmony with nature. Nature does not possess desire; Without desire, the heart becomes quiet; In this manner the whole world is made tranquil. -- Lao Tse, "Tao Te Ching"
1 parent 62d01ab commit c1b4c29

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

example-gitmodules

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@
2323
url = https://github.com/zdharma-continuum/fast-syntax-highlighting
2424
shallow = true
2525
ignore = dirty
26-
27-

gitsubmodulesparser.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@
55
from typing import List, Tuple
66

77

8-
def convert_and_validate_gitmodules_file(gitmodules_path: str = ".gitmodules") -> List[Tuple[str, str, str, str, str]]:
8+
def convert_and_validate_gitmodules_file(gitmodules_path: str = ".gitmodules") -> List[Tuple[str, str, str]]:
99
if not os.path.exists(gitmodules_path):
1010
raise FileNotFoundError(
1111
f"Gitmodules file '{gitmodules_path}' not found.")
1212

1313
with open(gitmodules_path, "r") as file:
14-
gitmodules_content = file.read()
14+
content = file.read()
1515

16-
submodule_pattern = (
17-
r'\n\s*\[submodule\s+"([^"]+)"\]\n\s+path\s+=\s+([^ ]+)\n\s+url\s+=\s+([^ ]+)\n\s+shallow\s+=\s+([^ ]+)\n\s+ignore\s+=\s+([^ ]+)\n'
18-
)
19-
matches = re.findall(submodule_pattern, gitmodules_content)
20-
submodules = []
21-
for match in matches:
22-
submodule_name, submodule_path, submodule_url, submodule_shallow, submodule_ignore = match
23-
submodules.append((submodule_name, submodule_path,
24-
submodule_url, submodule_shallow, submodule_ignore))
25-
return submodules
16+
pattern = r'\[submodule "([^"]+)"\]\s*path = ([^\n]+)\s*url = ([^\n]+)'
17+
matches = re.findall(pattern, content)
18+
19+
return matches # This will be a list of tuples
2620

2721

2822
def main() -> None:
@@ -36,7 +30,7 @@ def main() -> None:
3630
gitmodules_file = args.gitmodules_file
3731
modules = convert_and_validate_gitmodules_file(gitmodules_file)
3832

39-
for name, path, url, shallow, ignore in modules:
33+
for name, path, url in modules:
4034
git_command = f"git submodule add {'--force ' if args.force else ''}{url} {path}"
4135
print(git_command)
4236

0 commit comments

Comments
 (0)