private static void parseComments(byte[] buf, int tokenBegin, List<RebaseTodoLine> r, int lineEnd) { RebaseTodoLine line = null; String commentString = RawParseUtils.decode(buf, tokenBegin, lineEnd + 1); try { int skip = tokenBegin + 1; // skip '#' skip = nextParsableToken(buf, skip, lineEnd); if (skip != -1) { // try to parse the line as non-comment line = parseLine(buf, skip, lineEnd); // successfully parsed as non-comment line // mark this line as a comment explicitly line.setAction(Action.COMMENT); // use the read line as comment string line.setComment(commentString); } } catch (Exception e) { // parsing as non-comment line failed line = null; } finally { if (line == null) line = new RebaseTodoLine(commentString); r.add(line); } }
sb.setLength(0); if (RebaseTodoLine.Action.COMMENT.equals(step.action)) sb.append(step.getComment()); else { sb.append(step.getAction().toToken()); sb.append(" "); //$NON-NLS-1$ sb.append(step.getCommit().name()); sb.append(" "); //$NON-NLS-1$ sb.append(step.getShortMessage().trim());
/** * <p> * Set a comment for this line that is used if this line's * {@link org.eclipse.jgit.lib.RebaseTodoLine#action} is a {@link org.eclipse.jgit.lib.RebaseTodoLine.Action#COMMENT} * </p> * It's allowed to unset the comment by calling * <code>setComment(null)</code> <br> * A valid comment either starts with a hash (i.e. <code>'#'</code>), is an * empty string, or consists of only spaces and tabs.<br> * If the argument <code>newComment</code> doesn't match these requirements * an Exception is thrown. * * @param newComment * the comment */ public void setComment(String newComment) { if (newComment == null) { this.comment = null; return; } if (newComment.contains("\n") || newComment.contains("\r")) //$NON-NLS-1$ //$NON-NLS-2$ throw createInvalidCommentException(newComment); if (newComment.trim().length() == 0 || newComment.startsWith("#")) { //$NON-NLS-1$ this.comment = newComment; return; } throw createInvalidCommentException(newComment); }
RebaseTodoLine step = doneLines.get(doneLines.size() - 1); if (newHead != null && step.getAction() != Action.PICK) { RebaseTodoLine newStep = new RebaseTodoLine( step.getAction(), AbbreviatedObjectId.fromObjectId(newHead), step.getShortMessage()); RebaseResult result = processStep(newStep, false); if (result != null)
@Override public void prepareSteps(List<RebaseTodoLine> steps) { for (RebaseTodoLine step : steps.subList(1, steps.size())) { try { step.setAction(RebaseTodoLine.Action.SQUASH); step.setShortMessage(""); } catch (IllegalTodoFileModification e) { throw new RuntimeException("Couldn't squash commit " + step.getCommit().name(), e); } } }
private RebaseResult processStep(RebaseTodoLine step, boolean shouldPick) throws IOException, GitAPIException { if (Action.COMMENT.equals(step.getAction())) return null; if (preserveMerges && shouldPick && (Action.EDIT.equals(step.getAction()) || Action.PICK .equals(step.getAction()))) { writeRewrittenHashes(); Collection<ObjectId> ids = or.resolve(step.getCommit()); if (ids.size() != 1) throw new JGitInternalException( switch (step.getAction()) { case PICK: return null; // continue rebase process on pick command
private void checkSteps(List<RebaseTodoLine> steps) throws InvalidRebaseStepException, IOException { if (steps.isEmpty()) return; if (RebaseTodoLine.Action.SQUASH.equals(steps.get(0).getAction()) || RebaseTodoLine.Action.FIXUP.equals(steps.get(0).getAction())) { if (!rebaseState.getFile(DONE).exists() || rebaseState.readFile(DONE).trim().length() == 0) { throw new InvalidRebaseStepException(MessageFormat.format( JGitText.get().cannotSquashFixupWithoutPreviousCommit, steps.get(0).getAction().name())); } } }
break; case 2: return new RebaseTodoLine(action, commit, RawParseUtils.decode(buf, tokenBegin, 1 + lineEnd)); return new RebaseTodoLine(action, commit, ""); //$NON-NLS-1$ return null;
@Override public void prepareSteps(List<RebaseTodoLine> steps) { // the handler receives the list of commits that are rebased, i.e. the ones on the local branch for(RebaseTodoLine step : steps) { // for each step, you can decide which action should be taken // default is PICK try { // by selecting "EDIT", the rebase will stop and ask you to edit the commit-contents step.setAction(Action.EDIT); } catch (IllegalTodoFileModification e) { throw new IllegalStateException(e); } } }
/** * Create a new comment line * * @param newComment * the new comment */ public RebaseTodoLine(String newComment) { this.action = Action.COMMENT; setComment(newComment); this.commit = null; this.shortMessage = null; }
RebaseTodoLine step = doneLines.get(doneLines.size() - 1); if (newHead != null && step.getAction() != Action.PICK) { RebaseTodoLine newStep = new RebaseTodoLine( step.getAction(), AbbreviatedObjectId.fromObjectId(newHead), step.getShortMessage()); RebaseResult result = processStep(newStep, false); if (result != null)
private RebaseResult processStep(RebaseTodoLine step, boolean shouldPick) throws IOException, GitAPIException { if (Action.COMMENT.equals(step.getAction())) return null; if (preserveMerges && shouldPick && (Action.EDIT.equals(step.getAction()) || Action.PICK .equals(step.getAction()))) { writeRewrittenHashes(); Collection<ObjectId> ids = or.resolve(step.getCommit()); if (ids.size() != 1) throw new JGitInternalException( switch (step.getAction()) { case PICK: return null; // continue rebase process on pick command
/** * Removes the number of lines given in the parameter from the * <code>git-rebase-todo</code> file but preserves comments and other lines * that can not be parsed as steps * * @param numSteps * @throws IOException */ private void popSteps(int numSteps) throws IOException { if (numSteps == 0) return; List<RebaseTodoLine> todoLines = new LinkedList<>(); List<RebaseTodoLine> poppedLines = new LinkedList<>(); for (RebaseTodoLine line : repo.readRebaseTodo( rebaseState.getPath(GIT_REBASE_TODO), true)) { if (poppedLines.size() >= numSteps || RebaseTodoLine.Action.COMMENT.equals(line.getAction())) todoLines.add(line); else poppedLines.add(line); } repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO), todoLines, false); if (poppedLines.size() > 0) { repo.writeRebaseTodoFile(rebaseState.getPath(DONE), poppedLines, true); } }
r.add(new RebaseTodoLine(RawParseUtils.decode(buf, lineStart, 1 + lineEnd))); continue;
@Override public void prepareSteps(List<RebaseTodoLine> steps) { // the handler receives the list of commits that are rebased, i.e. the ones on the local branch for(RebaseTodoLine step : steps) { // for each step, you can decide which action should be taken // default is PICK try { // by selecting "EDIT", the rebase will stop and ask you to edit the commit-contents step.setAction(Action.EDIT); } catch (IllegalTodoFileModification e) { throw new IllegalStateException(e); } } }
/** * Create a new comment line * * @param newComment * the new comment */ public RebaseTodoLine(String newComment) { this.action = Action.COMMENT; setComment(newComment); this.commit = null; this.shortMessage = null; }
sb.setLength(0); if (RebaseTodoLine.Action.COMMENT.equals(step.action)) sb.append(step.getComment()); else { sb.append(step.getAction().toToken()); sb.append(" "); //$NON-NLS-1$ sb.append(step.getCommit().name()); sb.append(" "); //$NON-NLS-1$ sb.append(step.getShortMessage().trim());
private static void parseComments(byte[] buf, int tokenBegin, List<RebaseTodoLine> r, int lineEnd) { RebaseTodoLine line = null; String commentString = RawParseUtils.decode(buf, tokenBegin, lineEnd + 1); try { int skip = tokenBegin + 1; // skip '#' skip = nextParsableToken(buf, skip, lineEnd); if (skip != -1) { // try to parse the line as non-comment line = parseLine(buf, skip, lineEnd); // successfully parsed as non-comment line // mark this line as a comment explicitly line.setAction(Action.COMMENT); // use the read line as comment string line.setComment(commentString); } } catch (Exception e) { // parsing as non-comment line failed line = null; } finally { if (line == null) line = new RebaseTodoLine(commentString); r.add(line); } }
RebaseTodoLine step = doneLines.get(doneLines.size() - 1); if (newHead != null && step.getAction() != Action.PICK) { RebaseTodoLine newStep = new RebaseTodoLine( step.getAction(), AbbreviatedObjectId.fromObjectId(newHead), step.getShortMessage()); RebaseResult result = processStep(newStep, false); if (result != null)