summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-11 16:52:35 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-11 16:52:35 -0400
commit9597ccf8f856ec1d3a80486d0b1591d5a8ab8a67 (patch)
tree43e89d4746673f70cb6d08872ba51241aa3e8352
parent3b1d01c1259a9d3182815a95c7613f4793b84a01 (diff)
downloadb4-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.py30
1 files 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