bitbake-layers: layerindex-fetch: Fix branch detection method
PATCH v2 2/4 bitbake-layers: layerindex-fetch: Fix branch detection method
Replace fragile parsing of 'git branch' output with the more reliable 'git name-rev --name-only HEAD' command to get the current branch name. This avoids parsing issues and is the recommended way to get the current branch name.
Signed-off-by Osama Abdelkader <[email protected]>
---
v2: change current branch detection to name-rev --name-only
--- lib/bblayers/layerindex.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/bblayers/layerindex.py +4 -2
@@ -55,13 +55,15 @@ class LayerIndexPlugin(ActionPlugin): switching branches if necessary and possible. """ base_cmd = ['git', '--git-dir=%s/.git' % repodir, '--work-tree=%s' % repodir] - cmd = base_cmd + ['branch'] + # Get current branch name + cmd = base_cmd + ['name-rev', '--name-only', 'HEAD'] completed_proc = subprocess.run(cmd, text=True, capture_output=True) if completed_proc.returncode: logger.error("Unable to validate repo %s (%s)" % (repodir, completed_proc.stderr)) return None, None, None else: - if branch != completed_proc.stdout[2:-1]: + current_branch = completed_proc.stdout.strip() + if branch != current_branch: cmd = base_cmd + ['status', '--short'] completed_proc = subprocess.run(cmd, text=True, capture_output=True) if completed_proc.stdout.count('\n') != 0:
Signature · 1 line
2.43.0