<commit_before># -*- coding: utf-8 -*-

"""
legit.scm
~~~~~~~~~

This module provides the main interface to Git.
"""

import os
from collections import namedtuple
from operator import attrgetter

from git import Repo, Git

from .helpers import find_path_above



GH_TEMPLATE = 'GitHub: stashing before switching branches.'
LEGIT_TEMPLATE = 'Legit: stashing before syncing.'


Branch = namedtuple('Branch', ['name', 'is_published'])



def stash_for_switch():
    """Stashes changes from current branch for branch switch."""

    return repo.git.execute(['git',
        'stash', 'save',
        GH_TEMPLATE.format(branch=repo.head.ref.name)])


def unstash_for_switch():
    """Unstashes changes from current branch for branch switch."""

    stash_list = repo.git.execute(['git',
        'stash', 'list'])

    stash_index = None

    for stash in stash_list.splitlines():
        if ('GitHub' in stash) and (repo.head.ref.name in stash):
            stash_index = stash[7]

    if stash_index is not None:
        return repo.git.execute(['git',
            'stash', 'pop', 'stash@{{0}}'.format(stash_index)])


def stash_for_sync():
    return repo.git.execute(['git',
        'stash', 'save',
        LEGIT_TEMPLATE.format(branch=repo.head.ref.name)])


def unstash_for_sync():
    """Unstashes changes from current branch for branch sync."""

    stash_list = repo.git.execute(['git',
        'stash', 'list'])

    stash_index = None

    for stash in stash_list.splitlines():
        if ('Legit' in stash) and (repo.head.ref.name in stash):
            stash_index = stash[7]

    if stash_index is not None:
        return repo.git.execute(['git',
            'stash', 'pop', 'stash@{{0}}'.format(stash_index)])

def fetch():
    return repo.remotes[0].fetch()

def pull(branch=None):
    if branch is None:
        return repo.remotes[0].pull()
    else:
        return repo.git.execute(['git', 'pull', repo.remotes[0].name, branch])


def push(branch=None):
    if branch is None:
        return repo.remotes[0].push()
    else:
        return repo.git.execute(['git', 'push', repo.remotes[0].name, branch])


def checkout_branch(branch):
    """Checks out given branch."""

    return repo.heads[branch].checkout()


def get_repo(git=False):
    """Returns the current Repo, based on path."""<commit_msg>raw commands are better<commit_after># -*- coding: utf-8 -*-

"""
legit.scm
~~~~~~~~~

This module provides the main interface to Git.
"""

import os
from collections import namedtuple
from operator import attrgetter

from git import Repo, Git

from .helpers import find_path_above



GH_TEMPLATE = 'GitHub: stashing before switching branches.'
LEGIT_TEMPLATE = 'Legit: stashing before syncing.'


Branch = namedtuple('Branch', ['name', 'is_published'])



def stash_for_switch():
    """Stashes changes from current branch for branch switch."""

    return repo.git.execute(['git',
        'stash', 'save',
        GH_TEMPLATE.format(branch=repo.head.ref.name)])


def unstash_for_switch():
    """Unstashes changes from current branch for branch switch."""

    stash_list = repo.git.execute(['git',
        'stash', 'list'])

    stash_index = None

    for stash in stash_list.splitlines():
        if ('GitHub' in stash) and (repo.head.ref.name in stash):
            stash_index = stash[7]

    if stash_index is not None:
        return repo.git.execute(['git',
            'stash', 'pop', 'stash@{{0}}'.format(stash_index)])


def stash_for_sync():
    return repo.git.execute(['git',
        'stash', 'save',
        LEGIT_TEMPLATE.format(branch=repo.head.ref.name)])


def unstash_for_sync():
    """Unstashes changes from current branch for branch sync."""

    stash_list = repo.git.execute(['git',
        'stash', 'list'])

    stash_index = None

    for stash in stash_list.splitlines():
        if ('Legit' in stash) and (repo.head.ref.name in stash):
            stash_index = stash[7]

    if stash_index is not None:
        return repo.git.execute(['git',
            'stash', 'pop', 'stash@{{0}}'.format(stash_index)])


def fetch():
    return repo.remotes[0].fetch()


def pull(branch=None):
    if branch is None:
        return repo.git.execute(['git', 'pull'])
    else:
        return repo.git.execute(['git', 'pull', repo.remotes[0].name, branch])


def push(branch=None):
    if branch is None:
        return repo.git.execute(['git', 'push'])
    else:
        return repo.git.execute(['git', 'push', repo.remotes[0].name, branch])


def checkout_branch(branch):
    """Checks out given branch."""

    return repo.heads[branch].checkout()


def get_repo(git=False):
    """Returns the current Repo, based on path."""
{'fraction_non_alphanumeric': 0.14972114972114972, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 3.193345323741007, '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': '5058709', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1499, 'n_words': 398}