git reattach

This commit is contained in:
Vladimir Mandic
2024-05-22 08:39:47 -04:00
parent ae95d3ec8d
commit 28ad605f29
2 changed files with 10 additions and 3 deletions
+9 -2
View File
@@ -286,15 +286,22 @@ def git(arg: str, folder: str = None, ignore: bool = False):
log.debug(f'Git output: {txt}')
return txt
# switch to main branch as head can get detached
# reattach as needed as head can get detached
def branch(folder=None):
# if args.experimental:
# return None
if not os.path.exists(os.path.join(folder or os.curdir, '.git')):
return None
b = ''
branches = []
try:
b = git('branch --show-current', folder)
if b == '':
branches = git('branch', folder).split('\n')
if len(branches) > 0:
b = [x for x in branches if x.startswith('*')][0]
if 'detached' in b and len(branches) > 1:
b = branches[1].strip()
log.debug(f'Git detached head detected: folder={folder} reattach={b}')
except Exception:
b = git('git rev-parse --abbrev-ref HEAD', folder)
if 'main' in b:
+1 -1
Submodule wiki updated: fef11cc6fe...f17d12033e