示例#1
0
文件: test_gbpx.py 项目: johwerm/gbpx
def set_up():
    # Init repository with one file.
    remove_dir(_FLAGS, _TEST_DIR)
    mkdirs(_FLAGS, _TEST_DIR)
    init_repository(_FLAGS, _TEST_DIR)
    chdir(_TEST_DIR)
    create_file(_FLAGS, _TEST_FILE)
    commit_changes(_FLAGS, "Test file added.")

    # Create branches.
    create_branch(_FLAGS, _UPSTREAM)
    switch_branch(_UPSTREAM)

    create_branch(_FLAGS, _DEBIAN)
    switch_branch(_DEBIAN)
    mkdirs(_FLAGS, path.dirname(_TEST_DEBIAN_FILE))
    create_file(_FLAGS, _TEST_DEBIAN_FILE)
    commit_changes(_FLAGS, "Test debian file added.")

    # Commit ignored file and config.
    switch_branch(_RELEASE)
    create_file(_FLAGS, _IGNORE_FILE)
    create_file(_FLAGS, _TEST_FILE2)
    execute_with(action=Action.CONFIG)
    commit_changes(_FLAGS, "Ignored file added.")
示例#2
0
文件: gbpxutil.py 项目: johwerm/gbpx
def create_temp_commit(flags):
    """
    Commits any uncommitted changes on the current
    branch to a temporary commit.
    - branch    -- The branch to tag.
    Returns the a tuple with the branch name, commit id and
    stash name, used to restore the initial state with the
    'restore_temp_commit' function.
    If no changes can be committed the stash name is set to 'None'.
    """
    try:
        # Save the current branch
        current_branch = get_branch()
        log(flags, "Saving current branch name \'{0}\' ".format(current_branch))

        # Try to get the HEAD commit id of the current branch.
        head_commit = get_head_commit(current_branch)

        # Check for uncommitted changes.
        if not is_working_dir_clean():
            log(flags, "Stashing uncommitted changes on branch \'{0}\'".
                format(current_branch))
            # Save changes to tmp stash.
            stash_name = "gbpx<{0}>".format(head_commit)
            stash_changes(flags, stash_name)

            # Apply stash and create a temporary commit.
            log(flags, "Creating temporary commit on branch \'{0}\'".
                format(current_branch))
            apply_stash(flags, current_branch, drop=False)
            commit_changes(flags, "Temp \'{0}\' commit.".format(current_branch))
        else:
            stash_name = None
            log(flags, "Working directory clean, no commit needed")

        return current_branch, head_commit, stash_name
    except Error as err:
        raise OpError(err)