# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# 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 get_default_branch(repo, origin_name):
#     # TODO: Figure out how to do this with GitPython
#     res = subprocess.run(
#         f"git remote show {origin_name}".split(),
#         check=True,
#         capture_output=True,
#         cwd=repo.working_tree_dir,
#     )
#     for line in res.stdout.decode("utf-8").splitlines():
#         if line.strip().startswith("HEAD branch:"):
#             return line.replace("HEAD branch:", "").strip()
# 
#     raise NotImplementedError(f"No remote called {origin_name!r}")
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))


from gg.main import cli, pass_config
from gg.state import read
from gg.utils import error_out, get_default_branch, success_out


@cli.command()
@pass_config
def mastermerge(config):
    """Merge the origin_name/default_branch into the the current branch"""
    repo = config.repo

    state = read(config.configfile)
    origin_name = state.get("ORIGIN_NAME", "origin")
    default_branch = get_default_branch(repo, origin_name)

    active_branch = repo.active_branch
    if active_branch.name == default_branch:
        error_out(f"You're already on the {default_branch} branch.")
    active_branch_name = active_branch.name

    if repo.is_dirty():

# Path: gg/main.py
# DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")
# class Config:
#     def __init__(self):
# def cli(config, configfile, verbose):
# 
# Path: gg/state.py
# def read(configfile):
#     with open(configfile, "r") as f:
#         return json.load(f)
# 
# 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 get_default_branch(repo, origin_name):
#     # TODO: Figure out how to do this with GitPython
#     res = subprocess.run(
#         f"git remote show {origin_name}".split(),
#         check=True,
#         capture_output=True,
#         cwd=repo.working_tree_dir,
#     )
#     for line in res.stdout.decode("utf-8").splitlines():
#         if line.strip().startswith("HEAD branch:"):
#             return line.replace("HEAD branch:", "").strip()
# 
#     raise NotImplementedError(f"No remote called {origin_name!r}")
# 
# def success_out(msg):
#     click.echo(click.style(msg, fg="green"))


# Path: gg/builtins/mastermerge/gg_mastermerge.py
from gg.main import cli, pass_config
from gg.state import read
from gg.utils import error_out, get_default_branch, success_out



@cli.command()
@pass_config
def mastermerge(config):
    """Merge the origin_name/default_branch into the the current branch"""
    repo = config.repo

    state = read(config.configfile)
    origin_name = state.get("ORIGIN_NAME", "origin")
    default_branch = get_default_branch(repo, origin_name)

    active_branch = repo.active_branch
    if active_branch.name == default_branch:
        error_out(f"You're already on the {default_branch} branch.")
    active_branch_name = active_branch.name

    if repo.is_dirty():

        error_out(