From 9597ccf8f856ec1d3a80486d0b1591d5a8ab8a67 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 11 May 2020 16:52:35 -0400 Subject: Deal with cases when [branch] is not specified Not all local branches are going to have matching [branch] entries -- sometimes there is only a [remote]. Deal with both cases. Signed-off-by: Konstantin Ryabitsev --- b4/ty.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/b4/ty.py b/b4/ty.py index a2f3d5f..02898b0 100644 --- a/b4/ty.py +++ b/b4/ty.py @@ -589,15 +589,33 @@ def get_branch_info(gitdir, branch): remotecfg = b4.get_config_from_git('branch\\.%s\\.*' % branch) if remotecfg is None or 'remote' not in remotecfg: - # Not found any matching remotes - return BRANCH_INFO + # Did not find a matching branch entry, so look at remotes + gitargs = ['remote', 'show'] + lines = b4.git_get_command_lines(gitdir, gitargs) + if not len(lines): + # No remotes? Hmm... + return BRANCH_INFO + + remote = None + for entry in lines: + if branch.find(f'{entry}/') == 0: + remote = entry + break - BRANCH_INFO['remote'] = remotecfg['remote'] - if 'merge' in remotecfg: - BRANCH_INFO['branch'] = re.sub(r'^refs/heads/', '', remotecfg['merge']) + if remote is None: + # Not found any matching remotes + return BRANCH_INFO + + BRANCH_INFO['remote'] = remote + BRANCH_INFO['branch'] = branch.replace(f'{remote}/', '') + + else: + BRANCH_INFO['remote'] = remotecfg['remote'] + if 'merge' in remotecfg: + BRANCH_INFO['branch'] = re.sub(r'^refs/heads/', '', remotecfg['merge']) # Grab template overrides - remotecfg = b4.get_config_from_git('remote\\.%s\\..*' % remotecfg['remote']) + remotecfg = b4.get_config_from_git('remote\\.%s\\..*' % BRANCH_INFO['remote']) BRANCH_INFO.update(remotecfg) return BRANCH_INFO -- cgit v1.2.3