# Path: mod/log.py
# RED = '\033[1;31m'
# GREEN = '\033[1;32m'
# YELLOW = '\033[1;33m'
# BLUE = '\033[1;36m'
# DEF = '\033[0;0m'
# def error(msg, fatal=True) :
# def warn(msg) :
# def ok(item, status) :
# def failed(item, status) :
# def optional(item, status) :
# def info(msg) :
# def colored(color, msg) :


import re
import subprocess
from mod import log

#-------------------------------------------------------------------------------
def commit_allow_empty(proj_dir, msg):
    """same as commit(), but uses the --allow-empty arg so that the
    commit doesn't fail if there's nothing to commit.

    :param proj_dir:    path to a git repo
    """
    check_exists_with_error()
    try:
        subprocess.check_call('git commit --allow-empty -m "{}"'.format(msg), cwd=proj_dir, shell=True)
    except subprocess.CalledProcessError as e:
        log.error("'git commit' failed with '{}'".format(e.returncode))

#-------------------------------------------------------------------------------
def push(proj_dir):
    """runs a 'git push' in the provided git repo
    
    :param proj_dir:    path to git repo
    """
    check_exists_with_error()
    try:
        res = subprocess.check_call('git push', cwd=proj_dir, shell=True)
    except subprocess.CalledProcessError as e:
        log.error("'git push' failed with '{}'".format(e.returncode))

#-------------------------------------------------------------------------------
def has_local_changes(proj_dir):
    """checks if a git repo has uncommitted or unpushed changes (basically
    anything which would make a git pull unsafe"""

# Path: mod/log.py
# RED = '\033[1;31m'
# GREEN = '\033[1;32m'
# YELLOW = '\033[1;33m'
# BLUE = '\033[1;36m'
# DEF = '\033[0;0m'
# def error(msg, fatal=True) :
# def warn(msg) :
# def ok(item, status) :
# def failed(item, status) :
# def optional(item, status) :
# def info(msg) :
# def colored(color, msg) :


# Path: mod/tools/git.py
import re
import subprocess
from mod import log


#-------------------------------------------------------------------------------
def commit_allow_empty(proj_dir, msg):
    """same as commit(), but uses the --allow-empty arg so that the
    commit doesn't fail if there's nothing to commit.

    :param proj_dir:    path to a git repo
    """
    check_exists_with_error()
    try:
        subprocess.check_call('git commit --allow-empty -m "{}"'.format(msg), cwd=proj_dir, shell=True)
    except subprocess.CalledProcessError as e:
        log.error("'git commit' failed with '{}'".format(e.returncode))

#-------------------------------------------------------------------------------
def push(proj_dir):
    """runs a 'git push' in the provided git repo
    
    :param proj_dir:    path to git repo
    """
    check_exists_with_error()
    try:
        res = subprocess.check_call('git push', cwd=proj_dir, shell=True)
    except subprocess.CalledProcessError as e:
        log.error("'git push' failed with '{}'".format(e.returncode))

#-------------------------------------------------------------------------------
def has_local_changes(proj_dir):
    """checks if a git repo has uncommitted or unpushed changes (basically
    anything which would make a git pull unsafe"""

    check_exists_with_error()