diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-11 16:52:35 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-11 16:54:04 -0400 |
commit | 89321511fec7c5e8379cad30025c70f31bea9482 (patch) | |
tree | 524a1e0ffac79befa9d7e5a4829ff0418e8dcec4 | |
parent | 98ec0fd24fa7732df21c546ddb555fc97e765406 (diff) | |
download | b4-89321511fec7c5e8379cad30025c70f31bea9482.tar.gz |
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 <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/ty.py | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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 |