示例#1
0
文件: gbpxutil.py 项目: johwerm/gbpx
def verify_create_head_tag(flags, branch, tag_type, version_str=None):
    """
    Verifies or creates a version tag for a branch HEAD.
    If tag needs to be created and no version is given,
    user will be prompted for version.
    - branch        -- The branch to tag.
    - tag_type      -- The tag type (<tag_type>/<version>).
    - version_str   -- The version string to use.
    Returns the a tuple with version created or found
    and True if created otherwise False. (<version>, <created>)
    """
    try:
        # Check that at least one head tag exists.
        if get_head_tags(branch, tag_type):
            log(flags, "The HEAD commit on branch \'" + branch +
                "\' is already tagged, skipping tagging")
            version_str = get_head_tag_version_str(branch, tag_type)
            return version_str, tag_type + "/" + version_str, False
        else:
            log(flags, "The HEAD commit on branch \'" + branch +
                "\' is not tagged correctly")
            if version_str is None:
                # Prompt user to tag the HEAD of release branch.
                raw_ver = prompt_user_input("Enter release version to tag",
                                            True)
                if raw_ver is not None:
                    version_str = raw_ver
                else:
                    raise OpError(msg="Tagging of HEAD commit on branch " +
                                      "\'" + branch + "\' aborted by user")

            # Tag using the given version string.
            tag = tag_type + "/" + version_str
            if not flags[Flag.SAFEMODE]:
                log(flags, "Tagging HEAD commit on branch \'" + branch +
                    "\' as \'" + tag + "\'")
                tag_head(flags, branch, tag)
            return version_str, tag, True
    except Error as err:
        raise OpError(err)