<commit_before># -*- coding: utf-8 -*-
"""Tests for vcspull git repos."""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, with_statement)

import os
import unittest

import mock

from vcspull import exc
from vcspull._compat import StringIO
from vcspull.repo import create_repo
from vcspull.util import run
from .helpers import (ConfigTestCase, RepoIntegrationTest, RepoTestMixin,
                      mute)


class RepoGit(RepoIntegrationTest, unittest.TestCase):

    """Integration level tests."""

    @mute
    def test_repo_git_update(self):
        repo_dir = os.path.join(self.TMP_DIR, '.repo_dir')
        repo_name = 'my_git_project'

        git_repo = create_repo(**{
            'url': 'git+file://' + os.path.join(repo_dir, repo_name),
            'parent_dir': self.TMP_DIR,
            'name': repo_name
        })

        os.mkdir(repo_dir)
        run([
            'git', 'init', git_repo['name']
        ], cwd=repo_dir)
        git_checkout_dest = os.path.join(self.TMP_DIR, git_repo['name'])
        git_repo.obtain(quiet=True)

        testfile = 'testfile.test'

        run(['touch', testfile], cwd=os.path.join(repo_dir, repo_name))
        run([
            'git', 'add', testfile
        ], cwd=os.path.join(repo_dir, repo_name))
        run([
            'git', 'commit', '-m', 'a test file for %s' % git_repo['name']
        ], cwd=os.path.join(repo_dir, repo_name))
        git_repo.update_repo()

        test_repo_revision = run(
            ['git', 'rev-parse', 'HEAD'],
            cwd=os.path.join(repo_dir, repo_name),
        )['stdout']

        self.assertEqual(
            git_repo.get_revision(),
            test_repo_revision
        )
        self.assertTrue(os.path.exists(git_checkout_dest))


class GitRepoRemotes(RepoIntegrationTest, unittest.TestCase):

    @mute
    def test_remotes(self):
        repo_dir, git_repo = self.create_git_repo(create_temp_repo=True)<commit_msg>rewrite top git test, split test into bare repo test<commit_after># -*- coding: utf-8 -*-
"""Tests for vcspull git repos."""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals, with_statement)

import os
import unittest

import mock

from vcspull import exc
from vcspull._compat import StringIO
from vcspull.repo import create_repo
from vcspull.util import run
from .helpers import (ConfigTestCase, RepoIntegrationTest, RepoTestMixin,
                      mute)


def test_repo_git_obtain_bare_repo(tmpdir):

    repo_name = 'my_git_project'

    # init bare repo
    run([
        'git', 'init', repo_name
    ], cwd=str(tmpdir))

    bare_repo_dir = tmpdir.join(repo_name)

    git_repo = create_repo(**{
        'url': 'git+file://' + str(bare_repo_dir),
        'parent_dir': str(tmpdir),
        'name': 'obtaining a bare repo'
    })

    git_repo.obtain(quiet=True)
    assert git_repo.get_revision() == ['HEAD']


def test_repo_git_obtain_full(tmpdir):
    repo_name = 'my_git_project'

    # init sophisticated repo
    run([
        'git', 'init', repo_name
    ], cwd=str(tmpdir))
    remote_repo_dir = str(tmpdir.join(repo_name))
    testfile = 'testfile.test'

    run(['touch', testfile], cwd=remote_repo_dir)
    run([
        'git', 'add', testfile
    ], cwd=remote_repo_dir)
    run([
        'git', 'commit', '-m', 'a test file'
    ], cwd=remote_repo_dir)


    test_repo_revision = run(
        ['git', 'rev-parse', 'HEAD'],
        cwd=remote_repo_dir,
    )['stdout']

    # create a new repo with the repo as a remote
    git_repo = create_repo(**{
        'url': 'git+file://' + remote_repo_dir,
        'parent_dir': str(tmpdir),
        'name': 'myrepo'
    })

    git_repo.obtain(quiet=True)

    assert git_repo.get_revision() == test_repo_revision
    assert os.path.exists(str(tmpdir.join('myrepo')))


class GitRepoRemotes(RepoIntegrationTest, unittest.TestCase):

    @mute
    def test_remotes(self):
        repo_dir, git_repo = self.create_git_repo(create_temp_repo=True)
{'fraction_non_alphanumeric': 0.12577065351418001, 'fraction_numerical': 0.0004932182490752158, 'mean_word_length': 2.81203007518797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6850775', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1349, 'n_words': 281}