From a5e2f1e3b5c23fe8cf98309aba17c34b8e94ef2f Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Fri, 4 Nov 2016 11:09:29 -0400 Subject: [PATCH] layerindex/tools/import_project.py: Detect remote name & branch Don't assume remote name is origin, run `git remote` to get the remote name. When checking the remote, detect the branch as well, that way the layerindex will work if the remote branch name and local branch name do not match. Note that this currently only supports one remote. Signed-off-by: Liam R. Howlett Signed-off-by: Mark Hatle --- layerindex/tools/import_project.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/layerindex/tools/import_project.py b/layerindex/tools/import_project.py index 511282d..11c1f25 100755 --- a/layerindex/tools/import_project.py +++ b/layerindex/tools/import_project.py @@ -10,7 +10,6 @@ # # Licensed under the MIT license, see COPYING.MIT for details -from git import Repo from urllib.parse import urlparse import logging import optparse @@ -82,12 +81,10 @@ class ImportProject: self.logger.error("Cannot get root dir for layer %s: %s - Skipping." % (layer, str(e))) return 1 - repo = Repo(git_dir) - actual_branch = repo.active_branch.name - layer_name = layer.split('/')[-2] + layer_subdir = None if os.path.basename(git_dir) != layer_name: layer_subdir = layer_name @@ -95,18 +92,30 @@ class ImportProject: layer_name = self.get_layer_name(layer) for i in [1, 2, 3]: + remote = utils.runcmd("git remote", destdir=git_dir, logger=self.logger) + if not remote: + self.logger.warning("Cannot find remote git for %s" % layer_name) + return 1 + try: - git_url = utils.runcmd("git config --get remote.origin.url", destdir=git_dir, logger=self.logger) + git_url = utils.runcmd("git config --get remote.%s.url" % remote, destdir=git_dir, logger=self.logger) except Exception as e: - self.logger.info("Cannot get remote.origin.url for git dir %s: %s" % (git_dir, str(e))) + self.logger.info("Cannot get remote.%s.url for git dir %s: %s" % (remote, git_dir, str(e))) if not os.path.exists(git_url): # Assume this is remote. self.logger.debug("Found git url = %s" % git_url) - break; + remote_branch = utils.runcmd( "git rev-parse --abbrev-ref --symbolic-full-name @\{u\}", destdir=git_dir, logger=self.logger) + if remote_branch.startswith(remote): + actual_branch = remote_branch[len(remote) + 1:] + break self.logger.debug("Iterating to find git url into %s" % git_dir) git_dir = git_url + if not git_url: + self.logger.warning("Cannot find layer %s git url" % layer) + return 1 + cmd = ['import_layer.py'] if self.options.loglevel == logging.DEBUG: cmd.append("-d")