'This wil create conditions to exercise bad paths in the switch_branch function.'

def test_branch_exceptions(self):

    bare_repo = os.path.abspath('{0}/{1}'.format(settings.TEST_ROOT, 'bare.git'))
    os.mkdir(bare_repo)
    self.addCleanup(shutil.rmtree, bare_repo)
    subprocess.check_output(['git', '--bare', 'init'], stderr=subprocess.STDOUT, cwd=bare_repo)
    repo_dir = self.git_repo_dir
    if (not os.path.isdir(repo_dir)):
        os.mkdir(repo_dir)
    self.addCleanup(shutil.rmtree, repo_dir)
    rdir = '{0}/bare'.format(repo_dir)
    with self.assertRaises(GitImportErrorBadRepo):
        git_import.add_repo('file://{0}'.format(bare_repo), None, None)
    output = StringIO.StringIO()
    test_log_handler = logging.StreamHandler(output)
    test_log_handler.setLevel(logging.DEBUG)
    glog = git_import.log
    glog.addHandler(test_log_handler)
    shutil.move(bare_repo, '{0}/not_bare.git'.format(settings.TEST_ROOT))
    try:
        git_import.switch_branch('master', rdir)
    except GitImportError:
        self.assertIn('Unable    to    fetch    remote', output.getvalue())
    shutil.move('{0}/not_bare.git'.format(settings.TEST_ROOT), bare_repo)
    output.truncate(0)
    subprocess.check_output(['git', 'remote', 'rename', 'origin', 'blah'], stderr=subprocess.STDOUT, cwd=rdir)
    with self.assertRaises(GitImportError):
        git_import.switch_branch('master', rdir)
    self.assertIn('Getting    a    list    of    remote    branches    failed', output.getvalue())
