Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Options:
-g, --graphmode TEXT GraphMode: scattered | clustered [default: scattered]
-o, --out TEXT Image filename [default: graph]
-u, --with-url Add repo URLs [default: False]
-r, --relative-path Show relative path [default: False]
--help Show this message and exit.
```

Expand All @@ -28,6 +29,9 @@ $ submodulegraph <path to repo>
# Print the structure of the submodules in text in the console, including repo URLs.
$ submodulegraph -u <path to repo>

# Print the structure of the submodules in text in the console, including repo URLs and relative paths of submodule directories.
$ submodulegraph -u -r <path to repo>

# Create a png of the submodule structure where all the submodules are listed separately.
$ submodulegraph -m png <path to repo>

Expand Down
26 changes: 18 additions & 8 deletions submodulegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,23 @@ def parseGitModuleFile(file):
res.append((p, u))
return res

def parse(path, url=None):
def parse(path, relpath=None, url=None):
if relpath:
name = os.path.normpath(os.path.relpath(path, start=relpath))
else:
name = os.path.basename(os.path.normpath(path))

if os.path.isfile(os.path.join(path, '.gitmodules')) is False:
return Tree({'name': os.path.basename(os.path.normpath(path)),
'path': path, 'url': url})
return Tree({'name': name, 'path': path, 'url': url})

tree = Tree({'name': os.path.basename(os.path.normpath(path)),
'path': path, 'url': url})
tree = Tree({'name': name, 'path': path, 'url': url})
moduleFile = os.path.join(path, '.gitmodules')

if os.path.isfile(moduleFile) is True:
subs = parseGitModuleFile(moduleFile)
for p, u in subs:
newPath = os.path.join(path, p)
newTree = parse(newPath, u)
newTree = parse(newPath, relpath=relpath, url=u)
tree.createChild(newTree)
return tree

Expand All @@ -102,10 +105,17 @@ def parse(path, url=None):
default=False, is_flag=True,
show_default=True,
help="Add repo URLs")
@click.option('-r', '--relative-path',
default=False, is_flag=True,
show_default=True,
help="Show relative path")
@click.argument('repo')
def main(mode, repo, graphmode, out, with_url):
def main(mode, repo, graphmode, out, with_url, relative_path):
root = repo
tree = parse(root)
if relative_path:
tree = parse(root, relpath=root)
else:
tree = parse(root)

if mode == 'text':
tree.print(with_url=with_url)
Expand Down