示例#1
0
def do_rebranch_abort(args):
    git = Git()
    state = RebranchState(git.rootdir)

    if not state.in_progress():
        error("There is no rebranch in progress")
        sys.exit(1)

    # Abort an eventual rebase
    if git.rebase_in_progress():
        (rc, stdout, stderr) = git.rebase_abort()
        sys.stdout.write(stdout)
        sys.stderr.write(stderr)
        if rc != 0:
            error("Failed rebase --abort")

    # Just to be sure; check if the repo is clean
    if git.isdirty:
        error("Working copy is not clean")
        sys.exit(1)

    # Reset rebased branches to their original revisions
    (curbranch, orig_branches, _) = state.load()
    for (branch, sha1) in orig_branches.items():
        info("Resetting {0} to {1}", branch, sha1)
        git.checkout(branch)
        git.reset_hard(sha1)

    # Checkout the original branch
    git.checkout(curbranch)

    state.clear()
示例#2
0
def do_rebranch(args):
    git = Git()
    state = RebranchState(git.rootdir)

    # Check if we were interrupted
    if state.in_progress():
        error("Rebranch is in progress. Use --continue or --abort")
        sys.exit(1)

    # Check if the repo is clean
    if git.isdirty:
        error("Working copy is not clean, aborting.")
        sys.exit(1)

    # Remember the current branch
    curbranch = git.current_branch

    try:
        # Read .gitrebranch
        config = RebranchConfig(git)

        # Check that all the required branches exist
        for branch in config.branches:
            git.get_sha1(branch)

        # Do rebranch
        _rebranch(git, curbranch, {}, config.rebase_plan(), args.dry_run)
    except (GitError, RebranchConfigError) as e:
        error(e)
        sys.exit(1)

    # Checkout the original branch
    git.checkout(curbranch)
示例#3
0
def do_rebranch_continue(args):
    git = Git()
    state = RebranchState(git.rootdir)

    if not state.in_progress():
        error("There is no rebranch in progress")
        sys.exit(1)

    # Continue the interrupted rebase
    if git.rebase_in_progress():
        info("Continue rebasing")
        (rc, stdout, stderr) = git.rebase_continue()
        sys.stdout.write(stdout)
        sys.stderr.write(stderr)
        if rc != 0:
            error('Resolve the conflicts and run "git rebranch --continue"')
            error('To stop, run "git rebranch --abort"')
            sys.exit(1)

    # Continue rebasing
    try:
        (curbranch, orig_branches, plan) = state.load()
        _rebranch(git, curbranch, orig_branches, plan, args.dry_run)
    except GitError as e:
        error(e)
        sys.exit(1)

    # Checkout the original branch
    git.checkout(curbranch)