-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitdiffsub
More file actions
executable file
·96 lines (75 loc) · 2.78 KB
/
gitdiffsub
File metadata and controls
executable file
·96 lines (75 loc) · 2.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import re
def usage():
print('show git submodule modification')
print('usage:')
print(sys.argv[0] + ' <commit1> <commit2> <index of submoudle> # show diff between the two commits')
print(sys.argv[0] + ' <commit> <index of submoudle> # show diff between commit and HEAD')
if __name__ == '__main__':
if len(sys.argv) < 3:
usage()
sys.exit(0)
commit2 = ''
if len(sys.argv) == 3:
commit1 = sys.argv[1]
index = int(sys.argv[2])
if len(sys.argv) == 4:
commit1 = sys.argv[1]
commit2 = sys.argv[2]
index = int(sys.argv[3])
if commit2:
cmd = 'git diff %s %s > /tmp/git_diff_sub' % (commit1, commit2)
else:
cmd = 'git diff %s > /tmp/git_diff_sub' % (commit1)
r = os.system(cmd)
p = r'.*?a/(.*)\sb/(.*)'
subs = []
item = '' # submodule dir
commits = [] # submodule commit
if r == 0:
with open('/tmp/git_diff_sub') as f:
while True:
line = f.readline()
if not line:
break
line = line.strip()
if line.startswith('diff --git'):
m = re.match(p, line)
if m:
item = m.group(1)
commits = []
if line.startswith('-Subproject commit'):
if line.find('-dirty') >= 0:
line = line[:line.find('-dirty')]
commits.append(line.split()[2])
if line.startswith('+Subproject commit'):
if line.find('-dirty') >= 0:
line = line[:line.find('-dirty')]
commits.append(line.split()[2])
subs.append((item, commits))
print('%d submodules modified' % (len(subs)))
currdir = os.getcwd()
index -= 1
if commit2:
print('Showing %dst submodule [%s] difference of commit %s and %s' % (index + 1, subs[index][0], commit1, commit2))
else:
print('Showing %dst submodule [%s] difference of commit %s and HEAD' % (index + 1, subs[index][0], commit1))
# find git root dir
root = currdir
while True:
d = os.path.join(root, ".git")
if os.path.exists(d):
break
else:
root = os.path.join(root, '../')
os.chdir(os.path.join(root, subs[index][0]))
cmd = 'git diff --stat %s %s' % (subs[index][1][0], subs[index][1][1])
os.system(cmd)
print('Press ENTER to continue...')
raw_input()
cmd = 'git diff %s %s' % (subs[index][1][0], subs[index][1][1])
os.system(cmd)
os.chdir(currdir)