aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 13:31:16 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-07 13:31:16 -0400
commit80febe77d774bc947fd754310a9b64228d5de489 (patch)
treefeedea3b648aa12d07a71918266490ce1d560921
parent56b965b2e30d483145a737062151616a3628960c (diff)
downloadb4-80febe77d774bc947fd754310a9b64228d5de489.tar.gz
Improve remote/branch mapping
Our mapping of local to remote branches was very naive and failed when remote names didn't exactly match heads. Improve it using suggestions from Will Deacon. Link: https://linux.kernel.org/g/tools/message/140 Reported-by: Will Deacon <will@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/ty.py33
1 files changed, 9 insertions, 24 deletions
diff --git a/b4/ty.py b/b4/ty.py
index 82cc02f..af78d63 100644
--- a/b4/ty.py
+++ b/b4/ty.py
@@ -531,12 +531,12 @@ def get_wanted_branch(cmdargs):
gitdir = cmdargs.gitdir
if not cmdargs.branch:
# Find out our current branch
- gitargs = ['rev-parse', '--abbrev-ref', 'HEAD']
+ gitargs = ['symbolic-ref', '-q', 'HEAD']
ecode, out = b4.git_run_command(gitdir, gitargs)
if ecode > 0:
- logger.critical('Not able to get current branch (git branch --show-current)')
+ logger.critical('Not able to get current branch (git symbolic-ref HEAD)')
sys.exit(1)
- wantbranch = out.strip()
+ wantbranch = re.sub(r'^refs/heads/', '', out.strip())
logger.debug('will check branch=%s', wantbranch)
else:
# Make sure it's a real branch
@@ -560,32 +560,17 @@ def get_branch_info(gitdir, branch):
BRANCH_INFO = dict()
- if branch.find('/') < 0:
- # Not a remote branch
- return BRANCH_INFO
-
- # Get a list of all 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('%s/' % entry) == 0:
- remote = entry
- break
-
- if remote is None:
+ 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
- BRANCH_INFO['remote'] = remote
- BRANCH_INFO['branch'] = branch.replace('%s/' % remote, '')
+ 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\\..*' % remote)
+ remotecfg = b4.get_config_from_git('remote\\.%s\\..*' % remotecfg['remote'])
BRANCH_INFO.update(remotecfg)
return BRANCH_INFO