<commit_before>import os

from git import Repo

from maintain.release.base import Releaser
from maintain.process import invoke


class GitReleaser(Releaser):
    name = 'git'

    @classmethod
    def detect(cls):
        return os.path.exists('.git')

    def __init__(self, config=None):
        self.repo = Repo()

        self.commit_format = (config or {}).get('commit_format', 'Release {version}')

        if self.repo.head.ref != self.repo.heads.master:
            # TODO: Support releasing from stable/hotfix branches
            raise Exception('You need to be on the `master` branch in order to do a release.')

        if self.repo.is_dirty():
            raise Exception('Git repository has unstaged changes.')

        if self.has_origin():
            self.repo.remotes.origin.fetch()

            if self.repo.remotes.origin.refs.master.commit != self.repo.head.ref.commit:
                raise Exception('Master has unsynced changes.')

    def has_origin(self):
        try:
            self.repo.remotes.origin
        except AttributeError:
            return False

        return True

    def determine_current_version(self):
        return None

    def bump(self, new_version):
        if self.repo.is_dirty():
            self.repo.index.add('*')
            self.repo.index.commit(self.commit_format.format(version=new_version))

    def release(self, version):
        tag = self.repo.create_tag(str(version), message='Release {}'.format(version))

        if self.has_origin():
            self.repo.remotes.origin.push(tag)


def git_update():
    invoke(['git', 'pull', 'origin', 'master'])
<commit_msg>feat: Allow changing git tag format<commit_after>import os

from git import Repo

from maintain.release.base import Releaser
from maintain.process import invoke


class GitReleaser(Releaser):
    name = 'git'

    @classmethod
    def detect(cls):
        return os.path.exists('.git')

    def __init__(self, config=None):
        self.repo = Repo()

        self.commit_format = (config or {}).get('commit_format', 'Release {version}')
        self.tag_format = (config or {}).get('tag_format', '{version}')

        if self.repo.head.ref != self.repo.heads.master:
            # TODO: Support releasing from stable/hotfix branches
            raise Exception('You need to be on the `master` branch in order to do a release.')

        if self.repo.is_dirty():
            raise Exception('Git repository has unstaged changes.')

        if self.has_origin():
            self.repo.remotes.origin.fetch()

            if self.repo.remotes.origin.refs.master.commit != self.repo.head.ref.commit:
                raise Exception('Master has unsynced changes.')

    def has_origin(self):
        try:
            self.repo.remotes.origin
        except AttributeError:
            return False

        return True

    def determine_current_version(self):
        return None

    def bump(self, new_version):
        if self.repo.is_dirty():
            self.repo.index.add('*')
            self.repo.index.commit(self.commit_format.format(version=new_version))

    def release(self, version):
        tag_name = self.tag_format.format(version=version)
        tag = self.repo.create_tag(tag_name, message='Release {}'.format(version))

        if self.has_origin():
            self.repo.remotes.origin.push(tag)


def git_update():
    invoke(['git', 'pull', 'origin', 'master'])

{'fraction_non_alphanumeric': 0.1178018123355744, 'fraction_numerical': 0.0, 'mean_word_length': 2.488277268093782, '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': '797129', 'n_tokens_mistral': 996, 'n_tokens_neox': 957, 'n_words': 240}