Browse Source

Update updategit script.

5.3.8
Chris Smith 7 years ago
parent
commit
04625b7396
1 changed files with 17 additions and 4 deletions
  1. 17
    4
      .updater/updategit.py

+ 17
- 4
.updater/updategit.py View File

2
 
2
 
3
 import fileinput
3
 import fileinput
4
 import re
4
 import re
5
+import subprocess
6
+import sys
5
 from os import close, remove, path
7
 from os import close, remove, path
6
 from shutil import move
8
 from shutil import move
7
-from subprocess import call
8
 from tempfile import mkstemp
9
 from tempfile import mkstemp
9
 
10
 
10
 assert path.isdir('.git'), "No git dir found"
11
 assert path.isdir('.git'), "No git dir found"
11
 
12
 
13
+
12
 def replace(file_path, pattern, subst):
14
 def replace(file_path, pattern, subst):
13
     # From http://stackoverflow.com/a/39110
15
     # From http://stackoverflow.com/a/39110
14
     fh, abs_path = mkstemp()
16
     fh, abs_path = mkstemp()
20
     remove(file_path)
22
     remove(file_path)
21
     move(abs_path, file_path)
23
     move(abs_path, file_path)
22
 
24
 
25
+
26
+def call(args):
27
+    print('>>> %s' % ' '.join(args))
28
+    return subprocess.call(args)
29
+
23
 call(['git', 'fetch'])
30
 call(['git', 'fetch'])
24
 
31
 
32
+updated = False
25
 for line in fileinput.input():
33
 for line in fileinput.input():
26
     branch, version, changelog, url = line.strip().split(' ')
34
     branch, version, changelog, url = line.strip().split(' ')
27
     branch = 'master' if branch == 'latest' else branch
35
     branch = 'master' if branch == 'latest' else branch
28
     call(['git', 'branch', branch, 'master']) # Will fail if the branch exists
36
     call(['git', 'branch', branch, 'master']) # Will fail if the branch exists
29
     call(['git', 'checkout', branch])
37
     call(['git', 'checkout', branch])
30
-    call(['git', 'rebase', 'origin/%s' % branch]) # May fail as well
38
+    call(['git', 'reset', '--hard', 'origin/%s' % branch]) # May fail as well
31
     replace('Dockerfile', r'^ARG url=.*', 'ARG url=%s' % url)
39
     replace('Dockerfile', r'^ARG url=.*', 'ARG url=%s' % url)
32
-    call(['git', 'commit', '-am', 'Auto update to version %s.\n\nChangelog: %s' % (version, changelog)])
33
-    call(['git', 'push', 'origin', branch])
40
+    c = call(['git', 'commit', '-am', 'Auto update to version %s.\n\nChangelog: %s' % (version, changelog)])
41
+    if c == 0:
42
+      call(['git', 'push', 'origin', branch])
43
+      updated = True
34
 
44
 
35
 call(['git', 'checkout', 'master'])
45
 call(['git', 'checkout', 'master'])
46
+
47
+sys.exit(0 if updated else 1)
48
+

Loading…
Cancel
Save