# Path: gg/utils.py
# def error_out(msg, raise_abort=True):
#     click.echo(click.style(msg, fg="red"))
#     if raise_abort:
#         raise click.Abort
# 
# def info_out(msg):
#     click.echo(msg)
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def load_config(configfile, key):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:_config:{key}"
#     return read(configfile)[key]
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):


import git
import click
from gg.utils import error_out, info_out, success_out
from gg.state import read, load_config
from gg.main import cli, pass_config

@cli.command()
@click.option("-f", "--force", is_flag=True, default=False)
@pass_config
def push(config, force=False):
    """Create push the current branch."""
    repo = config.repo

    state = read(config.configfile)
    default_branch = state.get("DEFAULT_BRANCH", "master")

    active_branch = repo.active_branch
    if active_branch.name == default_branch:
        error_out(
            f"Can't commit when on the {default_branch} branch. "
            "You really ought to do work in branches."
        )

    if not state.get("FORK_NAME"):
        info_out("Can't help you push the commit. Please run: gg config --help")
        return 0

    try:
        push_to_origin = load_config(config.configfile, "push_to_origin")
    except KeyError:
        push_to_origin = False

        try:
            repo.remotes[state["FORK_NAME"]]
        except IndexError:

# Path: gg/utils.py
# def error_out(msg, raise_abort=True):
#     click.echo(click.style(msg, fg="red"))
#     if raise_abort:
#         raise click.Abort
# 
# def info_out(msg):
#     click.echo(msg)
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# def load_config(configfile, key):
#     # like read() but returning specifically the state for the current repo
#     key = f"{get_repo_name()}:_config:{key}"
#     return read(configfile)[key]
# 
# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):


# Path: gg/builtins/push/gg_push.py
import git
import click
from gg.utils import error_out, info_out, success_out
from gg.state import read, load_config
from gg.main import cli, pass_config


@cli.command()
@click.option("-f", "--force", is_flag=True, default=False)
@pass_config
def push(config, force=False):
    """Create push the current branch."""
    repo = config.repo

    state = read(config.configfile)
    default_branch = state.get("DEFAULT_BRANCH", "master")

    active_branch = repo.active_branch
    if active_branch.name == default_branch:
        error_out(
            f"Can't commit when on the {default_branch} branch. "
            "You really ought to do work in branches."
        )

    if not state.get("FORK_NAME"):
        info_out("Can't help you push the commit. Please run: gg config --help")
        return 0

    try:
        push_to_origin = load_config(config.configfile, "push_to_origin")
    except KeyError:
        push_to_origin = False

        try:
            repo.remotes[state["FORK_NAME"]]
        except IndexError:

            error_out("There is no remote called '{}'".format(state["FORK_NAME"]))