-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitsubmodulesparser2.py
More file actions
executable file
·47 lines (36 loc) · 1.5 KB
/
gitsubmodulesparser2.py
File metadata and controls
executable file
·47 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/env python3
import re
import sys
import os
import argparse
from configparser import ConfigParser
gitmodules=".gitmodules"
def convert_gitmodules(gitmodules_file=gitmodules, force=False):
"""Convert gitmodules file to git submodule add commands.
Args:
gitmodules_file (str): Path to the gitmodules file. Default is ".gitmodules".
force (bool): Whether to add the "--force" flag to the git command. Default is False.
Returns:
str: Converted git submodule add commands.
"""
config = ConfigParser(allow_no_value=True)
config.read(gitmodules_file)
result = []
for section in config.sections():
if config.has_option(section, 'url'):
submodule_path = config.get(section, 'path')
submodule_url = config.get(section, 'url', fallback=None)
# Construct the git command
git_command = "git submodule add"
if force:
git_command += " --force"
git_command += f" {submodule_url if submodule_url else ''} {submodule_path}"
result.append(git_command)
return "\n".join(result)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--force", action="store_true", help="Add --force flag to git command")
parser.add_argument("gitmodules_file", nargs="?", default=gitmodules, help="Path to the gitmodules file")
args = parser.parse_args()
output = convert_gitmodules(args.gitmodules_file, args.force)
print(output)