Browse Source

Don't use API exception in RebaseTodoLine

This came up while testing the proposed buck build for jgit. With buck
we can introduce smaller modules to allow for more concurrency during
build and to better control inner structure of jgit. Trying to put the
porcelain API into a different module than lower level implementation
classes failed since RebaseTodoLine used a porcelain API exception
causing a dependency cycle on the proposed modules. Using an exception
defined on the same abstraction level fixes this problem.

Change-Id: I26a5353e1a8fc23e67d8ce61309bd964f7665bcb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
stable-3.2
Christian Halstrick 11 years ago committed by Matthias Sohn
parent
commit
ea04d2329d
  1. 150
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  2. 59
      org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java
  3. 16
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java

150
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java

@ -64,13 +64,13 @@ import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.InvalidRebaseStepException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IllegalTodoFileModification;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.junit.RepositoryTestCase;
@ -1953,8 +1953,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res2 = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.COMMENT); // delete
// RevCommit c4
try {
// delete RevCommit c4
steps.get(0).setAction(Action.COMMENT);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2083,7 +2087,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
new RebaseTodoLine("This is a invalid comment");
fail("Constructing a comment line with invalid comment string should fail, but doesn't");
} catch (JGitInternalException e) {
} catch (IllegalArgumentException e) {
// expected
}
RebaseTodoLine validCommentLine = new RebaseTodoLine(
@ -2098,7 +2102,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
actionLineToBeChanged.setComment("invalid comment");
fail("Setting a invalid comment string should fail but doesn't");
} catch (JGitInternalException e) {
} catch (IllegalArgumentException e) {
assertEquals(null, actionLineToBeChanged.getComment());
}
@ -2107,7 +2111,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
actionLineToBeChanged.setComment("invalid comment");
fail("Setting a invalid comment string should fail but doesn't");
} catch (JGitInternalException e) {
} catch (IllegalArgumentException e) {
// expected
// setting comment failed, but was successfully set before,
// therefore it may not be altered since then
@ -2124,7 +2128,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
actionLineToBeChanged.setComment("line1 \n\r line2");
actionLineToBeChanged.setComment("\n\r");
fail("Setting a multiline comment string should fail but doesn't");
} catch (JGitInternalException e) {
} catch (IllegalArgumentException e) {
// expected
}
// Try setting valid comments
@ -2176,9 +2180,15 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.REWORD);
try {
steps.get(0).setAction(Action.REWORD);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
return "rewritten commit message";
}
@ -2218,7 +2228,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("HEAD~2")
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.EDIT);
try {
steps.get(0).setAction(Action.EDIT);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2278,7 +2292,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(1).setAction(Action.SQUASH);
try {
steps.get(1).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2353,8 +2371,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(1).setAction(Action.SQUASH);
steps.get(2).setAction(Action.SQUASH);
try {
steps.get(1).setAction(Action.SQUASH);
steps.get(2).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2430,8 +2452,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(1).setAction(Action.FIXUP);
steps.get(2).setAction(Action.SQUASH);
try {
steps.get(1).setAction(Action.FIXUP);
steps.get(2).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2500,7 +2526,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(1).setAction(Action.FIXUP);
try {
steps.get(1).setAction(Action.FIXUP);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2544,7 +2574,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(1).setAction(Action.FIXUP);
try {
steps.get(1).setAction(Action.FIXUP);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2579,7 +2613,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.FIXUP);
try {
steps.get(0).setAction(Action.FIXUP);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2607,7 +2645,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.SQUASH);
try {
steps.get(0).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2634,7 +2676,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.EDIT);
try {
steps.get(0).setAction(Action.EDIT);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2673,7 +2719,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
steps.get(0).setAction(Action.EDIT);
try {
steps.get(0).setAction(Action.EDIT);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2711,7 +2761,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
steps.get(0).setAction(Action.REWORD);
try {
steps.get(0).setAction(Action.REWORD);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2724,7 +2778,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.remove(0);
steps.get(0).setAction(Action.REWORD);
try {
steps.get(0).setAction(Action.REWORD);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2765,9 +2823,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.SQUASH);
try {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2779,9 +2841,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
result = git.rebase().runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.SQUASH);
try {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.SQUASH);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2823,9 +2889,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.FIXUP);
try {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.FIXUP);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2837,9 +2907,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
result = git.rebase().runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.FIXUP);
try {
steps.get(0).setAction(Action.PICK);
steps.remove(1);
steps.get(1).setAction(Action.FIXUP);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {
@ -2886,8 +2960,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
.runInteractively(new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
steps.get(0).setAction(Action.EDIT);
steps.get(1).setAction(Action.PICK);
try {
steps.get(0).setAction(Action.EDIT);
steps.get(1).setAction(Action.PICK);
} catch (IllegalTodoFileModification e) {
fail("unexpected exception: " + e);
}
}
public String modifyCommitMessage(String commit) {

59
org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java

@ -0,0 +1,59 @@
/*
* Copyright (C) 2013, Christian Halstrick <christian.halstrick@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* - Neither the name of the Eclipse Foundation, Inc. nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.errors;
/**
* Attempt to modify a rebase-todo file in an unsupported way
*
* @since 3.2
*/
public class IllegalTodoFileModification extends Exception {
private static final long serialVersionUID = 1L;
/**
* @param msg
*/
public IllegalTodoFileModification(final String msg) {
super(msg);
}
}

16
org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java

@ -45,7 +45,7 @@ package org.eclipse.jgit.lib;
import java.text.MessageFormat;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.IllegalTodoFileModification;
import org.eclipse.jgit.internal.JGitText;
/**
@ -111,7 +111,7 @@ public class RebaseTodoLine {
|| action.shortToken.equals(token))
return action;
}
throw new JGitInternalException(MessageFormat.format(
throw new IllegalArgumentException(MessageFormat.format(
JGitText.get().unknownOrUnsupportedCommand, token,
Action.values()));
}
@ -167,8 +167,11 @@ public class RebaseTodoLine {
* non-comment.
*
* @param newAction
* @throws IllegalTodoFileModification
* on attempt to set a non-comment action on a line which was a
* comment line before.
*/
public void setAction(Action newAction) {
public void setAction(Action newAction) throws IllegalTodoFileModification {
if (!Action.COMMENT.equals(action) && Action.COMMENT.equals(newAction)) {
// transforming from non-comment to comment
if (comment == null)
@ -180,7 +183,7 @@ public class RebaseTodoLine {
} else if (Action.COMMENT.equals(action) && !Action.COMMENT.equals(newAction)) {
// transforming from comment to non-comment
if (commit == null)
throw new JGitInternalException(MessageFormat.format(
throw new IllegalTodoFileModification(MessageFormat.format(
JGitText.get().cannotChangeActionOnComment, action,
newAction));
}
@ -219,12 +222,11 @@ public class RebaseTodoLine {
throw createInvalidCommentException(newComment);
}
private static JGitInternalException createInvalidCommentException(
private static IllegalArgumentException createInvalidCommentException(
String newComment) {
IllegalArgumentException iae = new IllegalArgumentException(
return new IllegalArgumentException(
MessageFormat.format(
JGitText.get().argumentIsNotAValidCommentString, newComment));
return new JGitInternalException(iae.getMessage(), iae);
}
/**

Loading…
Cancel
Save