Exemple #1
0
def reset_dbedit_and_switch():
    # delete remote branch, if applicable
    if config.remote_personal_dbedit_exists():
        try:
            git.push(REMOTE_PERSONAL, "--delete", BRANCH_DBEDIT)
        except sh.ErrorReturnCode as e:
            error(e)
            error("Unable to delete the remote branch.")

    # switch to branch, creating it if it doesn't exist
    git.checkout("-B", BRANCH_DBEDIT, REMOTE_LINGBIB_MASTER, _out=gitout)
Exemple #2
0
def set_defaults():
    if not remote_personal_url_is_set():
        warning("Remote 'personal' not set. "
                "Please set it to your personal fork manually.")
        warning("Skipping other settings that depend on this.")
    else:
        if not branch_master_exists():
            git.checkout("master", "remote/personal")
        elif not branch_master_tracking_personal():
            set_branch_master_tracking()

    if not remote_lingbib_url_is_set():
        set_remote_lingbib_url()
Exemple #3
0
def switch_to_master():
    if config.current_branch() == BRANCH_MASTER:
        print("Already on branch 'master'.")
    else:
        cmd = git.checkout("master", _out=gitout)
Exemple #4
0
def create_dbedit_and_switch():
    """create the new branch based on master and switch immediately"""
    git.checkout("-b", BRANCH_DBEDIT, REMOTE_LINGBIB_MASTER, _out=gitout)
Exemple #5
0
def update_dbedit_and_switch():
    git.checkout(BRANCH_DBEDIT, _out=gitout)
    git.rebase(REMOTE_LINGBIB_MASTER, _out=gitout)
Exemple #6
0
def update_personal_db(personal_db_path, skip_backup):
    """
    Reimplementation of scripts/update_personal_db.sh.
    """
    # ensure that personal database exists
    if os.path.isfile(personal_db_path):
        info("Using '{db}' as personal database.".format(db=personal_db_path))
    else:
        error("Personal database '{db}' does not exist.".format(
              db=personal_db_path))
        exit(1)

    # force the master branch to be used
    if not config.current_branch() == defs.BRANCH_MASTER:
        info("Not currently on 'master' branch. Switching now.")
        try:
            git.checkout("master")
        except sh.ErrorReturnCode as e:
            gitout(e.stderr)
            error("Unable to switch branches. "
                  "Please fix any Git problems and try again.")
            exit(1)

    # make sure remote 'lingbib' is set
    if not config.remote_lingbib_url_is_set():
        config.set_remote_lingbib_url()
    
    # fetch updates from lingbib/master
    info("Pulling updates to master database...")
    try:
        git.pull("--rebase lingbib master".split())
    except sh.ErrorReturnCode as e:
        gitout(e.stderr)
        error("Please run 'git pull --rebase lingbib master' and resolve "
              "the conflicts, then try again.")
        exit(1)
    else:
        info("Update complete.")

    # fetch updates from remote "personal"
    # TODO
    
    # backup current personal bibfile
    if not skip_backup:
        backup_path = personal_db_path + ".old"
        try:
            sh.cp(personal_db_path, backup_path)
        except sh.ErrorReturnCode as e:
            error("Unable to make a backup of the current personal database.")
            error(e.stderr)
            exit(1)
        else:
            info("Backed up current personal database as '{old}'.".format(
                 old=backup_path))

    # invoke BibTool to merge master and personal databases, overwriting personal
    # Note: BibTool considers things that should be errors as warnings, and
    #   doesn't return an error code so for now just print warnings
    info("Merging master database with personal database.")
    try:
        cmd_status = bibtool("-r", "bibtool/personal-merge.rsc",
        personal_db_path, defs.DB_MASTER, o=personal_db_path,
        _out=handle_bibtool_output, _err=handle_bibtool_output)
    except sh.ErrorReturnCode as e:
        error("Call to BibTool failed.")
        error(e.stderr)
        exit(1)