def repo_branches(self, repo):
        """ Get the branches of a repository """
        branches = []
        try:
            # switch to directory where repo will be cloned to
            status = self.path_dirs.apply_path(repo)
            if status[0]:
                cwd = status[1]
            else:
                self.logger.error('apply_path failed. Exiting repo_branches'
                                  ' with status ' + str(status))
                return status

            branch_output = check_output(shlex.split('git branch -a'),
                                         stderr=STDOUT,
                                         close_fds=True)
            branch_output = branch_output.split(b'\n')
            for branch in branch_output:
                br = branch.strip()
                if br.startswith(b'*'):
                    br = br[2:]
                if b'/' in br:
                    branches.append(br.rsplit(b'/', 1)[1].decode('utf-8'))
                elif br:
                    branches.append(br.decode('utf-8'))

            branches = list(set(branches))
            for branch in branches:
                try:
                    check_output(shlex.split('git checkout ' + branch),
                                 stderr=STDOUT,
                                 close_fds=True)
                except Exception as e:  # pragma: no cover
                    self.logger.error('repo_branches failed with error: ' +
                                      str(e) + ' on branch: ' + str(branch))
                    status = (False, e)
                    return status

            chdir(cwd)
            status = (True, branches)
        except Exception as e:  # pragma: no cover
            self.logger.error('repo_branches failed with error: ' + str(e))
            status = (False, e)

        return status
def repo_branches ( self , repo ) : branches = [ ] try : status = self . path_dirs . apply_path ( repo ) if status [ 0 ] : cwd = status [ 1 ] else : self . logger . error ( 'apply_path failed. Exiting repo_branches' ' with status ' + str ( status ) ) return status branch_output = check_output ( shlex . split ( 'git branch -a' ) , stderr = STDOUT , close_fds = True ) branch_output = branch_output . split ( b'\n' ) for branch in branch_output : br = branch . strip ( ) if br . startswith ( b'*' ) : br = br [ 2 : ] if b'/' in br : branches . append ( br . rsplit ( b'/' , 1 ) [ 1 ] . decode ( 'utf-8' ) ) elif br : branches . append ( br . decode ( 'utf-8' ) ) branches = list ( set ( branches ) ) for branch in branches : try : check_output ( shlex . split ( 'git checkout ' + branch ) , stderr = STDOUT , close_fds = True ) except Exception as e : self . logger . error ( 'repo_branches failed with error: ' + str ( e ) + ' on branch: ' + str ( branch ) ) status = ( False , e ) return status chdir ( cwd ) status = ( True , branches ) except Exception as e : self . logger . error ( 'repo_branches failed with error: ' + str ( e ) ) status = ( False , e ) return status
Get the branches of a repository