]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - shell/bin/git-update-and-verify-submodule
Check evtags for submodules
[config/dotfiles.git] / shell / bin / git-update-and-verify-submodule
diff --git a/shell/bin/git-update-and-verify-submodule b/shell/bin/git-update-and-verify-submodule
new file mode 100755 (executable)
index 0000000..c4ba1f6
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+# Copyright (C) 2018  Simon Ruderich
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+import os
+import subprocess
+import sys
+
+
+sha1 = sys.argv[1]
+
+repo_path = os.environ['OLDPWD']
+submodule_path = os.getcwd()
+submodule = os.path.relpath(submodule_path, repo_path)
+
+evtag = subprocess.check_output(['git-evtag-compute-py', sha1]).split('\n')
+assert evtag[0].startswith('# git-evtag comment: ')
+assert evtag[1].startswith('Git-EVTag-v0-SHA512: ')
+
+os.chdir(repo_path)
+
+log = subprocess.check_output(['git', 'log', '-1', '--', submodule])
+
+found_comment = False
+found_evtag = False
+for line in log.split('\n'):
+    if evtag[0] in line:
+        found_comment = True
+    elif evtag[1] in line:
+        found_evtag = True
+
+if not found_comment or not found_evtag:
+    print('missing or invalid evtag, aborting')
+    sys.exit(1)
+
+subprocess.check_call(['git', 'submodule', 'update', '--checkout', '--',
+    submodule])