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:52:35 -0400 |
commit | 9597ccf8f856ec1d3a80486d0b1591d5a8ab8a67 (patch) | |
tree | 43e89d4746673f70cb6d08872ba51241aa3e8352 | |
parent | 3b1d01c1259a9d3182815a95c7613f4793b84a01 (diff) | |
download | b4-9597ccf8f856ec1d3a80486d0b1591d5a8ab8a67.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 |