diff options
author | Mark Asselstine <mark.asselstine@windriver.com> | 2022-10-09 19:26:24 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-10-29 16:30:43 +0100 |
commit | 78fd269e6649000b48ef1ef3e86009bad00fa815 (patch) | |
tree | 37c7d135a2958a02c0b4368d03de74d4da988f32 /bitbake | |
parent | 6ca9f04b8e2cf1475ead09e55ac6282cab3ee9e7 (diff) | |
download | poky-78fd269e6649000b48ef1ef3e86009bad00fa815.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: d2cb388f58a37db2149fad34e4572d954e6e5441)
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>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bblayers/layerindex.py | 25 |
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: |