summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam R. Howlett <Liam.Howlett@WindRiver.com>2016-11-04 11:09:29 -0400
committerMark Hatle <mark.hatle@windriver.com>2016-11-21 15:27:42 -0600
commita5e2f1e3b5c23fe8cf98309aba17c34b8e94ef2f (patch)
treeb7280bfdb6c5ae87e3b82c718e23faceb5d741e8
parenta988b6ba085ca93832a16eb464d7992715e2edab (diff)
downloadopenembedded-core-contrib-a5e2f1e3b5c23fe8cf98309aba17c34b8e94ef2f.tar.gz
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>
-rwxr-xr-xlayerindex/tools/import_project.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/layerindex/tools/import_project.py b/layerindex/tools/import_project.py
index 511282d1ec..11c1f25c0b 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")