print_submodule_info.py 556 Bytes
Newer Older
gaoqiong's avatar
gaoqiong committed
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
#!/usr/bin/env python3

# args: <submodule path>
# output: <path> <url> <commit>

import subprocess
import sys

assert len(sys.argv) == 2

path = sys.argv[1]

proc = subprocess.run(
    ["git", "config", "--get", "remote.origin.url"],
    check=True,
    cwd=path,
    stdout=subprocess.PIPE,
    universal_newlines=True,
)

url = proc.stdout.strip()

proc = subprocess.run(
    ["git", "rev-parse", "HEAD"], check=True, cwd=path, stdout=subprocess.PIPE, universal_newlines=True
)

commit = proc.stdout.strip()

print("{} {} {}".format(path, url, commit))