]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/bin/git-update-and-verify-submodule
shell: git-update-and-verify-submodule: convert to python3
[config/dotfiles.git] / shell / bin / git-update-and-verify-submodule
1 #!/usr/bin/python3
2
3 # Copyright (C) 2018-2019  Simon Ruderich
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 import os
20 import subprocess
21 import sys
22
23
24 sha1 = sys.argv[1]
25
26 repo_path = os.environ['OLDPWD']
27 submodule_path = os.getcwd()
28 submodule = os.path.relpath(submodule_path, repo_path)
29
30 evtag = subprocess.check_output(['git-evtag-compute-py', sha1]) \
31         .decode('ascii') \
32         .split('\n')
33 assert evtag[0].startswith('# git-evtag comment: ')
34 assert evtag[1].startswith('Git-EVTag-v0-SHA512: ')
35
36 os.chdir(repo_path)
37
38 log = subprocess.check_output(['git', 'log', '-1', '--', submodule]) \
39         .decode('ascii')
40
41 found_comment = False
42 found_evtag = False
43 for line in log.split('\n'):
44     if evtag[0] in line:
45         found_comment = True
46     elif evtag[1] in line:
47         found_evtag = True
48
49 if not found_comment or not found_evtag:
50     print('missing or invalid evtag, aborting')
51     sys.exit(1)
52
53 subprocess.check_call(['git', 'submodule', 'update', '--checkout', '--',
54     submodule])