diff options
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: |
