]> git.wh0rd.org Git - home.git/commitdiff
cros-repo: minor improvements
authorMike Frysinger <vapier@gentoo.org>
Tue, 10 Nov 2020 08:29:51 +0000 (03:29 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 10 Nov 2020 08:29:51 +0000 (03:29 -0500)
.bin/cros-repo

index 474b1aa38e73696590e8d71d0391e8294d513b19..567347f30152b29aa6453aabb826f2868cb26c83 100755 (executable)
@@ -45,7 +45,10 @@ def expand_branch(opts):
     branches = [x.split()[-1].split('/')[-1] for x in ret.stdout.splitlines()]
     ret = []
     for branch in branches:
-        if fnmatch.fnmatch(branch.lower(), f'*{opts.branch.lower()}*'):
+        if branch.lower() == opts.branch.lower():
+            ret = [branch]
+            break
+        elif fnmatch.fnmatch(branch.lower(), f'*{opts.branch.lower()}*'):
             ret.append(branch)
     if not ret:
         print(f'error: could not match branch {opts.branch}', file=sys.stderr)
@@ -59,8 +62,8 @@ def expand_branch(opts):
     return ret[0]
 
 
-def set_git_config(opts):
-    """Set .git/config settings in all the repos."""
+def get_repo_topdir(opts):
+    """Find the top dir of this repo client checkout."""
     topdir = os.getcwd()
     while True:
         rdir = os.path.join(topdir, '.repo')
@@ -68,6 +71,13 @@ def set_git_config(opts):
             break
         topdir = os.path.dirname(topdir)
         assert topdir != '/'
+    return topdir
+
+
+def set_git_config(opts):
+    """Set .git/config settings in all the repos."""
+    topdir = get_repo_topdir(opts)
+    rdir = os.path.join(topdir, '.repo')
 
     def gcfg(path, *args):
         cmd = ['git', f'--git-dir={path}', 'config', 'user.email'] + list(args)
@@ -96,7 +106,7 @@ def init_repo(opts):
         cmd += ['-u', EXT_MANIFEST]
         cmd += ['--repo-url', REPO_URL]
 
-    if opts.ref:
+    if opts.ref and os.path.realpath(opts.ref) != os.path.realpath(get_repo_topdir(opts)):
         cmd += ['--reference', opts.ref]
 
     if opts.manifest: