org.eclipse.jgit.lib.RebaseTodoLine Java Examples

The following examples show how to use org.eclipse.jgit.lib.RebaseTodoLine. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RewordActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public RebaseResponse extractMessage(Repository repository) throws IOException {
    List<RebaseTodoLine> rebaseTodoLines = repository.readRebaseTodo(getRebasePath(repository, DONE), false);
    // the last rebase_todo_line
    RebaseTodoLine line = rebaseTodoLines.get(rebaseTodoLines.size() - 1);

    try (RevWalk walk = new RevWalk(repository)) {
        ObjectReader or = repository.newObjectReader();
        RevCommit commitToPick = walk.parseCommit(or.resolve(line.getCommit()).iterator().next());

        String oldMessage = commitToPick.getFullMessage();

        RebaseResponse response = new RebaseResponse(false, RebaseResponse.Status.INTERACTIVE_EDIT);
        response.setMessage(oldMessage);

        return response;
    }
}
 
Example #2
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void writeTodoFile (Repository repository, List<RebaseTodoLine> steps) throws IOException {
    File f = new File(repository.getDirectory(), SEQUENCER);
    if (f.canWrite()) {
        RebaseTodoFile todoFile = new RebaseTodoFile(repository);
        todoFile.writeRebaseTodoFile(SEQUENCER + File.separator + SEQUENCER_TODO, steps, false);
    }
}
 
Example #3
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<RebaseTodoLine> readTodoFile (Repository repository) throws IOException {
    String path = SEQUENCER + File.separator + SEQUENCER_TODO;
    File f = new File(repository.getDirectory(), path);
    if (f.canRead()) {
        RebaseTodoFile todoFile = new RebaseTodoFile(repository);
        return todoFile.readRebaseTodo(SEQUENCER + File.separator + SEQUENCER_TODO, true);
    }
    return Collections.<RebaseTodoLine>emptyList();
}
 
Example #4
Source File: RebaseTodoUtils.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static List<RebaseResponse.RebaseTodoLine> loadFrom(List<RebaseTodoLine> lines) {
    List<RebaseResponse.RebaseTodoLine> rebaseTodoLines = new ArrayList<>();

    for (RebaseTodoLine line : lines) {
        RebaseResponse.RebaseTodoLine rebaseTodoLine = new RebaseResponse.RebaseTodoLine(
                line.getAction().name(),
                line.getCommit().name(),
                line.getShortMessage());

        rebaseTodoLines.add(rebaseTodoLine);
    }

    return rebaseTodoLines;
}
 
Example #5
Source File: RebaseTodoUtils.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static List<RebaseTodoLine> parseLines(List<RebaseResponse.RebaseTodoLine> lines) {
    List<RebaseTodoLine> rebaseTodoLines = new ArrayList<>();

    for (RebaseResponse.RebaseTodoLine line : lines) {
        RebaseTodoLine rebaseTodoLine = new RebaseTodoLine(
                RebaseTodoLine.Action.valueOf(line.getAction().name()),
                AbbreviatedObjectId.fromString(line.getCommit()),
                line.getShortMessage());

        rebaseTodoLines.add(rebaseTodoLine);
    }

    return rebaseTodoLines;
}
 
Example #6
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    ObjectId originalCommit = getOriginalCommit();
    ObjectId head = getHead();
    List<RebaseTodoLine> steps;
    try {
        switch (operation) {
            case BEGIN:
                // initialize sequencer and cherry-pick steps if there are
                // more commits to cherry-pick
                steps = prepareCommand(head);
                // apply the selected steps
                applySteps(steps, false);
                break;
            case ABORT:
                // delete the sequencer and reset to the original head
                if (repository.getRepositoryState() == RepositoryState.CHERRY_PICKING
                        || repository.getRepositoryState() == RepositoryState.CHERRY_PICKING_RESOLVED) {
                    if (originalCommit == null) {
                        // maybe the sequencer is not created in that case simply reset to HEAD
                        originalCommit = head;
                    }
                }
                Utils.deleteRecursively(getSequencerFolder());
                if (originalCommit != null) {
                    ResetCommand reset = new ResetCommand(repository, getClassFactory(),
                            originalCommit.name(), GitClient.ResetType.HARD, new DelegatingGitProgressMonitor(monitor), listener);
                    reset.execute();
                }
                result = createCustomResult(GitCherryPickResult.CherryPickStatus.ABORTED);
                break;
            case QUIT:
                // used to reset the sequencer only
                Utils.deleteRecursively(getSequencerFolder());
                switch (repository.getRepositoryState()) {
                    case CHERRY_PICKING:
                        // unresolved conflicts
                        result = createResult(CherryPickResult.CONFLICT);
                        break;
                    case CHERRY_PICKING_RESOLVED:
                        result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED);
                        break;
                    default:
                        result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK);
                        break;
                }
                break;
            case CONTINUE:
                switch (repository.getRepositoryState()) {
                    case CHERRY_PICKING:
                        // unresolved conflicts, cannot continue
                        result = createResult(CherryPickResult.CONFLICT);
                        break;
                    case CHERRY_PICKING_RESOLVED:
                        // cannot continue without manual commit
                        result = createCustomResult(GitCherryPickResult.CherryPickStatus.UNCOMMITTED);
                        break;
                    default:
                        // read steps from sequencer and apply them
                        // if sequencer is empty this will be a noop
                        steps = readTodoFile(repository);
                        applySteps(steps, true);
                        break;
                }
                break;
            default:
                throw new IllegalStateException("Unexpected operation " + operation.name());
        }
    } catch (GitAPIException | IOException ex) {
        throw new GitException(ex);
    }
}
 
Example #7
Source File: CherryPickCommand.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void applySteps (List<RebaseTodoLine> steps, boolean skipFirstStep) throws GitAPIException, IOException {
    Repository repository = getRepository();
    ObjectReader or = repository.newObjectReader();
    CherryPickResult res = null;
    boolean skipped = false;
    List<Ref> cherryPickedRefs = new ArrayList<>();
    for (Iterator<RebaseTodoLine> it = steps.iterator(); it.hasNext();) {
        RebaseTodoLine step = it.next();
        if (step.getAction() == RebaseTodoLine.Action.PICK) {
            if (skipFirstStep && !skipped) {
                it.remove();
                writeTodoFile(repository, steps);
                skipped = true;
                continue;
            }
            Collection<ObjectId> ids = or.resolve(step.getCommit());
            if (ids.size() != 1) {
                throw new JGitInternalException("Could not resolve uniquely the abbreviated object ID");
            }
            org.eclipse.jgit.api.CherryPickCommand command = new Git(repository).cherryPick();
            command.include(ids.iterator().next());
            if (workAroundStrategyIssue) {
                command.setStrategy(new FailuresDetectRecurciveStrategy());
            }
            res = command.call();
            if (res.getStatus() == CherryPickResult.CherryPickStatus.OK) {
                it.remove();
                writeTodoFile(repository, steps);
                cherryPickedRefs.addAll(res.getCherryPickedRefs());
            } else {
                break;
            }
        } else {
            it.remove();
        }
    }
    if (res == null) {
        result = createCustomResult(GitCherryPickResult.CherryPickStatus.OK, cherryPickedRefs);
    } else {
        result = createResult(res, cherryPickedRefs);
    }
    if (steps.isEmpty()) {
        // sequencer no longer needed
        Utils.deleteRecursively(getSequencerFolder());
    }
}
 
Example #8
Source File: SquashActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public RebaseTodoLine.Action getAction() {
    return RebaseTodoLine.Action.SQUASH;
}
 
Example #9
Source File: RebaseActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void prepareSteps(List<RebaseTodoLine> steps) {
    // does nothing
}
 
Example #10
Source File: EditActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public RebaseTodoLine.Action getAction() {
    return EDIT;
}
 
Example #11
Source File: RewordActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public RebaseTodoLine.Action getAction() {
    return RebaseTodoLine.Action.REWORD;
}
 
Example #12
Source File: RebaseActionHandler.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License votes vote down vote up
RebaseTodoLine.Action getAction();