From patchwork Wed Jul 10 01:24:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Sangorrin X-Patchwork-Id: 11037693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9171A14DB for ; Wed, 10 Jul 2019 01:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85372288E5 for ; Wed, 10 Jul 2019 01:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79A9D28900; Wed, 10 Jul 2019 01:34:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1F0B7288E5 for ; Wed, 10 Jul 2019 01:34:51 +0000 (UTC) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 30DE940BF; Wed, 10 Jul 2019 01:34:42 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id A54673645 for ; Wed, 10 Jul 2019 01:25:08 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mo-csw.securemx.jp (mo-csw1115.securemx.jp [210.130.202.157]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id EFF57CF for ; Wed, 10 Jul 2019 01:25:07 +0000 (UTC) Received: by mo-csw.securemx.jp (mx-mo-csw1115) id x6A1OvpT002130; Wed, 10 Jul 2019 10:24:57 +0900 X-Iguazu-Qid: 2wGr73g3jC1l4JAxhA X-Iguazu-QSIG: v=2; s=0; t=1562721897; q=2wGr73g3jC1l4JAxhA; m=sI24+3LAO1rxUnGOYU1GolPWW/2YTY6Pp/+Db7SElHk= Received: from imx2.toshiba.co.jp (imx2.toshiba.co.jp [106.186.93.51]) by relay.securemx.jp (mx-mr1111) id x6A1Ot5u020241; Wed, 10 Jul 2019 10:24:56 +0900 Received: from enc01.localdomain ([106.186.93.100]) by imx2.toshiba.co.jp with ESMTP id x6A1OtZe019812; Wed, 10 Jul 2019 10:24:55 +0900 (JST) Received: from hop001.toshiba.co.jp ([133.199.164.63]) by enc01.localdomain with ESMTP id x6A1OtTi025473; Wed, 10 Jul 2019 10:24:55 +0900 From: Daniel Sangorrin To: ben.hutchings@codethink.co.uk Date: Wed, 10 Jul 2019 10:24:45 +0900 X-TSB-HOP: ON Message-Id: <20190710012450.16524-2-daniel.sangorrin@toshiba.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190710012450.16524-1-daniel.sangorrin@toshiba.co.jp> References: <20190710012450.16524-1-daniel.sangorrin@toshiba.co.jp> Cc: cip-dev@lists.cip-project.org Subject: [cip-dev] [cip-kernel-sec][RESEND 1/6] check_git_repo: add checks to the local repository X-BeenThere: cip-dev@lists.cip-project.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cip-dev-bounces@lists.cip-project.org Errors-To: cip-dev-bounces@lists.cip-project.org X-Virus-Scanned: ClamAV using ClamSMTP Add checks to make sure that the local repository exists and has the configured remotes in place. Signed-off-by: Daniel Sangorrin --- scripts/import_stable.py | 1 + scripts/kernel_sec/branch.py | 21 +++++++++++++++++++++ scripts/report_affected.py | 1 + scripts/webview.py | 1 + 4 files changed, 24 insertions(+) diff --git a/scripts/import_stable.py b/scripts/import_stable.py index 2c88b07..26fcc2f 100755 --- a/scripts/import_stable.py +++ b/scripts/import_stable.py @@ -190,4 +190,5 @@ if __name__ == '__main__': remotes = kernel_sec.branch.get_remotes(args.remote_name, mainline=args.mainline_remote_name, stable=args.stable_remote_name) + kernel_sec.branch.check_git_repo(args.git_repo, remotes) main(args.git_repo, remotes, args.debug) diff --git a/scripts/kernel_sec/branch.py b/scripts/kernel_sec/branch.py index 10f3339..a138b96 100644 --- a/scripts/kernel_sec/branch.py +++ b/scripts/kernel_sec/branch.py @@ -4,10 +4,12 @@ # Public License, Version 3 or later. See http://www.gnu.org/copyleft/gpl.html # for details. +import argparse import io import os import re import subprocess +import sys import time import urllib.error import urllib.request @@ -219,3 +221,22 @@ def get_remotes(mappings, mainline=None, stable=None): if stable: remotes['stable']['git_name'] = stable return remotes + + +def check_git_repo(git_repo, remotes): + if not os.path.isdir(git_repo): + msg = "directory %r not present" % git_repo + raise argparse.ArgumentError(None, msg) + # .git could be a regular file (worktrees) or a directory + if not os.path.exists(os.path.join(git_repo, '.git')): + msg = "directory %r is not a git repository" % git_repo + raise argparse.ArgumentError(None, msg) + + current_remotes = subprocess.check_output( + ['git', 'remote', 'show'], cwd=git_repo).decode( + sys.stdout.encoding).strip().split('\n') + for key in remotes.keys(): + remote = remotes[key] # __getitem__ will add git_name + if remote['git_name'] not in current_remotes: + msg = "remote %r not in git repository" % remote['git_name'] + raise argparse.ArgumentError(None, msg) diff --git a/scripts/report_affected.py b/scripts/report_affected.py index 879c021..d2f1f22 100755 --- a/scripts/report_affected.py +++ b/scripts/report_affected.py @@ -100,5 +100,6 @@ if __name__ == '__main__': remotes = kernel_sec.branch.get_remotes(args.remote_name, mainline=args.mainline_remote_name, stable=args.stable_remote_name) + kernel_sec.branch.check_git_repo(args.git_repo, remotes) main(args.git_repo, remotes, args.only_fixed_upstream, args.include_ignored, *args.branches) diff --git a/scripts/webview.py b/scripts/webview.py index a3a643b..52a7b15 100755 --- a/scripts/webview.py +++ b/scripts/webview.py @@ -219,6 +219,7 @@ if __name__ == '__main__': remotes = kernel_sec.branch.get_remotes(args.remote_name, mainline=args.mainline_remote_name, stable=args.stable_remote_name) + kernel_sec.branch.check_git_repo(args.git_repo, remotes) conf = { '/static/style.css': {