def error_out(msg, raise_abort=True):
    click.echo(click.style(msg, fg="red"))
    if raise_abort:
        raise click.Abort def get_repo(here="."):
    if os.path.abspath(here) == "/":  # hit rock bottom
        raise git.InvalidGitRepositoryError("Unable to find repo root")
    if os.path.isdir(os.path.join(here, ".git")):
        return git.Repo(here)
    return get_repo(os.path.join(here, "..")) @cli.group()
@click.option(
    "-u",
    "--bugzilla-url",
    default=BUGZILLA_URL,
    help=f"URL to Bugzilla instance (default: {BUGZILLA_URL})",
)
@pass_config
def bugzilla(config, bugzilla_url):
    """General tool for connecting to Bugzilla. The default URL
    is that for bugzilla.mozilla.org but you can override that.
    Once you're signed in you can use those credentials to automatically
    fetch bug summaries even of private bugs.
    """
    config.bugzilla_url = bugzilla_url @cli.group()
@click.option(
    "-u",
    "--github-url",
    default=GITHUB_URL,
    help=f"URL to GitHub instance (default: {GITHUB_URL})",
)
@pass_config
def github(config, github_url):
    """For setting up a GitHub API token."""
    config.github_url = github_url @cli.command()
@click.option(
    "-f",
    "--fork-name",
    default="",
    help="Name of the remote which is the fork where you push your branches.",
)
@click.option(
    "-o",
    "--origin-name",
    default="",
    help="Name of the remote which is the origin remote.",
)
@click.option(
    "-b",
    "--default-branch",
    default="",
    help="Name of the default branch.",
)
@pass_config
def config(config, fork_name="", origin_name="", default_branch=""):
    """Setting various configuration options"""
    state = read(config.configfile)
    if fork_name:
        update(config.configfile, {"FORK_NAME": fork_name})
        success_out(f"fork-name set to: {fork_name}")
    else:
        info_out(f"fork-name: {state['FORK_NAME']}")

    if origin_name:
        update(config.configfile, {"ORIGIN_NAME": origin_name})
        success_out(f"origin-name set to: {origin_name}")
    else:
        info_out(f"origin-name: {state.get('ORIGIN_NAME', '*not set*')}")

    if default_branch:
        update(config.configfile, {"DEFAULT_BRANCH": default_branch})
        success_out(f"default-branch set to: {default_branch}")
    else:
        info_out(f"default-branch: {state.get('DEFAULT_BRANCH', '*not set*')}") @cli.command()
@click.option(
    "--push-to-origin",
    default="",
    help="Push to the origin instead of your fork (true or false)",
)
@click.option(
    "--toggle-fixes-message",
    is_flag=True,
    default=False,
    help="Enable or disable the 'fixes' functionality in commits",
)
@pass_config
def local_config(config, push_to_origin="", toggle_fixes_message=False):
    """Setting configuration options per repo name"""
    if push_to_origin:
        try:
            before = load_config(config.configfile, "push_to_origin")
            print(f"push_to_origin before: {before}")
        except KeyError:
            print("push_to_origin before: not set")
        new_value = json.loads(push_to_origin)
        update_config(config.configfile, push_to_origin=new_value)
        print(f"push_to_origin after: {new_value}")

    if toggle_fixes_message:
        try:
            before = load_config(config.configfile, "fixes_message")
            print(f"toggle_fixes_message before: {before}")
        except KeyError:
            print("toggle_fixes_message before: not set")
            before = True  # the default
        new_value = not before
        update_config(config.configfile, fixes_message=new_value)
        print(f"fixes_message after: {new_value}") def commit(config, no_verify, yes):
    def count_files_in_directory(directory):
def _humanize_time(amount, units):
def humanize_seconds(seconds): def pr(config): def merge(config): def mastermerge(config): def start(config, bugnumber=""):
    def clean_branch_name(string):
def get_summary(config, bugnumber):
def parse_remote_url(url): def push(config, force=False): def getback(config, force=False): def rebase(config): class InvalidRemoteName(Exception):
DEFAULT_CUTOFF = 10
def branches(config, yes=False, searchstring="", cutoff=DEFAULT_CUTOFF):
def find(repo, searchstring, exact=False):
def get_merged_branches(repo):
def print_list(heads, merged_names, cutoff=10):
    def wrap(head):
    def format_age(dt):
    def format_msg(message): def cleanup(config, searchstring, force=False):
import os
import click
import git
from pkg_resources import iter_entry_points
from . import state
from .utils import error_out, get_repo
from .builtins import bugzilla  # noqa
from .builtins import github  # noqa
from .builtins import config as _  # noqa
from .builtins import local_config as _  # noqa
from .builtins.commit import gg_commit  # noqa
from .builtins.pr import gg_pr  # noqa
from .builtins.merge import gg_merge  # noqa
from .builtins.mastermerge import gg_mastermerge  # noqa
from .builtins.start import gg_start  # noqa
from .builtins.push import gg_push  # noqa
from .builtins.getback import gg_getback  # noqa
from .builtins.rebase import gg_rebase  # noqa
from .builtins.branches import gg_branches  # noqa
from .builtins.cleanup import gg_cleanup  # noqa




DEFAULT_CONFIGFILE = os.path.expanduser("~/.gg.json")


class Config:
    def __init__(self):
        self.verbose = False  # default
        self.configfile = DEFAULT_CONFIGFILE
        try:

            self.repo = get_repo()