import os
import sys
from contextlib import contextmanager

from invoke import UnexpectedExit


def git_commit(c, addstr, msg):
    try:
        c.run("git config --get user.email")
        c.run("git config --get user.name")
    except UnexpectedExit:
        c.run('git config --local user.email "ci@cd.org"')
        c.run('git config --local user.name "CI/CD"')
    c.run(f'git add {addstr} && git commit -m "{msg}"')


@contextmanager
def cd_into(dirpath):
    wd = os.getcwd()
    os.chdir(dirpath)
    sys.path.insert(0, str(dirpath))
    yield
    os.chdir(wd)
    sys.path.pop(0)

[((20, 9, 20, 20), 'os.getcwd', 'os.getcwd', ({}, {}), '()', False, 'import os\n'), ((21, 4, 21, 21), 'os.chdir', 'os.chdir', ({(21, 13, 21, 20): 'dirpath'}, {}), '(dirpath)', False, 'import os\n'), ((24, 4, 24, 16), 'os.chdir', 'os.chdir', ({(24, 13, 24, 15): 'wd'}, {}), '(wd)', False, 'import os\n'), ((25, 4, 25, 19), 'sys.path.pop', 'sys.path.pop', ({(25, 17, 25, 18): '(0)'}, {}), '(0)', False, 'import sys\n')]