summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorMark Asselstine <mark.asselstine@windriver.com>2022-11-09 04:29:36 -1000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-10 14:43:30 +0000
commit79434a17eb4835e85fcd477baec08c8ce49a4c14 (patch)
treea71a3c863c72355148a762244d310faa6f31c56c /bitbake
parent25f355e0ef2fa98699cc62587a8f265258c09fda (diff)
downloadpoky-79434a17eb4835e85fcd477baec08c8ce49a4c14.tar.gz
bitbake: bitbake: bitbake-layers: checkout layer(s) branch when clone exists
[YOCTO #7852] Fixes 'bitbake-layers layerindex-fetch --branch kirkstone meta-arm' not checking out the branch if the repo is already cloned and on a different branch. If a clone of a layer being added already exists check what branch it is on and if necessary attempt to switch to the given branch. If the switch fails to happen the git error will be reported. We also warn if there are uncommitted changes as the changes might go unnoticed and result in unexpected behaviors. (Bitbake rev: 138dd7883ee2c521900b29985b6d24a23d96563c) Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit d2cb388f58a37db2149fad34e4572d954e6e5441) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bblayers/layerindex.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/bitbake/lib/bblayers/layerindex.py b/bitbake/lib/bblayers/layerindex.py
index 0ac8fd2ec7..ba91fac669 100644
--- a/bitbake/lib/bblayers/layerindex.py
+++ b/bitbake/lib/bblayers/layerindex.py
@@ -49,6 +49,31 @@ class LayerIndexPlugin(ActionPlugin):
49 else: 49 else:
50 logger.plain("Repository %s needs to be fetched" % url) 50 logger.plain("Repository %s needs to be fetched" % url)
51 return subdir, layername, layerdir 51 return subdir, layername, layerdir
52 elif os.path.exists(repodir) and branch:
53 """
54 If the repo is already cloned, ensure it is on the correct branch,
55 switching branches if necessary and possible.
56 """
57 base_cmd = ['git', '--git-dir=%s/.git' % repodir, '--work-tree=%s' % repodir]
58 cmd = base_cmd + ['branch']
59 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
60 if completed_proc.returncode:
61 logger.error("Unable to validate repo %s (%s)" % (repodir, stderr))
62 return None, None, None
63 else:
64 if branch != completed_proc.stdout[2:-1]:
65 cmd = base_cmd + ['status', '--short']
66 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
67 if completed_proc.stdout.count('\n') != 0:
68 logger.warning("There are uncommitted changes in repo %s" % repodir)
69 cmd = base_cmd + ['checkout', branch]
70 completed_proc = subprocess.run(cmd, text=True, capture_output=True)
71 if completed_proc.returncode:
72 # Could be due to original shallow clone on a different branch for example
73 logger.error("Unable to automatically switch %s to desired branch '%s' (%s)"
74 % (repodir, branch, completed_proc.stderr))
75 return None, None, None
76 return subdir, layername, layerdir
52 elif os.path.exists(layerdir): 77 elif os.path.exists(layerdir):
53 return subdir, layername, layerdir 78 return subdir, layername, layerdir
54 else: 79 else: