diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-07 13:31:16 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-07 13:34:57 -0400 |
commit | 2ceffc04de08acb337b4c0ea768688fba16dfe69 (patch) | |
tree | d9fb5ebe7ed71cd1c70f6e1b91deea950316b8c6 | |
parent | b1d463c624e5cef483bed2a809edd6c4eecff93f (diff) | |
download | b4-2ceffc04de08acb337b4c0ea768688fba16dfe69.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.py | 33 |
1 files changed, 9 insertions, 24 deletions
@@ -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 |