Merge branch 'stable-3.2'
* stable-3.2: Canonicalize worktree path in BaseRepositoryBuilder if set via config Add missing @since tags for new public methods in Config Don't use API exception in RebaseTodoLine Fix aborting rebase with detached head Add recursive variant of Config.getNames() methods Prepare post 3.2.0-m3 builds JGit v3.2.0.201311130903-m3 Change-Id: Iad6e284e0fe2c7950f156372b334e47ebd82f3f7 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
aad7dee3ef
|
@ -64,13 +64,13 @@
|
||||||
import org.eclipse.jgit.api.RebaseCommand.Operation;
|
import org.eclipse.jgit.api.RebaseCommand.Operation;
|
||||||
import org.eclipse.jgit.api.RebaseResult.Status;
|
import org.eclipse.jgit.api.RebaseResult.Status;
|
||||||
import org.eclipse.jgit.api.errors.InvalidRebaseStepException;
|
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.RefNotFoundException;
|
||||||
import org.eclipse.jgit.api.errors.UnmergedPathsException;
|
import org.eclipse.jgit.api.errors.UnmergedPathsException;
|
||||||
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
|
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
|
||||||
import org.eclipse.jgit.diff.DiffEntry;
|
import org.eclipse.jgit.diff.DiffEntry;
|
||||||
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
||||||
import org.eclipse.jgit.errors.AmbiguousObjectException;
|
import org.eclipse.jgit.errors.AmbiguousObjectException;
|
||||||
|
import org.eclipse.jgit.errors.IllegalTodoFileModification;
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
import org.eclipse.jgit.junit.RepositoryTestCase;
|
import org.eclipse.jgit.junit.RepositoryTestCase;
|
||||||
|
@ -575,6 +575,69 @@ public void testStopOnConflict() throws Exception {
|
||||||
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
|
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStopOnConflictAndAbortWithDetachedHEAD() throws Exception {
|
||||||
|
// create file1 on master
|
||||||
|
RevCommit firstInMaster = writeFileAndCommit(FILE1, "Add file1", "1",
|
||||||
|
"2", "3");
|
||||||
|
// change first line in master
|
||||||
|
writeFileAndCommit(FILE1, "change file1 in master", "1master", "2", "3");
|
||||||
|
checkFile(FILE1, "1master", "2", "3");
|
||||||
|
// create a topic branch based on second commit
|
||||||
|
createBranch(firstInMaster, "refs/heads/topic");
|
||||||
|
checkoutBranch("refs/heads/topic");
|
||||||
|
// we have the old content again
|
||||||
|
checkFile(FILE1, "1", "2", "3");
|
||||||
|
|
||||||
|
// add a line (non-conflicting)
|
||||||
|
writeFileAndCommit(FILE1, "add a line to file1 in topic", "1", "2",
|
||||||
|
"3", "topic4");
|
||||||
|
|
||||||
|
// change first line (conflicting)
|
||||||
|
RevCommit conflicting = writeFileAndCommit(FILE1,
|
||||||
|
"change file1 in topic", "1topic", "2", "3", "topic4");
|
||||||
|
|
||||||
|
RevCommit lastTopicCommit = writeFileAndCommit(FILE1,
|
||||||
|
"change file1 in topic again", "1topic", "2", "3", "topic4");
|
||||||
|
|
||||||
|
git.checkout().setName(lastTopicCommit.getName()).call();
|
||||||
|
|
||||||
|
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
|
||||||
|
assertEquals(Status.STOPPED, res.getStatus());
|
||||||
|
assertEquals(conflicting, res.getCurrentCommit());
|
||||||
|
checkFile(FILE1,
|
||||||
|
"<<<<<<< Upstream, based on master\n1master\n=======\n1topic",
|
||||||
|
">>>>>>> e0d1dea change file1 in topic\n2\n3\ntopic4");
|
||||||
|
|
||||||
|
assertEquals(RepositoryState.REBASING_INTERACTIVE,
|
||||||
|
db.getRepositoryState());
|
||||||
|
assertTrue(new File(db.getDirectory(), "rebase-merge").exists());
|
||||||
|
// the first one should be included, so we should have left two picks in
|
||||||
|
// the file
|
||||||
|
assertEquals(1, countPicks());
|
||||||
|
|
||||||
|
// rebase should not succeed in this state
|
||||||
|
try {
|
||||||
|
git.rebase().setUpstream("refs/heads/master").call();
|
||||||
|
fail("Expected exception was not thrown");
|
||||||
|
} catch (WrongRepositoryStateException e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
// abort should reset to topic branch
|
||||||
|
res = git.rebase().setOperation(Operation.ABORT).call();
|
||||||
|
assertEquals(res.getStatus(), Status.ABORTED);
|
||||||
|
assertEquals(lastTopicCommit.getName(), db.getFullBranch());
|
||||||
|
checkFile(FILE1, "1topic", "2", "3", "topic4");
|
||||||
|
RevWalk rw = new RevWalk(db);
|
||||||
|
assertEquals(lastTopicCommit,
|
||||||
|
rw.parseCommit(db.resolve(Constants.HEAD)));
|
||||||
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||||
|
|
||||||
|
// rebase- dir in .git must be deleted
|
||||||
|
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStopOnConflictAndContinue() throws Exception {
|
public void testStopOnConflictAndContinue() throws Exception {
|
||||||
// create file1 on master
|
// create file1 on master
|
||||||
|
@ -1890,8 +1953,12 @@ public String modifyCommitMessage(String commit) {
|
||||||
RebaseResult res2 = git.rebase().setUpstream("HEAD~2")
|
RebaseResult res2 = git.rebase().setUpstream("HEAD~2")
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
steps.get(0).setAction(Action.COMMENT); // delete
|
try {
|
||||||
// RevCommit c4
|
// delete RevCommit c4
|
||||||
|
steps.get(0).setAction(Action.COMMENT);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2020,7 +2087,7 @@ public void testRebaseTodoLineSetComment() throws Exception {
|
||||||
try {
|
try {
|
||||||
new RebaseTodoLine("This is a invalid comment");
|
new RebaseTodoLine("This is a invalid comment");
|
||||||
fail("Constructing a comment line with invalid comment string should fail, but doesn't");
|
fail("Constructing a comment line with invalid comment string should fail, but doesn't");
|
||||||
} catch (JGitInternalException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
RebaseTodoLine validCommentLine = new RebaseTodoLine(
|
RebaseTodoLine validCommentLine = new RebaseTodoLine(
|
||||||
|
@ -2035,7 +2102,7 @@ public void testRebaseTodoLineSetComment() throws Exception {
|
||||||
try {
|
try {
|
||||||
actionLineToBeChanged.setComment("invalid comment");
|
actionLineToBeChanged.setComment("invalid comment");
|
||||||
fail("Setting a invalid comment string should fail but doesn't");
|
fail("Setting a invalid comment string should fail but doesn't");
|
||||||
} catch (JGitInternalException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
assertEquals(null, actionLineToBeChanged.getComment());
|
assertEquals(null, actionLineToBeChanged.getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2044,7 +2111,7 @@ public void testRebaseTodoLineSetComment() throws Exception {
|
||||||
try {
|
try {
|
||||||
actionLineToBeChanged.setComment("invalid comment");
|
actionLineToBeChanged.setComment("invalid comment");
|
||||||
fail("Setting a invalid comment string should fail but doesn't");
|
fail("Setting a invalid comment string should fail but doesn't");
|
||||||
} catch (JGitInternalException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
// setting comment failed, but was successfully set before,
|
// setting comment failed, but was successfully set before,
|
||||||
// therefore it may not be altered since then
|
// therefore it may not be altered since then
|
||||||
|
@ -2061,7 +2128,7 @@ public void testRebaseTodoLineSetComment() throws Exception {
|
||||||
actionLineToBeChanged.setComment("line1 \n\r line2");
|
actionLineToBeChanged.setComment("line1 \n\r line2");
|
||||||
actionLineToBeChanged.setComment("\n\r");
|
actionLineToBeChanged.setComment("\n\r");
|
||||||
fail("Setting a multiline comment string should fail but doesn't");
|
fail("Setting a multiline comment string should fail but doesn't");
|
||||||
} catch (JGitInternalException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
// Try setting valid comments
|
// Try setting valid comments
|
||||||
|
@ -2113,9 +2180,15 @@ public void testRebaseInteractiveReword() throws Exception {
|
||||||
|
|
||||||
RebaseResult res = git.rebase().setUpstream("HEAD~2")
|
RebaseResult res = git.rebase().setUpstream("HEAD~2")
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.REWORD);
|
steps.get(0).setAction(Action.REWORD);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
return "rewritten commit message";
|
return "rewritten commit message";
|
||||||
}
|
}
|
||||||
|
@ -2155,7 +2228,11 @@ public void testRebaseInteractiveEdit() throws Exception {
|
||||||
RebaseResult res = git.rebase().setUpstream("HEAD~2")
|
RebaseResult res = git.rebase().setUpstream("HEAD~2")
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.EDIT);
|
steps.get(0).setAction(Action.EDIT);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2215,7 +2292,11 @@ public void testRebaseInteractiveSingleSquashAndModifyMessage() throws Exception
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(1).setAction(Action.SQUASH);
|
steps.get(1).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2290,8 +2371,12 @@ public void testRebaseInteractiveMultipleSquash() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(1).setAction(Action.SQUASH);
|
steps.get(1).setAction(Action.SQUASH);
|
||||||
steps.get(2).setAction(Action.SQUASH);
|
steps.get(2).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2367,8 +2452,12 @@ public void testRebaseInteractiveMixedSquashAndFixup() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(1).setAction(Action.FIXUP);
|
steps.get(1).setAction(Action.FIXUP);
|
||||||
steps.get(2).setAction(Action.SQUASH);
|
steps.get(2).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2437,7 +2526,11 @@ public void testRebaseInteractiveSingleFixup() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(1).setAction(Action.FIXUP);
|
steps.get(1).setAction(Action.FIXUP);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2481,7 +2574,11 @@ public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(1).setAction(Action.FIXUP);
|
steps.get(1).setAction(Action.FIXUP);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2516,7 +2613,11 @@ public void testRebaseInteractiveFixupFirstCommitShouldFail()
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.FIXUP);
|
steps.get(0).setAction(Action.FIXUP);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2544,7 +2645,11 @@ public void testRebaseInteractiveSquashFirstCommitShouldFail()
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.SQUASH);
|
steps.get(0).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2571,7 +2676,11 @@ public void testRebaseEndsIfLastStepIsEdit() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.EDIT);
|
steps.get(0).setAction(Action.EDIT);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2610,7 +2719,11 @@ public void testRebaseShouldStopForEditInCaseOfConflict()
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
steps.remove(0);
|
steps.remove(0);
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.EDIT);
|
steps.get(0).setAction(Action.EDIT);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2648,7 +2761,11 @@ public void testRebaseShouldStopForRewordInCaseOfConflict()
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
steps.remove(0);
|
steps.remove(0);
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.REWORD);
|
steps.get(0).setAction(Action.REWORD);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2661,7 +2778,11 @@ public String modifyCommitMessage(String commit) {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
steps.remove(0);
|
steps.remove(0);
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.REWORD);
|
steps.get(0).setAction(Action.REWORD);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2702,9 +2823,13 @@ public void testRebaseShouldSquashInCaseOfConflict() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.PICK);
|
steps.get(0).setAction(Action.PICK);
|
||||||
steps.remove(1);
|
steps.remove(1);
|
||||||
steps.get(1).setAction(Action.SQUASH);
|
steps.get(1).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2716,9 +2841,13 @@ public String modifyCommitMessage(String commit) {
|
||||||
result = git.rebase().runInteractively(new InteractiveHandler() {
|
result = git.rebase().runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.PICK);
|
steps.get(0).setAction(Action.PICK);
|
||||||
steps.remove(1);
|
steps.remove(1);
|
||||||
steps.get(1).setAction(Action.SQUASH);
|
steps.get(1).setAction(Action.SQUASH);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2760,9 +2889,13 @@ public void testRebaseShouldFixupInCaseOfConflict() throws Exception {
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.PICK);
|
steps.get(0).setAction(Action.PICK);
|
||||||
steps.remove(1);
|
steps.remove(1);
|
||||||
steps.get(1).setAction(Action.FIXUP);
|
steps.get(1).setAction(Action.FIXUP);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2774,9 +2907,13 @@ public String modifyCommitMessage(String commit) {
|
||||||
result = git.rebase().runInteractively(new InteractiveHandler() {
|
result = git.rebase().runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.PICK);
|
steps.get(0).setAction(Action.PICK);
|
||||||
steps.remove(1);
|
steps.remove(1);
|
||||||
steps.get(1).setAction(Action.FIXUP);
|
steps.get(1).setAction(Action.FIXUP);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
@ -2823,8 +2960,12 @@ public void testInteractiveRebaseWithModificationShouldNotDeleteDataOnAbort()
|
||||||
.runInteractively(new InteractiveHandler() {
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
public void prepareSteps(List<RebaseTodoLine> steps) {
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
try {
|
||||||
steps.get(0).setAction(Action.EDIT);
|
steps.get(0).setAction(Action.EDIT);
|
||||||
steps.get(1).setAction(Action.PICK);
|
steps.get(1).setAction(Action.PICK);
|
||||||
|
} catch (IllegalTodoFileModification e) {
|
||||||
|
fail("unexpected exception: " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modifyCommitMessage(String commit) {
|
public String modifyCommitMessage(String commit) {
|
||||||
|
|
|
@ -519,6 +519,31 @@ public void test009_readNamesInSection() throws ConfigInvalidException {
|
||||||
assertFalse(itr.hasNext());
|
assertFalse(itr.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_ReadNamesInSectionRecursive()
|
||||||
|
throws ConfigInvalidException {
|
||||||
|
String baseConfigString = "[core]\n" + "logAllRefUpdates = true\n";
|
||||||
|
String configString = "[core]\n" + "repositoryFormatVersion = 0\n"
|
||||||
|
+ "filemode = false\n";
|
||||||
|
final Config c = parse(configString, parse(baseConfigString));
|
||||||
|
Set<String> names = c.getNames("core", true);
|
||||||
|
assertEquals("Core section size", 3, names.size());
|
||||||
|
assertTrue("Core section should contain \"filemode\"",
|
||||||
|
names.contains("filemode"));
|
||||||
|
assertTrue("Core section should contain \"repositoryFormatVersion\"",
|
||||||
|
names.contains("repositoryFormatVersion"));
|
||||||
|
assertTrue("Core section should contain \"logAllRefUpdates\"",
|
||||||
|
names.contains("logAllRefUpdates"));
|
||||||
|
assertTrue("Core section should contain \"logallrefupdates\"",
|
||||||
|
names.contains("logallrefupdates"));
|
||||||
|
|
||||||
|
Iterator<String> itr = names.iterator();
|
||||||
|
assertEquals("filemode", itr.next());
|
||||||
|
assertEquals("repositoryFormatVersion", itr.next());
|
||||||
|
assertEquals("logAllRefUpdates", itr.next());
|
||||||
|
assertFalse(itr.hasNext());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test010_readNamesInSubSection() throws ConfigInvalidException {
|
public void test010_readNamesInSubSection() throws ConfigInvalidException {
|
||||||
String configString = "[a \"sub1\"]\n"//
|
String configString = "[a \"sub1\"]\n"//
|
||||||
|
@ -540,6 +565,30 @@ public void test010_readNamesInSubSection() throws ConfigInvalidException {
|
||||||
assertTrue("Subsection should contain \"b\"", names.contains("b"));
|
assertTrue("Subsection should contain \"b\"", names.contains("b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readNamesInSubSectionRecursive() throws ConfigInvalidException {
|
||||||
|
String baseConfigString = "[a \"sub1\"]\n"//
|
||||||
|
+ "x = 0\n" //
|
||||||
|
+ "y = false\n"//
|
||||||
|
+ "[a \"sub2\"]\n"//
|
||||||
|
+ "A=0\n";//
|
||||||
|
String configString = "[a \"sub1\"]\n"//
|
||||||
|
+ "z = true\n"//
|
||||||
|
+ "[a \"sub2\"]\n"//
|
||||||
|
+ "B=1\n";
|
||||||
|
final Config c = parse(configString, parse(baseConfigString));
|
||||||
|
Set<String> names = c.getNames("a", "sub1", true);
|
||||||
|
assertEquals("Subsection size", 3, names.size());
|
||||||
|
assertTrue("Subsection should contain \"x\"", names.contains("x"));
|
||||||
|
assertTrue("Subsection should contain \"y\"", names.contains("y"));
|
||||||
|
assertTrue("Subsection should contain \"z\"", names.contains("z"));
|
||||||
|
names = c.getNames("a", "sub2", true);
|
||||||
|
assertEquals("Subsection size", 2, names.size());
|
||||||
|
assertTrue("Subsection should contain \"A\"", names.contains("A"));
|
||||||
|
assertTrue("Subsection should contain \"a\"", names.contains("a"));
|
||||||
|
assertTrue("Subsection should contain \"B\"", names.contains("B"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQuotingForSubSectionNames() {
|
public void testQuotingForSubSectionNames() {
|
||||||
String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
|
String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
|
||||||
|
@ -584,7 +633,12 @@ private static void assertReadLong(long exp, String act)
|
||||||
|
|
||||||
private static Config parse(final String content)
|
private static Config parse(final String content)
|
||||||
throws ConfigInvalidException {
|
throws ConfigInvalidException {
|
||||||
final Config c = new Config(null);
|
return parse(content, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Config parse(final String content, Config baseConfig)
|
||||||
|
throws ConfigInvalidException {
|
||||||
|
final Config c = new Config(baseConfig);
|
||||||
c.fromText(content);
|
c.fromText(content);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1101,15 +1101,21 @@ private RebaseResult abort(RebaseResult result) throws IOException,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String headName = rebaseState.readFile(HEAD_NAME);
|
String headName = rebaseState.readFile(HEAD_NAME);
|
||||||
if (headName.startsWith(Constants.R_REFS)) {
|
|
||||||
monitor.beginTask(MessageFormat.format(
|
monitor.beginTask(MessageFormat.format(
|
||||||
JGitText.get().resettingHead, headName),
|
JGitText.get().resettingHead, headName),
|
||||||
ProgressMonitor.UNKNOWN);
|
ProgressMonitor.UNKNOWN);
|
||||||
|
|
||||||
// update the HEAD
|
Result res = null;
|
||||||
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false);
|
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false);
|
||||||
refUpdate.setRefLogMessage("rebase: aborting", false); //$NON-NLS-1$
|
refUpdate.setRefLogMessage("rebase: aborting", false); //$NON-NLS-1$
|
||||||
Result res = refUpdate.link(headName);
|
if (headName.startsWith(Constants.R_REFS)) {
|
||||||
|
// update the HEAD
|
||||||
|
res = refUpdate.link(headName);
|
||||||
|
} else {
|
||||||
|
refUpdate.setNewObjectId(repo.readOrigHead());
|
||||||
|
res = refUpdate.forceUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case FAST_FORWARD:
|
case FAST_FORWARD:
|
||||||
case FORCED:
|
case FORCED:
|
||||||
|
@ -1119,7 +1125,6 @@ private RebaseResult abort(RebaseResult result) throws IOException,
|
||||||
throw new JGitInternalException(
|
throw new JGitInternalException(
|
||||||
JGitText.get().abortingRebaseFailed);
|
JGitText.get().abortingRebaseFailed);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
boolean stashConflicts = autoStashApply();
|
boolean stashConflicts = autoStashApply();
|
||||||
// cleanup the files
|
// cleanup the files
|
||||||
FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE);
|
FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -695,7 +695,7 @@ private File guessWorkTreeOrFail() throws IOException {
|
||||||
String path = cfg.getString(CONFIG_CORE_SECTION, null,
|
String path = cfg.getString(CONFIG_CORE_SECTION, null,
|
||||||
CONFIG_KEY_WORKTREE);
|
CONFIG_KEY_WORKTREE);
|
||||||
if (path != null)
|
if (path != null)
|
||||||
return safeFS().resolve(getGitDir(), path);
|
return safeFS().resolve(getGitDir(), path).getCanonicalFile();
|
||||||
|
|
||||||
// If core.bare is set, honor its value. Assume workTree is
|
// If core.bare is set, honor its value. Assume workTree is
|
||||||
// the parent directory of the repository.
|
// the parent directory of the repository.
|
||||||
|
|
|
@ -527,6 +527,35 @@ public Set<String> getNames(String section, String subsection) {
|
||||||
return getState().getNames(section, subsection);
|
return getState().getNames(section, subsection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param section
|
||||||
|
* the section
|
||||||
|
* @param recursive
|
||||||
|
* if {@code true} recursively adds the names defined in all base
|
||||||
|
* configurations
|
||||||
|
* @return the list of names defined for this section
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public Set<String> getNames(String section, boolean recursive) {
|
||||||
|
return getState().getNames(section, null, recursive);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param section
|
||||||
|
* the section
|
||||||
|
* @param subsection
|
||||||
|
* the subsection
|
||||||
|
* @param recursive
|
||||||
|
* if {@code true} recursively adds the names defined in all base
|
||||||
|
* configurations
|
||||||
|
* @return the list of names defined for this subsection
|
||||||
|
* @since 3.2
|
||||||
|
*/
|
||||||
|
public Set<String> getNames(String section, String subsection,
|
||||||
|
boolean recursive) {
|
||||||
|
return getState().getNames(section, subsection, recursive);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain a handle to a parsed set of configuration values.
|
* Obtain a handle to a parsed set of configuration values.
|
||||||
*
|
*
|
||||||
|
|
|
@ -97,6 +97,16 @@ Set<String> getSubsections(String section) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> getNames(String section, String subsection) {
|
Set<String> getNames(String section, String subsection) {
|
||||||
|
return getNames(section, subsection, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> getNames(String section, String subsection, boolean recursive) {
|
||||||
|
Map<String, String> m = getNamesInternal(section, subsection, recursive);
|
||||||
|
return new CaseFoldingSet(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getNamesInternal(String section,
|
||||||
|
String subsection, boolean recursive) {
|
||||||
List<ConfigLine> s = sorted();
|
List<ConfigLine> s = sorted();
|
||||||
int idx = find(s, section, subsection, ""); //$NON-NLS-1$
|
int idx = find(s, section, subsection, ""); //$NON-NLS-1$
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
|
@ -113,7 +123,9 @@ Set<String> getNames(String section, String subsection) {
|
||||||
if (!m.containsKey(l))
|
if (!m.containsKey(l))
|
||||||
m.put(l, e.name);
|
m.put(l, e.name);
|
||||||
}
|
}
|
||||||
return new CaseFoldingSet(m);
|
if (recursive && baseState != null)
|
||||||
|
m.putAll(baseState.getNamesInternal(section, subsection, recursive));
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] get(String section, String subsection, String name) {
|
String[] get(String section, String subsection, String name) {
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.JGitInternalException;
|
import org.eclipse.jgit.errors.IllegalTodoFileModification;
|
||||||
import org.eclipse.jgit.internal.JGitText;
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +111,7 @@ static public Action parse(String token) {
|
||||||
|| action.shortToken.equals(token))
|
|| action.shortToken.equals(token))
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
throw new JGitInternalException(MessageFormat.format(
|
throw new IllegalArgumentException(MessageFormat.format(
|
||||||
JGitText.get().unknownOrUnsupportedCommand, token,
|
JGitText.get().unknownOrUnsupportedCommand, token,
|
||||||
Action.values()));
|
Action.values()));
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,11 @@ public Action getAction() {
|
||||||
* non-comment.
|
* non-comment.
|
||||||
*
|
*
|
||||||
* @param newAction
|
* @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)) {
|
if (!Action.COMMENT.equals(action) && Action.COMMENT.equals(newAction)) {
|
||||||
// transforming from non-comment to comment
|
// transforming from non-comment to comment
|
||||||
if (comment == null)
|
if (comment == null)
|
||||||
|
@ -180,7 +183,7 @@ public void setAction(Action newAction) {
|
||||||
} else if (Action.COMMENT.equals(action) && !Action.COMMENT.equals(newAction)) {
|
} else if (Action.COMMENT.equals(action) && !Action.COMMENT.equals(newAction)) {
|
||||||
// transforming from comment to non-comment
|
// transforming from comment to non-comment
|
||||||
if (commit == null)
|
if (commit == null)
|
||||||
throw new JGitInternalException(MessageFormat.format(
|
throw new IllegalTodoFileModification(MessageFormat.format(
|
||||||
JGitText.get().cannotChangeActionOnComment, action,
|
JGitText.get().cannotChangeActionOnComment, action,
|
||||||
newAction));
|
newAction));
|
||||||
}
|
}
|
||||||
|
@ -219,12 +222,11 @@ public void setComment(String newComment) {
|
||||||
throw createInvalidCommentException(newComment);
|
throw createInvalidCommentException(newComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JGitInternalException createInvalidCommentException(
|
private static IllegalArgumentException createInvalidCommentException(
|
||||||
String newComment) {
|
String newComment) {
|
||||||
IllegalArgumentException iae = new IllegalArgumentException(
|
return new IllegalArgumentException(
|
||||||
MessageFormat.format(
|
MessageFormat.format(
|
||||||
JGitText.get().argumentIsNotAValidCommentString, newComment));
|
JGitText.get().argumentIsNotAValidCommentString, newComment));
|
||||||
return new JGitInternalException(iae.getMessage(), iae);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue