@@ -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:
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(-)