diff mbox series

[2/4] bitbake-layers: layerindex-fetch: Fix branch detection method

Message ID 20251212190806.32476-3-osama.abdelkader@gmail.com
State New
Headers show
Series bitbake-layers: layerindex-fetch: respect --branch for already-configured layers | expand

Commit Message

Osama Abdelkader Dec. 12, 2025, 7:08 p.m. UTC
Replace fragile parsing of 'git branch' output with the more reliable
'git rev-parse --abbrev-ref 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 <osama.abdelkader@gmail.com>
---
 lib/bblayers/layerindex.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/bblayers/layerindex.py b/lib/bblayers/layerindex.py
index 0ffc95822b..1c6511889d 100644
--- a/lib/bblayers/layerindex.py
+++ b/lib/bblayers/layerindex.py
@@ -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 + ['rev-parse', '--abbrev-ref', '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: