Re: [cip-kernel-sec][PATCH v2 3/3] remotes: check that remotes exist

Ben Hutchings <ben.hutchings@...>

On Thu, 2019-06-20 at 14:51 +0900, Daniel Sangorrin wrote:
--- a/scripts/kernel_sec/
+++ b/scripts/kernel_sec/
+def check_git_repo(git_repo, remotes, create=False):
+    if create:
+        if os.path.isdir(git_repo):
+            msg = "directory %r already exists" % git_repo
+            raise argparse.ArgumentTypeError(msg)
+        else:
+            os.mkdir(git_repo)
+            subprocess.check_call(['git', 'init', '.'], cwd=git_repo)
+        for key in remotes.keys():
+            remote = remotes[key]  # __getitem__ will add git_name
+            remote_add(git_repo, remote['git_name'], remote['git_repo_url'])
+    else:
+        if not os.path.isdir(git_repo):
+            msg = "directory %r not present" % git_repo
+            raise argparse.ArgumentTypeError(msg)
+        if not os.path.isdir(os.path.join(git_repo, '.git')):
+            msg = "directory %r is not a git repository" % git_repo
+            raise argparse.ArgumentTypeError(msg)
This isn't compatible with the use of git worktrees (which I use). In
a worktree, .git is a regular file that refers back to the repository.

So I think this check should use exists() instead of isdir().

Also, why does this function raise argparse.ArgumentTypeError? The
doc-string for that type says it's "An error from trying to convert a
command line string to a type." It doesn't seem to be suitable for
reporting problems with the thing that an argument refers to.

--- /dev/null
+++ b/scripts/
@@ -0,0 +1,46 @@
+# Copyright 2019 Toshiba corp.
+# Based on by Codethink Ltd.
+# This script is distributed under the terms and conditions of the GNU General
+# Public License, Version 3 or later. See
+# for details.
+# Helper script that prepares the local git repository with the configured
+# remote branches

Perhaps should also run "git remote update"?
Without that, the repository is still not actually useful.


Ben Hutchings, Software Developer   Codethink Ltd Dale House, 35 Dale Street
Manchester, M1 2HF, United Kingdom

Join { to automatically receive all group messages.