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 <Liam.Howlett@WindRiver.com>
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
This commit is contained in:
Liam R. Howlett 2016-11-04 11:09:29 -04:00 committed by Mark Hatle
parent a988b6ba08
commit a5e2f1e3b5

View File

@ -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")